![]() |
WPILibC++ 2025.3.2
|
A subsystem that uses a PIDController to control an output. More...
#include <frc2/command/PIDSubsystem.h>
Public Member Functions | |
| PIDSubsystem (frc::PIDController controller, double initialPosition=0) | |
| Creates a new PIDSubsystem. | |
| void | Periodic () override |
| This method is called periodically by the CommandScheduler. | |
| void | SetSetpoint (double setpoint) |
| Sets the setpoint for the subsystem. | |
| double | GetSetpoint () const |
| Gets the setpoint for the subsystem. | |
| virtual void | Enable () |
| Enables the PID control. | |
| virtual void | Disable () |
| Disables the PID control. | |
| bool | IsEnabled () |
| Returns whether the controller is enabled. | |
| frc::PIDController & | GetController () |
| Returns the PIDController. | |
Public Member Functions inherited from frc2::SubsystemBase | |
| void | InitSendable (wpi::SendableBuilder &builder) override |
| Initializes this Sendable object. | |
| std::string | GetName () const override |
| Gets the name of this Subsystem. | |
| void | SetName (std::string_view name) |
| Sets the name of this Subsystem. | |
| std::string | GetSubsystem () const |
| Gets the subsystem name of this Subsystem. | |
| void | SetSubsystem (std::string_view name) |
| Sets the subsystem name of this Subsystem. | |
| void | AddChild (std::string name, wpi::Sendable *child) |
| Associate a Sendable with this Subsystem. | |
Public Member Functions inherited from frc2::Subsystem | |
| virtual | ~Subsystem () |
| virtual void | SimulationPeriodic () |
| This method is called periodically by the CommandScheduler. | |
| template<std::derived_from< Command > T> | |
| void | SetDefaultCommand (T &&defaultCommand) |
| Sets the default Command of the subsystem. | |
| void | SetDefaultCommand (CommandPtr &&defaultCommand) |
| Sets the default Command of the subsystem. | |
| void | RemoveDefaultCommand () |
| Removes the default command for the subsystem. | |
| Command * | GetDefaultCommand () const |
| Gets the default command for this subsystem. | |
| Command * | GetCurrentCommand () const |
| Returns the command currently running on this subsystem. | |
| void | Register () |
| Registers this subsystem with the CommandScheduler, allowing its Periodic() method to be called when the scheduler runs. | |
| CommandPtr | RunOnce (std::function< void()> action) |
| Constructs a command that runs an action once and finishes. | |
| CommandPtr | Run (std::function< void()> action) |
| Constructs a command that runs an action every iteration until interrupted. | |
| CommandPtr | StartEnd (std::function< void()> start, std::function< void()> end) |
| Constructs a command that runs an action once and another action when the command is interrupted. | |
| CommandPtr | RunEnd (std::function< void()> run, std::function< void()> end) |
| Constructs a command that runs an action every iteration until interrupted, and then runs a second action. | |
| CommandPtr | StartRun (std::function< void()> start, std::function< void()> run) |
| Constructs a command that runs an action once, and then runs an action every iteration until interrupted. | |
| CommandPtr | Defer (wpi::unique_function< CommandPtr()> supplier) |
| Constructs a DeferredCommand with the provided supplier. | |
Public Member Functions inherited from wpi::Sendable | |
| virtual constexpr | ~Sendable ()=default |
Public Member Functions inherited from wpi::SendableHelper< SubsystemBase > | |
| constexpr | SendableHelper (const SendableHelper &rhs)=default |
| constexpr | SendableHelper (SendableHelper &&rhs) |
| constexpr SendableHelper & | operator= (const SendableHelper &rhs)=default |
| constexpr SendableHelper & | operator= (SendableHelper &&rhs) |
Protected Member Functions | |
| virtual double | GetMeasurement ()=0 |
| Returns the measurement of the process variable used by the PIDController. | |
| virtual void | UseOutput (double output, double setpoint)=0 |
| Uses the output from the PIDController. | |
Protected Member Functions inherited from frc2::SubsystemBase | |
| SubsystemBase () | |
| Constructor. | |
| SubsystemBase (std::string_view name) | |
| Constructor. | |
Protected Member Functions inherited from wpi::SendableHelper< SubsystemBase > | |
| constexpr | SendableHelper ()=default |
| constexpr | ~SendableHelper () |
Protected Attributes | |
| frc::PIDController | m_controller |
| PID controller. | |
| bool | m_enabled {false} |
| Whether PID controller output is enabled. | |
A subsystem that uses a PIDController to control an output.
The controller is run synchronously from the subsystem's periodic() method.
This class is provided by the NewCommands VendorDep
|
explicit |
Creates a new PIDSubsystem.
| controller | the PIDController to use |
| initialPosition | the initial setpoint of the subsystem |
|
virtual |
Disables the PID control.
Sets output to zero.
|
virtual |
Enables the PID control.
Resets the controller.
| frc::PIDController & frc2::PIDSubsystem::GetController | ( | ) |
Returns the PIDController.
|
protectedpure virtual |
Returns the measurement of the process variable used by the PIDController.
| double frc2::PIDSubsystem::GetSetpoint | ( | ) | const |
Gets the setpoint for the subsystem.
| bool frc2::PIDSubsystem::IsEnabled | ( | ) |
Returns whether the controller is enabled.
|
overridevirtual |
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.
Reimplemented from frc2::Subsystem.
| void frc2::PIDSubsystem::SetSetpoint | ( | double | setpoint | ) |
Sets the setpoint for the subsystem.
| setpoint | the setpoint for the subsystem |
|
protectedpure virtual |
Uses the output from the PIDController.
| output | the output of the PIDController |
| setpoint | the setpoint of the PIDController (for feedforward) |
|
protected |
PID controller.
|
protected |
Whether PID controller output is enabled.