SendableChooser

“For instance, you may wish to be able to select between multiple autonomous modes. You can do this by putting every possible Command you want to run as an autonomous into a SendableChooser and then put it into the SmartDashboard to have a list of options appear on the laptop. Once autonomous starts, simply ask the SendableChooser what the selected value is.”

The above is from the java doc. Is this intended for competition?
This is the line that makes me wonder
“Once autonomous starts, simply ask the SendableChooser what the selected value is.”

How do you do ask the SendableChooser during competition? Is it intended such that you choose a value for an autonomous program you want to run? And then it just runs in autonomous portion of the competition?

1 Like

If you are doing command based, you write a Command (often a CommandGroup) for each of your autonomous modes that you want your drivers to choose between. In robotInit, have the code send a SendableChooser to the smartdashboard, and populate the SendableChooser with the Commands you created. Driver places robot on the field, powers up, waits for communcation on the driver station, pulls up Smartdashboard, picks the one she wants for that match. In AutonomousInit() (which is called when autonomous starts), your code asks the SendableChooser for which one to run, and starts that one.

Clear example and verbage at https://wpilib.screenstepslive.com/s/4485/m/26401/l/255419-choosing-an-autonomous-program-from-smartdashboard.

If your code is not command based (IterativeRobot), the code can just send strings to the SendableChooser, and look to see what String got picked. If you do a File | New | Project … | Robot Java Project (not Example Robot Java Project) | Iterative Robot, you get a nice little Iterative Robot that does this; you can copy and paste the relevant bits into your code.

Having the robot save the setting when it gets set so can retrieve the last used value when it powers up is nice; then the drivers can set the autonomous while still in queue and tethered to the robot. I read there were changes in WPILIBj around saving networktables settings, haven’t looked at it yet. Get the easy version working first.