public class Robot extends IterativeRobot {
private DriveSystem drive;
private FlightStick joystick;
private ContinuousRange driveSpeed;
private ContinuousRange turnSpeed;
private ContinuousRange throttle;
@Override
public void robotInit() {
...
// Define the interface components ...
joystick = Hardware.HumanInterfaceDevices.logitechAttack3D(0);
throttle = joystick.getThrottle().map(t -> (t + 1.0) / 2.0);
driveSpeed = joystick.getPitch().scale(this::throttle);
turnSpeed = joystick.getRoll().scale(this::throttle).invert();
...
}
/**
* Function that returns the current throttle in both autonomous and teleop.
* @return the current throttle
*/
private double throttle() {
return throttle.read();
}
@Override
public void autonomousInit() {
// Set the maximum throttle in autonomous to be 100% ...
this.throttle = ()->1.0;
}
...
@Override
public void teleopInit() {
// Set the throttle obtain the value from the joystick ...
throttle = joystick.getThrottle().map(t -> (t + 1.0) / 2.0);
...
}
@Override
public void teleopPeriodic() {
drive.arcade(driveSpeed.read(), turnSpeed.read());
}
...
}