Programming_Basics

Subsystems

Prerequisite: Simulation

Robot functions are broken into subsystems. Each subsystem represents a distinct robot mechanism. Subsystems vary based on the game objectives, but they typically include:

In programing, subsystems serve as abstractions to encapsulate system information and behavior such as:

Within WPILib, there is a Command Scheduler that orchestrates when actions are performed by the subsystems. Commands will be covered in a separate section.

Create a subsysyem by following these steps:

Exercise

Create the Subsystem Class

1) Open project you created in Simulation section 1) Right-click on subsystems directory and select “Create a new class/commnad” 1) Select Subsystem from the menu and type in a name for the subsystem (e.g. “Arm”) and press enter 1) Add a print statement to the periodic method
Instantiation in constructor

Instantiate the Subsystem

1) Create an instance variable for the new subsystem. Note, you need to import the subsystem, hover over the class name and from the Quick Fix… menu select “Import {classname}”
Instantiation
1) In the constructor of RobotContainer, instantiate the Subsystem
Instantiation in constructor

Run Simulation

1) Simulate the robot code and observe the print statements
Output Subsystem

Reference: docs