Command to Button

I have been working on the new command based format for about 3 days. However, I never seem to be able to tie a command onto a button.

There is my code of RobotContainer which has the button mapping the command. I followed the examples on the wpi doc but can’t seemed to get it working. Am I doing something wrong? I mean I have to be… right?

1 Like

For starters, don’t use new when declaring commands; you can do it, but it is poor form since the library is written to allow you to simply stack-allocate the commands instead.

The code as you’ve written it looks like it should work; what diagnostics have you done to see what’s happening in more detail?

I mean I kind of didn’t know where to start… it compiled fine and pushed fine to the robot… and even the driving with joystick works fine… so there’s that…

A good place to start is to try a simple PrintCommand and see if that works. If that’s working, try putting print statements in your own commands to see if the commands are actually failing to schedule, or if they’re just not doing what you expect them to.

You can also watch the subsystem on Shuffleboard to see what commands are scheduled for it. So, at least you’d have an idea if the command is being scheduled at all.

How would I do this?

I would also add, if you’re not familiar with smartdashboard or shuffleboard, you should definitely get to know how to use it. It reduces your troubleshooting and tuning time dramatically if you use it the right way.

I tried printing out on the smartdashboard but it says that there is no current command or default command…
The drive still works tho…

Did you try running a PrintCommand?

I will do that right now

1 Like

I tried print but it didn’t work either

Could you push your current code so I could see it? The github page hasn’t updated.


Okay. So, that pretty solidly verifies that the commands aren’t running.

So, the next thing to do is verify that the buttons are being pressed (i.e. that your controller isn’t assigned to the wrong port). Try scheduling a RunCommand (you can set it as a default command for now) that prints the state of one of your bound joystick buttons, and see if it changes as expected when you press the button.

So the driver station recognizes the buttons when I press them. Should I still run a runcommand to check that?

Yes, because you may have incorrectly specified the controller port; you want to make sure your controller object in code is seeing the button presses.

Well but the axis on the same xbox joystick works just fine though… so i dont think there is the worry of incorrect controller port. I will try the code anyways just in case.

Use the SmartDashboard (or Shuffleboard) to schedule your command to take the controller out of the equation.

Your syntax for setting the default command looks correct (and you said it drives) so I think you should be seeing the scheduler information on Shuffleboard (unless there are shuffleboard bugs).

I will verify the shuffleboard piece in about 90 minutes or so when I have access to the robot at our school.

The button does get recognized. The boolean becomes true when I press on the button.

I am also having the same issue. The defaultCommand() for the drive system is working just fine and the robot is drive-able, but trying to create Commands to a button press under ConfigureButtonBindings does not work once code is deployed to the robot.