summaryrefslogtreecommitdiff
path: root/src/org/usfirst/frc/team4272/robot2016/Teleop.java
blob: 19dfc6edb9e4a5b39b79b21d614bdecc03d70f9f (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
62
63
64
65
66
67
68
69
70
71
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;
	private final double armSoftStop = 95;//295;

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

	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 = 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();
		}

		if (oi.xbox.getButton(Button.LBumper))
			control.arm = 1-(robot.armE.pidGet()/armSoftStop);
		else if (oi.xbox.getButton(Button.RBumper))
			control.arm = robot.armE.pidGet()/armSoftStop;

		//if (robot.armE.pidGet() > armSoftStop && control.arm > 0)
		//	control.arm = 0;

		/* 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;
	}
}