Subsystem Groups and the Robot Subsystem
NextFTC offers a SubsystemGroup
class, which allows you to group multiple subsystems together for easier management and control. This is particularly useful for complex robots with many subsystems, as it enables you to treat them as a single unit.
This can be used in multiple ways. Some examples include a double-jointed arm mechanism, or a swerve drive train with multiple modules that can be controlled independently. This example also illustrates using a SubsystemGroup
to represent your robot as a whole, allowing for more streamlined control and coordination between subsystems.
Just like regular subsystems, subsystem groups have an initialize
and periodic
function; in addition, the initialize
function of each subsystem in the group will be called when the group is initialized, and the periodic
function of each subsystem will be called every loop.
Creating a Subsystem Group
To create a SubsystemGroup
, you must create a subclass of SubsystemGroup
, and provide the necessary subsystem instances to its constructor.
object MySubsystemGroup() : SubsystemGroup(
MyFirstSubsystem,
MySecondSubsystem
)
Using a Subsystem Group
To register a subsystem group, you can simply pass its instance to the SubsystemComponent
constructor in a NextFtcOpMode the way you would with a regular subsystem:
init {
addComponents(
SubsystemComponent(MySubsystemGroup)
)
}
The Robot Subsystem
A Robot class is often used in FTC robot programs to encapsulate the robot's subsystems and provide a unified interface for controlling them. This class typically contains references to all of the robot's subsystems, as well as methods for initializing and updating them, and for actions that involve multiple subsystems.
In NextFTC, we can create a Robot class that extends the SubsystemGroup class, allowing us to treat the entire robot as a single subsystem. This makes it easier to manage the robot's subsystems and their interactions.
Lets assume the Claw and Lift subsystems are both part of our robot, and implemented as described in those sections. We can create a Robot class that encapsulates these subsystems and provides a unified interface for controlling them.
object MyRobot : SubsystemGroup(
Claw,
Lift
)
Now, we can add methods to MyRobot
that control the robot as a whole, by interacting with its subsystems.
val score = SequentialGroup(
Lift.toHigh,
Claw.open
).named("Score")
You might notice that we use the .named()
function to give our command a name. This can be useful for debugging and logging purposes, as it allows us to easily identify the command in the logs.
All command groups can be named in this way, making it easier to manage and debug complex robot behaviors, though they also have default names that include the names of their constituent commands. Depending on the complexity of a given command, you may choose to name it explicitly for clarity, especially if it is part of a larger sequence of commands, or keep its default name for simplicity.