Prerequisite: Subsystems Exercise
A Command represents an action that the robot can perform.
A command is a special class in WPILib which must contain the following methods:
The Command Scheduler is a core utility in WPILib which orchestrates activity amongst subsystems.
WPILib contains various types of Commands to achieve specific functionality. There are also helpful shortcuts available for implementing common tasks. Heres a shortlist of Command types that are used frequently in Cyber Cat code base:
After you complete the following exercise, check out the refernece material at the end of this document to explore these Command types.
Background: Commands:
1) Add a position instance variable to the subsystem(arm).
2) Add a member functions(setter and getter functions) to set and get the position of the arm.
1) Open project from Simulation section
2) Right-click on subsystems directory and select “Create a new class/commnad”
3) Select Command from the menu and type in a name for the command (e.g. “ArmPrint”) and press enter
4) Create an instance of subsytem(Use the same subsystem(e.g. Arm)ArmSubsystem,
and add it to the command using addRequirements()
5) Set the postion of the arm in the execute() and access the postion variable using getPostion().
1) Add Arm subsysytem instance variable in ‘RobotContainer’.
2) Instantiate the subsystem, and set ‘Default’ command on Arm subsystem in the constructor.
Simulate the robot code
Choose the ‘Teleoperated’ option in the GUI
Observe the print statements