Class Subsystem

Inheritance Relationships

Derived Types

Class Documentation

class Subsystem

A robot subsystem. Subsystems are the basic unit of robot organization in the Command-based framework; they encapsulate low-level hardware objects (motor controllers, sensors, etc) and provide methods through which they can be used by Commands. Subsystems are used by the CommandScheduler’s resource management system to ensure multiple robot actions are not “fighting” over the same hardware; Commands that use a subsystem should include that subsystem by adding it as a requirement via addSubsystemRequirement, and resources used within a subsystem should generally remain encapsulated and not be shared by other parts of the robot.

Subsystems must be registered with the scheduler with the CommandScheduler.registerSubsystem() function in order for the refresh() function to be called.

Subclassed by tap::control::chassis::ChassisSubsystemInterface, tap::control::setpoint::SetpointSubsystem, tap::control::turret::TurretSubsystemInterface

Public Functions

Subsystem(Drivers *drivers)
virtual ~Subsystem()
inline virtual void initialize()

Called once when you add the Subsystem to the commandScheduler stored in the Drivers class.

void registerAndInitialize()

Calls initialize and registers the subsystem with the command scheduler passed in through the driver.

void setDefaultCommand(Command *defaultCommand)

Sets the default Command of the Subsystem. The default Command will be automatically scheduled when no other Commands are scheduled that require the Subsystem. Default Commands should generally not end on their own, i.e. their isFinished() function should always return false. Will automatically register this Subsystem with the CommandScheduler if no other Command is scheduled for this Subsystem.

Parameters:

defaultCommand – the default Command to associate with this subsystem

inline Command *getDefaultCommand() const

Gets the default command for this subsystem. Returns nullptr if no default command is currently associated with the subsystem.

Returns:

the default command associated with this subsystem

inline virtual void refresh()

Called in the scheduler’s run function assuming this command has been registered with the scheduler. This function should contain code that must be periodically updated and is generic to the subsystem (i.e. updating a control loop generic to this subsystem). This function should not contain command specific control code. When you create a subclass of Subsystem, you should overwrite this virtual function.

Must be virtual otherwise scheduler will refer to this function rather than looking in child for this function.

inline virtual void refreshSafeDisconnect()

Called in the scheduler’s run function before removing commands when safe disconnecting. This function should contain code that safely shuts down the subsystem (i.e. shutting off motors). All subsystems must implement this virtual function.

void setTestCommand(Command *testCommand)

Sets the test command of the Subsystem. The test command can be run by calling CommandScheduler::runHardwareTests.

Test commands must keep track of their state so that Command::isFinished continues to return true after the command has ended.

Parameters:

testCommand – the test Command to associate with this subsystem

inline Command *getTestCommand() const

Gets the test command for this subsystem. Returns nullptr if no test command is currently associated with the subsystem.

Returns:

the test command associated with this subsystem

virtual const char *getName() const
inline int getGlobalIdentifier() const

Protected Attributes

Drivers *drivers