For example, there could be a Motor Subsystem that controls a motor, or a shooting subsystem which uses multiple motors to shoot a object.
Subsystems are represented in java as classes who extend the SubsystemBase
abstract class
The only inherited method we will talk about is the periodic()
method.
The periodic()
method runs every 20 ms in the background. The typical use for periodic()
is code you want to run in the background once in a while. such as spinning the motor, checking if it's done, etc..
Some examples of what we use periodic()
for include:
Other methods are added as needed to fully encapsualte the component in question.
For example, a Motor Subsystem could have a run()
method to start the motor, and a stop()
method to stop the motor.
They are managed by the CommandScheduler, which schedules all commands in the queue.
The CommandScheduler also ensures that overlapping Commands (those who use the same Subsystems) dont run at the same time.
For more information about commands running in parallel, visit lesson 4.
These commands are represented in java as classes which extends the Command
abstract class,
and 38 inherited methods, but only 5 matter for creating commands for now: initialize()
, execute()
, end()
, isFinished()
, and addRequirements()
initialize(): |
|
execute(): |
|
isFinished(): |
You use this method to tell the robot when to end your command. |
end(boolean interrupted): |
It takes a boolean indicating if the command was interrupted or not, i.e.
|
addRequirements(Subsystem s): |
Instead, this method is used to register the subsystems that a command uses to the CommandScheduler This prevents the parrallel execution two different commands that use overlapping subsystems. |
Below is an example command that uses our previously defined Motor
Subsystem to run a motor for 1 second.