How to use the Rumble function on a Xbox controller (Both 360 and one) in Java

So I was figuring that Having some feed back would be wonderful for when we hit the walls. As I was looking through the WPILibj Libraries for the Xbox controller, I saw Rumble, or to be more precise, * GenericHID.RumbleType. I am deeply interested in:

  1. How to set up the robot to give live Rumble feedback, and
  2. How to set up to code for all of this in java.

Thanks in advance!
~Robert from Roboticus Team 6553
I’m starting to question if the rumble is the function that vibrates the controller. If so, then the question stands. If not, than please explain what it is and how to utilize it. Thanks!

1 Like
controller.setRumble(RumbleType.kLeftRumble, value);
controller.setRumble(RumbleType.kRightRumble, value);

Where controller is your xbox controller object and value is a value between 0 and 1 that sets the rumble strength.

kLeftRumble and kRightRumble are the two different rumble motors on each side of the controller. IIRC, one provides a stronger, lower frequency rumble and the other provides a weaker, higher frequency rumble. We usually just set both at the same time to the same value.

See the setRumble method in the javadoc:

Remember to set your rumbles to 0 when you disable. Unlike the motors on the robot, controller rumble is not disabled with the robot unless explicity set to 0.

1 Like

Thanks! How would i set up the robot to give the feed back though, if at all possible?

If you have a boolean bool you want to use as the trigger for rumble:

if(bool)  {
  controller.setRumble(RumbleType.kLeftRumble, 1.0);
  controller.setRumble(RumbleType.kRightRumble, 1.0);
} else {
  controller.setRumble(RumbleType.kLeftRumble, 0.0);
  controller.setRumble(RumbleType.kRightRumble, 0.0);

examples: sensor is within threshold, button/digital sensor is triggered, etc

If you have some sort of analog value value from 0 to 1 that you’d like to use to vary rumble:

controller.setRumble(RumbleType.kLeftRumble, value);
controller.setRumble(RumbleType.kRightRumble, value);

examples: distance sensor, current draw, acceleration(impacts!)

Also remember to explicitly set your rumbles to 0 on transition into disabled like so:

public void disabledInit() {  // Disabled init just in case you'd still like to rumble while the robot is disabled.
  controller.setRumble(RumbleType.kLeftRumble, value);
  controller.setRumble(RumbleType.kRightRumble, value);
1 Like


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