DeepBlueRobotics / RobotCodeSimulator

0 stars 0 forks source link

Mock Joystick class to be keyboard compatible #10

Closed alexander-mcdowell closed 3 years ago

brettle commented 3 years ago

Fyi, I've asked in the beta discussions for documentation/info about the joystick simulation support that's supposed to be in the beta.

alexander-mcdowell commented 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.

brettle commented 3 years ago

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).

alexander-mcdowell commented 3 years ago

Actually, we can avoid the problem by replacing passing in the joystick with some Supplier methods. For example, in RobotContainer, instead of writing drivetrain.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.

CoolSpy3 commented 3 years ago

Joysticks are now keyboard compatible via the WPILib simulator.