Closed alexander-mcdowell closed 3 years ago
@CoolSpy3 pointed out that the simulated joystick must also split the inputs from the real joystick across three ports. For example, the left throttle would map to port 0 (left joystick), the right throttle would map to port 1 (right joystick), and the buttons would map to port 2 (manipulator). We would also need to add some keys on the keyboard to represent buttons on the left and right joysticks.
Seems like overkill to map a single joystick to multiple ports. If you have a joystick, it should be possible to use it to drive the simulated robot by changing the mappings as necessary in an isSimulated() clause. If you don't have a joystick, the simulator should allow you to use your keyboard to simulate joystick inputs (outside the robot code).
Actually, we can avoid the problem by replacing passing in the joystick with some Supplierdrivetrain.setDefaultCommand(new Drive(drivetrain, joystick));
we write something like:
Supplier<Double> speedFunction, rotFunction;
if (RobotBase.isReal()) {
speedFunction = () -> { return -leftJoy.getY(); };
rotFunction = () -> { return rightJoy.getX(); };
} else {
speedFunction = () -> { return -joystick.getRawAxis(1); };
rotFunction = () -> { return joystick.getRawAxis(2); };
}
drivetrain.setDefaultCommand(new Drive(drivetrain, speedFunction, rotFunction));
If we were using the simulator, only joystick
would be used; if we were deploying to the robot, we would use leftJoy
and rightJoy
.
Fyi, I've asked in the beta discussions for documentation/info about the joystick simulation support that's supposed to be in the beta.