Running Commands during Autonomous¶
This documentation describes the use of the legacy command-based library. While this documentation has been preserved to help teams that have yet to do so, teams are strongly encouraged to migrate to the new command-based library.
Once commands are defined they can run in either the teleop or autonomous part of the program. In fact, the power of the command based programming approach is that you can reuse the same commands in either place. If the robot has a command that can shoot Frisbees during autonomous with camera aiming and accurate shooting, there is no reason not to use it to help the drivers during the teleop period of the game.
Our robot must do the following tasks during the autonomous period: pick up a soda can off the floor then drive a set distance from a table and deliver the can there. The process consists of:
Prepare to grab (move elevator, wrist, and gripper into position)
Grab the soda can
Drive to a distance from the table indicated by an ultrasonic rangefinder
Place the soda
Back off to a distance from the rangefinder
Re-stow the gripper
To do these tasks there are 6 commands that are executed sequentially as shown in this example (note that some of these, such as PlaceSoda are other command groups).
Setting the Command to Run during Autonomous¶
To get the SodaDelivery command to run as the Autonomous program,
Instantiate it in the
RobotInit()is called only once when the robot starts so it is a good time to create the command instance.
Start it during the
AutonomousInit()is called once at the start of the autonomous period so we schedule the command there.
Be sure the scheduler is called repeatedly during the
AutonomousPeriodic()is called (nominally) every 20ms so that is a good time to run the scheduler which makes a pass through all the currently scheduled commands.