What is Command Based Programming? - sateeshs/frc2024-scratchpad GitHub Wiki
Command Based Programming is a programming structure used by FRC to organize how the code is setup and run in a way similar to function calling. The main difference between the two is that a command is a completely seperate file that gets called in something called a scheduler. With this style though, you can easily run multiple commands, set commands to run as a default state, and even cancel commands. This is a very powerful tool that can be used to make your robot do many things at once.
Basic Terminology
Command
A command is a file that contains a set of instructions that can be called by the scheduler. This is the main part of the command based programming structure. Commands can be run in parallel, run as a default state, or even canceled.
Scheduler
The scheduler is a part of the command based programming structure that runs the commands. It is the main part of the command based programming structure. The scheduler is what runs the commands and makes sure that they are running correctly. This process runs about every 20 milliseconds and checks for mapped button presses, joystick movements, and other inputs.
Subsystem
A subsystem is a part of the robot that is controlled by a command. This can be the drive train, the intake, or even the shooter. Subsystems are the main part of the command based programming structure. Subsystems are what the commands control given functions created inside of them and contain all of the setup for components (such as motors for wheels in a Drive Train).
RobotContainer
The robot container is a file that contains all of the commands and subsystems. This is the main part of the command based programming structure. The robot container is what the scheduler runs. This file is where you will map all of the buttons and joysticks to the commands and subsystems, along with all of the other requirements that should be pre-written when a command based project is created.
How to Use Command Based Programming
Creating a Command
To create a command, you need to create a new file in the commands folder. The file should be named after the command. For example, if you were to create a command that drives the robot forward, you would name the file DriveForward. An example of a command is shown below.