Robot Core Documentation
Loading...
Searching...
No Matches
edu.wpi.first.wpilibj2.command.Subsystem Interface Reference
Inheritance diagram for edu.wpi.first.wpilibj2.command.Subsystem:
edu.wpi.first.wpilibj2.command.SubsystemBase

Public Member Functions

default void periodic ()
 
default void simulationPeriodic ()
 
default String getName ()
 
default void setDefaultCommand (Command defaultCommand)
 
default void removeDefaultCommand ()
 
default Command getDefaultCommand ()
 
default Command getCurrentCommand ()
 
default void register ()
 
default Command runOnce (Runnable action)
 
default Command run (Runnable action)
 
default Command startEnd (Runnable start, Runnable end)
 
default Command runEnd (Runnable run, Runnable end)
 
default Command defer (Supplier< Command > supplier)
 

Detailed Description

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 in their Command#getRequirements() method, 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(Subsystem...) method in order for the Subsystem#periodic() method to be called. It is recommended that this method be called from the constructor of users' Subsystem implementations. The SubsystemBase class offers a simple base for user implementations that handles this.

This class is provided by the NewCommands VendorDep

Member Function Documentation

◆ defer()

default Command edu.wpi.first.wpilibj2.command.Subsystem.defer ( Supplier< Command > supplier)

Constructs a DeferredCommand with the provided supplier. This subsystem is added as a requirement.

Parameters
supplierthe command supplier.
Returns
the command.
See also
DeferredCommand

◆ getCurrentCommand()

default Command edu.wpi.first.wpilibj2.command.Subsystem.getCurrentCommand ( )

Returns the command currently running on this subsystem. Returns null if no command is currently scheduled that requires this subsystem.

Returns
the scheduled command currently requiring this subsystem

◆ getDefaultCommand()

default Command edu.wpi.first.wpilibj2.command.Subsystem.getDefaultCommand ( )

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

Returns
the default command associated with this subsystem

◆ getName()

default String edu.wpi.first.wpilibj2.command.Subsystem.getName ( )

Gets the subsystem name of this Subsystem.

Returns
Subsystem name

Implemented in edu.wpi.first.wpilibj2.command.SubsystemBase.

◆ periodic()

default void edu.wpi.first.wpilibj2.command.Subsystem.periodic ( )

This method is called periodically by the CommandScheduler. Useful for updating subsystem-specific state that you don't want to offload to a Command. Teams should try to be consistent within their own codebases about which responsibilities will be handled by Commands, and which will be handled here.

◆ register()

default void edu.wpi.first.wpilibj2.command.Subsystem.register ( )

Registers this subsystem with the CommandScheduler, allowing its Subsystem#periodic() method to be called when the scheduler runs.

◆ removeDefaultCommand()

default void edu.wpi.first.wpilibj2.command.Subsystem.removeDefaultCommand ( )

Removes the default command for the subsystem. This will not cancel the default command if it is currently running.

◆ run()

default Command edu.wpi.first.wpilibj2.command.Subsystem.run ( Runnable action)

Constructs a command that runs an action every iteration until interrupted. Requires this subsystem.

Parameters
actionthe action to run
Returns
the command
See also
RunCommand

◆ runEnd()

default Command edu.wpi.first.wpilibj2.command.Subsystem.runEnd ( Runnable run,
Runnable end )

Constructs a command that runs an action every iteration until interrupted, and then runs a second action. Requires this subsystem.

Parameters
runthe action to run every iteration
endthe action to run on interrupt
Returns
the command

◆ runOnce()

default Command edu.wpi.first.wpilibj2.command.Subsystem.runOnce ( Runnable action)

Constructs a command that runs an action once and finishes. Requires this subsystem.

Parameters
actionthe action to run
Returns
the command
See also
InstantCommand

◆ setDefaultCommand()

default void edu.wpi.first.wpilibj2.command.Subsystem.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 Command#isFinished() method should always return false. Will automatically register this subsystem with the CommandScheduler.

Parameters
defaultCommandthe default command to associate with this subsystem

◆ simulationPeriodic()

default void edu.wpi.first.wpilibj2.command.Subsystem.simulationPeriodic ( )

This method is called periodically by the CommandScheduler. Useful for updating subsystem-specific state that needs to be maintained for simulations, such as for updating edu.wpi.first.wpilibj.simulation classes and setting simulated sensor readings.

◆ startEnd()

default Command edu.wpi.first.wpilibj2.command.Subsystem.startEnd ( Runnable start,
Runnable end )

Constructs a command that runs an action once and another action when the command is interrupted. Requires this subsystem.

Parameters
startthe action to run on start
endthe action to run on interrupt
Returns
the command
See also
StartEndCommand

The documentation for this interface was generated from the following file: