Changing button binding while robot is running

I have a program that is able to change the port of the controller object, and then will update all of the subsequent buttons inside of it. The problem is that the button bindings will not update when the controller/buttons are updated. SmartMap just returns button Ids.
I have tried calling configureButtonBinding multiple times, and that causes the controller to run the button bindings multiple times if the controller has not changed ports.

(In ControllerTracking class, called whenever teleop init because changing port numbers disables anyways)
public static void updatePortNumbers() {
JoystickTypes = new HIDType[5];
GenericHID testHID;
for (int i = 0; i < JoystickTypes.length; i++) {
testHID = new GenericHID(i);
if (testHID.isConnected()) {
JoystickTypes[i] = testHID.getType();
dynamicControllerXbox1.object = new XboxController(indexOf(JoystickTypes, HIDType.kXInputGamepad));

(In robot container)
public static class dynamicControllerXbox1 {
public static XboxController object = new XboxController(5);
public static JoystickButton A;
public static JoystickButton B;
public static JoystickButton X;
public static JoystickButton Y;
public static JoystickButton LeftBumper;
public static JoystickButton RightBumper;
public static JoystickButton LeftStickPress;
public static JoystickButton RightStickPress;
public static JoystickButton Share;
public static JoystickButton Options;
public static void updateController() {
System.out.println("Assigning dXbox: " + object.getPort());
A = new JoystickButton(object, OIConstants.SmartMap(object, “A”));
B = new JoystickButton(object, OIConstants.SmartMap(object, “B”));
X = new JoystickButton(object, OIConstants.SmartMap(object, “X”));
Y = new JoystickButton(object, OIConstants.SmartMap(object, “Y”));
LeftBumper = new JoystickButton(object, OIConstants.SmartMap(object, “LBump”));
RightBumper = new JoystickButton(object, OIConstants.SmartMap(object, “RBump”));
LeftStickPress = new JoystickButton(object, OIConstants.SmartMap(object, “LStick”));
RightStickPress = new JoystickButton(object, OIConstants.SmartMap(object, “RStick”));
Share = new JoystickButton(object, OIConstants.SmartMap(object, “DoubleSquare”));
Options = new JoystickButton(object, OIConstants.SmartMap(object, “Options”));
private void configureButtonBindings() {
dynamicControllerXbox1.A.whileActiveContinuous(()-> System.out.println(dynamicControllerXbox1.object.getPort() + “: dynamic XBOX”));

1 Like

Not a solution to your specific issue, but this whole class feels like a solution in search of a problem… what exactly are you trying to do with this class?


It’s not clear what you’re trying to accomplish with that code, but you cannot remove a single button binding. CommandScheduler.getActiveButtonLoop().clear() is about your only option, it’ll clear all button bindings.

Are you aware you can drag the controllers around in Driver Station to choose the ids?

You can create additional EventLoop instances, pass the relevant one to all your Triggers (there’s an optional constructor parameter) and then change which one is polled by calling CommandScheduler.setActiveButtonLoop().

I will add that as others have said, the correct solution here would to drag the joystick indexes and lock them in the DS.

Thank you, that is exactly what I was looking for, but when I tested it, that method does not seem to exist.
The problem I was solving is that if you have multiple controllers that have the same name, the driverstation can not tell which controller was which, so the first controller reconnected becomes the first assigned. Also, it would be easier to not have to worry about the port numbers at all. I am still working on more specific identification, but if anyone asks I can share more.

In Driver Station, you can tell which controller is which by pressing a button on the controller. That controller will be highlighted on the USB tab.

1 Like

ie. prevent having to do that this year.

I actually am not able to access any of those methods inside the robot. How would I reference those methods from a static field?

Well you wouldn’t, because they’re not static methods. You would need an instance of the scheduler to interact with those methods.

That said, I’d like to reiterate what I (and others) have already said. Any solution you come up with is going to be significantly more complex than simply testing your controllers with a button press and reordering if needed.

Very true. Well, thanks for all of your help!

1 Like