Subsystems
Subsystems are all the different mechanical parts of the robot. However, code-wise, subsystems are helper classes that directly control the robot's hardware. Typically, there should be a subsystem for each major component of the robot's hardware (e.g., elevator, drivetrain, etc.) They can vary in size and functionality, but are designed as Singletons (classes with only one instance at a time) to prevent issues with syncing and even more unnecessary tears.
Subsystems' designs can have a ton of variation— a ClimbSubsystem subsystem wouldn't (hopefully) be the same length or design as something like a DriveSubsystem command.
void GetInstance()
As mentioned back in APCS vs FRC, people use GetInstance() to reference objects, to avoid wasted space and data iss
A good way to create GetInstance() methods is to create a static variable with the same type as your subsystem in your class header. If you're confused, this is what I'm talking about:
public class Subsystem {
private static Subsystem exampleSub;
}We'll return this value every time we call GetInstance(). We can also simply make a static method that returns this value. If the variable is null, you can simply use the constructor. This should be the only time you'll EVER use the Subsystem's constructor.
public static Subsystem getInstance() {
if (exampleSub == null) {
exampleSub = new Subsystem();
}
return exampleSub;
}void Periodic()
The Periodic() method is continuously called by Side Tangent- CommandScheduler while the subsystem is in use by a command. Because this method runs frequently, optimize the code for the sake of you three months later when rereading your code, the compiler, and the rest of the programmers.
Default Commands
Default Commands are commands that are run when nothing is using the subsystem. They're useful for handling background tasks, such as preventing gravity from dragging down an arm while idle.
It would be a shame if I "taught" you what default commands were without actually explaining how to set them! That's where SetDefaultCommand() becomes relevant!
SetDefaultCommand(Command c)
SetDefaultCommand() has one parameter, c. Guess what this method does with this command! (sets default command to whatever's in its parameters)
Last updated