Subsystems - hammerheads5000/Team-Documentation GitHub Wiki
A subsystem is a program that directly interfaces with the libraries. They provide most of the robot logic in converting what a command tells it to do to what the robot does. See WPILib Subsystem Documentation.
The basic structure of a subsystem is as follows:
import edu.wpi.first.wpilibj2.command.SubsystemBase;
public class ExampleSubsystem extends SubsystemBase {
// Instance variables
SomethingToControl someComponent;
SomethingElseToControl anotherComponent;
// Constructor - runs when created
public ExampleSubsystem(SomethingToControl someComponent, SomethingElseToControl anotherComponent) {
this.someComponent = someComponent;
this.anotherComponent = anotherComponent;
this.someComponent.reset();
}
// Most of the subsystem should be in methods that commands will call
public void someAction(int amount) {
someComponent.doSomething(amount);
}
public int anotherAction() {
anotherComponent.doAThing(someComponent.getSomeValue());
return anotherComponent.getAValue();
}
@Override
public void periodic() {
// This method will ALWAYS be called once per scheduler run
// Usually do not use this except sometimes in swerve
}
}
Subsystems are usually created in RobotContainer.java, and then passed as arguments to commands, which call their methods.