Programming multiple joystick axes to control driveTrain


This year the team has decided to build a button board with two joysticks to control their arm and boom mechanisms using the Y-axis of each joystick (in addition to the buttons for fixed setpoints). They want to add fine drivetrain positioning control using the X-Axis of these two joysticks as well to strafe and rotate the robot.

We currently using a normal joystick (Logitech Extreme Pro) for the primary driving capabilities of the driveTrain. We are using a mecanum drive and ultimately call the driveCartesian method. In, we use setDefaultCommand as normal for using the Logitech to drive.

driveTrain.setDefaultCommand( new DriveCommand(driveTrain,
() → joystick.getX(),
() → -joystick.getY(),
() → joystick.getZ(),
() → driveTrain.normalizeThrottle(-joystick.getThrottle())));

It is not clear how we should program the code to utilize the 2 joysticks from the button board for to fine control X and Z of the driveTrain separately from the Logitech.

Can multiple setDefaultCommand be used or does a second one override the first setDefaultCommand in code if used? We tried adding the following before previous command for the Logitech, but that does not seem to work:

driveTrain.setDefaultCommand( new DriveCommand(driveTrain,
() → -bboard_left.getX(), //strafe
() → 0.0,
() → -bboard_right.getX(), //rotate
() → Constants.kPlacementSpeed)); //slower fixed speed for fine control

Not sure how to implement this. Any recommendation would be greatly appreciated to utilize the alternate axis inputs to control the driveTrain.

Thank you.

One way you could handle this is to feed values into the DriveCommand from the button board at all times.

Just make sure the bboard_left.getX() methods default to a 0.0 output when not in use.

driveTrain.setDefaultCommand( new DriveCommand(driveTrain,
() → joystick.getX() + bboard_left.getX(),
() → -joystick.getY() + bboard_left.getY(),
() → joystick.getZ() + bboard_left.getZ()
() → driveTrain.normalizeThrottle(-joystick.getThrottle())));

If that doesn’t work, (not sure if they need their own supplier, it would look like this:

driveTrain.setDefaultCommand( new DriveCommand(driveTrain,
() → joystick.getX(),
() → -joystick.getY(),
() → joystick.getZ(),
() → driveTrain.normalizeThrottle(-joystick.getThrottle(),
()-> bboard_left.getX(),
()-> bboard_left.getY(),

Then add them together inside the command in periodic.

Thank you. Will give those suggestions a try this weekend when we meet. Appreciate the quick reply.

After changing the default command, you have to schedule it. This will stop the old default command that’s already running and start the new one.

Here is how we handle switching drive schemes.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.