@Override public void robotInit() { // We could set up Strongback using its configurator, but this is entirely optional since all // defaults are acceptable. // Strongback.configure().initialize(); // Set up the robot hardware ... Motor left = Motor.compose(Hardware.Motors.talon(LF_MOTOR_PORT), Hardware.Motors.talon(LR_MOTOR_PORT)); Motor right = Motor.compose(Hardware.Motors.talon(RF_MOTOR_PORT), Hardware.Motors.talon(RR_MOTOR_PORT)) .invert(); drive = new TankDrive(left, right); // Set up the human input controls for teleoperated mode. We want to use the Logitech Attack // 3D's throttle as a // "sensitivity" input to scale the drive speed and throttle, so we'll map it from it's native // [-1,1] to a simple scale // factor of [0,1] ... FlightStick joystick = Hardware.HumanInterfaceDevices.logitechAttack3D(JOYSTICK_PORT); ContinuousRange sensitivity = joystick.getThrottle().map(t -> (t + 1.0) / 2.0); driveSpeed = joystick.getPitch().scale(sensitivity::read); // scaled turnSpeed = joystick.getRoll().scale(sensitivity::read).invert(); // scaled and inverted // Set up the command we'll use during autonomous. We'd probably use a custom CommandGroup that // did something more // complicated, but for this very simple example we'll just drive forward at 50% speed for 5 // seconds, // so we can use a simple lambda ... autonomousCommand = Command.create(5.0, () -> drive.tank(0.5, 0.5)); // Set up the data recorder to capture the left & right motor speeds (since both motors on the // same side should // be at the same speed, we can just use the composed motors for each) and the sensitivity. We // have to do this // before we start Strongback... Strongback.dataRecorder() .register("Left motors", left) .register("Right motors", right) .register("Sensitivity", sensitivity.scaleAsInt(1000)); }
@Override public void teleopPeriodic() { drive.arcade(driveSpeed.read(), turnSpeed.read()); }