Historical lesson
This material predates the 2026 course and may use older WPILib, vendor APIs, team wrappers, and game rules. Its original version is not verified here. Do not copy its robot code into a 2026 project without migration and mentor review. Start with the 2026 subsystem lesson.
Quick Guide to Making a Subsystem
This article will just be a quick list of all of the steps necessary to program a subsystem. It won't go into any exact details, so consult the previous subsystem tutorials for that.
Create Project from snail-robot-template (if making a new project)
- Go to [https://github.com/FRC1257/snail-robot-template] and press the green
Use this templatebutton to create a new project if you are making a new project. If working on an already existing project, skip this step. - If working on the GitHub website, skip the rest of this section. If using Visual Studio Code, follow the rest of the instructions.
- Open GitHub Desktop and log in if necessary. Go to File > Clone Repository and then select the repository that you just created in Step 1.
- Select a local area on your computer where you will download this project to. It is highly recommended that you make a folder on your computer in your Desktop or Documents folder for containing all robotics projects.
- Press the Clone button and wait for the project to download.
- Open VS Code. If you chose to install it separately from an existing Visual Studio Code installation, make sure the version of Visual Studio Code you're opening says "WPILib VS Code" instead of just "VS Code".
- In VS Code, open the folder for your robot project by going to File > Open Folder. Then, select the folder containing your robot project. This should be the one that has the exact same name as the GitHub repository and should not be a parent folder of that.
Create Subsystem File
- Inside of the /subsystems folder, create a file to contain the code for your new subsystem. For instance, if you are making an elevator, it should be called
Elevator.java. Make sure you add the.javatag to show that this is a Java file. - If editing in GitHub, scroll to the bottom of this article and copy and paste the preexisting template into your subsystem file. Then, skip to Step 5.
- If editing inside of VS Code, then the class should have automatically generated as the following. If it did not, then make sure you have opened the correct version of VS Code and that you opened the correct folder.
package frc.robot.subsystems;
public class SubsystemNameHere {
}
- Add
extends SnailSubsystemafter the class definition. In VS Code, the subsystem name should now be underlined in red. Click on the subsystem name and then a yellow lightbulb icon should appear to the side. Click the lightbulb to see options to fix the error automatically and pressAdd unimplemented methods. In general, if you see a red underline in your code, you can use the lightbulb to help fix things such as import errors. - Add all of the actuators (motors and pneumatics) that are part of the subsystem. Make sure to declare them as variables before the constructor and then instantiate them inside of the constructor.
- Create an enum called
Statethat represents all of the possible states or operating modes the subsystem could be in. - Create a variable of the type
Statethat will hold the current state of the subsystem. - Add the switch statement to the
update()method that will look at the current state and set the actuators accordingly. - Add extra methods that will allow outside code to modify the state of the subsystem such as
manualControl()orintake().
Command
Repeat these steps for each command present in your subsystem.
- If editing in GitHub, creating the folder for the commands will be a bit difficult. To do so, go to the /robot directory. Then, create a file with the following name:
commands/subsystem_name_here/command_name_here.java. This will create the folders necessary. - If inside VS Code, you can simply right click /robot and create new folders. Create a folder called
commandsand then another folder inside that with the name of your subsystem (in lowercase). - Create the file for the command and make sure it follows this general structure: Subsystem Name + Action +
Command.java. For instance,ElevatorManualControlCommand.java(sometimes shortened toElevatorManualCommand.java). - Regardless of whether you are coding in GitHub or VS Code, scroll to the bottom of the article and copy the template for the Command into your file.
- Replace
CommandNameHerewith the name of your command andSubsystemNamdHerewith the name of your subsystem. Make sure the lowercasesubsystemNameHereuses lowercase. - If applicable, you may also need to add a
DoubleSupplierto the variables of the command and the constructor. See theArmtutorial for how to do this. - Depending on the action of your command, add the appropriate instructions for the command inside of
initialize()orexecute(). - Depending on the action of your command, you may want to change
isFinished()toreturn true;.
RobotContainer
- Go to the file
RobotContainer.java. - Under the line
private ArrayList<SnailSubsystem> subsystems;, create an instance of your subsystem like the following. Again, make sure you respect the capitalization.
private SubsystemNameHere subsystemNameHere;
- Inside of
configureSubsystems(), instantiate the new subsystem
subsystemNameHere = new SubsystemNameHere();
- If applicable, set up the default command on the subsystem. Some commands may also need you to pass a speed supplier into the constructor. Do this with the
::notation (check theArmtutorial for more details).
subsystemNameHere.setDefaultCommand(new SubsystemDefaultCommand(subsystemNameHere));
- Register the subsystem by adding it to the Arraylist.
subsystems.add(subsystemNameHere);
- Inside of
configureButtonBindings(), bind button actions to commands. This line is entirely customizable depending on which controller you're using, which button you're using, how the button should be bound to the command, and which command you're using. Below is just a few examples of command bindings we've used in the past.
operatorController.getButton(Button.kA.value).whileHeld(new IntakeIntakeCommand(intake));
operatorController.getButton(Button.kB.value).whileHeld(new IntakeEjectCommand(intake));
operatorController.getButton(Button.kX.value).whenPressed(new ClimbAdvanceCommand(climb));
operatorController.getButton(Button.kY.value).whenPressed(new ClimbBackCommand(climb));
Examples
For a list of tons of examples of subsystems we've programmed in the past, check this out for examples!
File Templates
Subsystem File
package frc.robot.subsystems;
public class Roller extends SnailSubsystem {
@Override
public void update() {
}
@Override
public void outputValues() {
}
@Override
public void setUpConstantTuning() {
}
@Override
public void getConstantTuning() {
}
}
Command File
package frc.robot.commands.intake;
import edu.wpi.first.wpilibj2.command.CommandBase;
public class CommandNameHere extends CommandBase {
private final SubsystemNameHere subsystemNameHere;
public CommandNameHere(SubsystemNameHere subsystemNameHere) {
this.subsystemNameHere = subsystemNameHere;
addRequirements(subsystemNameHere);
}
@Override
public void initialize() {
}
@Override
public void execute() {
}
@Override
public void end(boolean interrupted) {
}
@Override
public boolean isFinished() {
return false;
}
}