Connecting the operator interface to a command
Commands handle the behaviors for your robot. The command starts a subsystem to some operating mode like raising and elevator and continues running until it reaches some setpoint or timeout. The command then handles waiting for the subsystem to finish. That way commands can run in sequence to develop more complex behaviors.
RobotBuilder will also generate code to schedule a command to run whenever a button on your operator interface is pressed. You can also write code to run a command when a particular trigger condition has happened.
Set up a command to be run by the button press
In this example we want to schedule the "Elevator to top" command to run whenever joystick button 1 is pressed.
- The command to run is called "Elevator to top" and its function is to move the elevator on the robot to the top position
- Notice that the command requires the Elevator subsystem. This will ensure that this command starts running even if there was another operation happening at the same time that used the elevator. In this case the previous command would be interrupted.
Adding the Joystick to the robot program
Add a button and link it to the Elevator to top command
Add the button that should be pressed to the program
- Drag the joystick button to the Joystick (Driver gamepad) so that it's under the joystick
- Set the properties for the button: the button number, the command to run when the button is pressed, and the "When to run" property to "whenPressed" to indicate that the command should run whenever the joystick button is pressed.
Note: Joystick buttons must be dragged to (under) a Joystick. You must have a joystick in the Operator Interface folder before adding buttons.