summaryrefslogtreecommitdiff
path: root/src/org/usfirst/frc/team4272/robot2016/Teleop.java
blob: cafbca12864d75c03249846122bdbfbc95ba416c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package org.usfirst.frc.team4272.robot2016;

import org.usfirst.frc.team4272.robotlib.Xbox360Controller.Axis;
import org.usfirst.frc.team4272.robotlib.Xbox360Controller.Button;
import edu.wpi.first.wpilibj.Joystick;

public class Teleop {
	private final HwRobot robot;

	public Teleop(HwRobot robot) {
		this.robot = robot;
	}

	private static double jsScale(Joystick j) {
		double y = -j.getY();/* +:forward; -:backward */
		double z = -j.getZ();/* +:more-sensitive; -:less-sensitive */
		return Math.copySign(Math.pow(Math.abs(y), 2.0-z), y);
	}

	private static double bound(double min, double v, double max) {
		return Math.min(Math.max(v, min), max);
	}

	private static double oneIf(boolean b) {
		return b ? 1 : 0;
	}

	public Control run(Control control, HwOI oi) {
		/* Drive */
		control.lDrive1 = jsScale(oi.lStick);
		control.rDrive1 = jsScale(oi.rStick);
		control.lDrive2 = oi.lStick.getTrigger() ? control.lDrive1 : 0;
		control.rDrive2 = oi.rStick.getTrigger() ? control.rDrive1 : 0;
		control.arm = -oi.xbox.getAxis(Axis.LY);

		double fBall = oi.xbox.getAxis(Axis.RTrigger) - oi.xbox.getAxis(Axis.LTrigger);
		double bBall = bound(-1, fBall, 0) + oneIf(oi.xbox.getButton(Button.A)) - oneIf(oi.xbox.getButton(Button.B));

		boolean ballL = false; //robot.ballL.get();
		control.fBall = bound(-oneIf(!ballL), fBall, 1);
		control.bBall = bound(-oneIf(!ballL), bBall < 0 ? 0.75*bBall : bBall, 1);

		/* I'm eyeballing 10 degrees ≈ 50 clicks */
		//if (robot.armE.pidGet() < 50 && robot.armL.get()) {
		//	robot.armE.reset();
		//}

		/* Take pictures */
		/*
		if (camButton.update(oi.xbox.getButton(Button.RT))) {
			try {
				ProcessBuilder pb = new ProcessBuilder("/home/lvuser/tweeterbot/bin/snapPhoto");
				pb.redirectErrorStream(true);
				pb.start();
			} catch (Exception e) {};
		}
		*/

		return control;
	}
}