WPILibC++ 2024.3.2
frc2::PIDSubsystem Class Referenceabstract

A subsystem that uses a PIDController to control an output. More...

#include <frc2/command/PIDSubsystem.h>

Inheritance diagram for frc2::PIDSubsystem:
frc2::SubsystemBase frc2::Subsystem wpi::Sendable wpi::SendableHelper< SubsystemBase >

Public Member Functions

 PIDSubsystem (frc::PIDController controller, double initialPosition=0)
 Creates a new PIDSubsystem. More...
 
void Periodic () override
 This method is called periodically by the CommandScheduler. More...
 
void SetSetpoint (double setpoint)
 Sets the setpoint for the subsystem. More...
 
double GetSetpoint () const
 Gets the setpoint for the subsystem. More...
 
virtual void Enable ()
 Enables the PID control. More...
 
virtual void Disable ()
 Disables the PID control. More...
 
bool IsEnabled ()
 Returns whether the controller is enabled. More...
 
frc::PIDControllerGetController ()
 Returns the PIDController. More...
 
- Public Member Functions inherited from frc2::SubsystemBase
void InitSendable (wpi::SendableBuilder &builder) override
 Initializes this Sendable object. More...
 
std::string GetName () const override
 Gets the name of this Subsystem. More...
 
void SetName (std::string_view name)
 Sets the name of this Subsystem. More...
 
std::string GetSubsystem () const
 Gets the subsystem name of this Subsystem. More...
 
void SetSubsystem (std::string_view name)
 Sets the subsystem name of this Subsystem. More...
 
void AddChild (std::string name, wpi::Sendable *child)
 Associate a Sendable with this Subsystem. More...
 
- Public Member Functions inherited from frc2::Subsystem
virtual ~Subsystem ()
 
virtual void Periodic ()
 This method is called periodically by the CommandScheduler. More...
 
virtual void SimulationPeriodic ()
 This method is called periodically by the CommandScheduler. More...
 
virtual std::string GetName () const
 Gets the name of this Subsystem. More...
 
template<std::derived_from< Command > T>
void SetDefaultCommand (T &&defaultCommand)
 Sets the default Command of the subsystem. More...
 
void SetDefaultCommand (CommandPtr &&defaultCommand)
 Sets the default Command of the subsystem. More...
 
void RemoveDefaultCommand ()
 Removes the default command for the subsystem. More...
 
CommandGetDefaultCommand () const
 Gets the default command for this subsystem. More...
 
CommandGetCurrentCommand () const
 Returns the command currently running on this subsystem. More...
 
void Register ()
 Registers this subsystem with the CommandScheduler, allowing its Periodic() method to be called when the scheduler runs. More...
 
CommandPtr RunOnce (std::function< void()> action)
 Constructs a command that runs an action once and finishes. More...
 
CommandPtr Run (std::function< void()> action)
 Constructs a command that runs an action every iteration until interrupted. More...
 
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. More...
 
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. More...
 
CommandPtr Defer (wpi::unique_function< CommandPtr()> supplier)
 Constructs a DeferredCommand with the provided supplier. More...
 
- Public Member Functions inherited from wpi::Sendable
virtual ~Sendable ()=default
 
virtual void InitSendable (SendableBuilder &builder)=0
 Initializes this Sendable object. More...
 
- Public Member Functions inherited from wpi::SendableHelper< SubsystemBase >
 SendableHelper (const SendableHelper &rhs)=default
 
 SendableHelper (SendableHelper &&rhs)
 
SendableHelperoperator= (const SendableHelper &rhs)=default
 
SendableHelperoperator= (SendableHelper &&rhs)
 

Protected Member Functions

virtual double GetMeasurement ()=0
 Returns the measurement of the process variable used by the PIDController. More...
 
virtual void UseOutput (double output, double setpoint)=0
 Uses the output from the PIDController. More...
 
- Protected Member Functions inherited from frc2::SubsystemBase
 SubsystemBase ()
 Constructor. More...
 
 SubsystemBase (std::string_view name)
 Constructor. More...
 
- Protected Member Functions inherited from wpi::SendableHelper< SubsystemBase >
 SendableHelper ()=default
 
 ~SendableHelper ()
 

Protected Attributes

frc::PIDController m_controller
 PID controller. More...
 
bool m_enabled {false}
 Whether PID controller output is enabled. More...
 

Detailed Description

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

See also
PIDController

Constructor & Destructor Documentation

◆ PIDSubsystem()

frc2::PIDSubsystem::PIDSubsystem ( frc::PIDController  controller,
double  initialPosition = 0 
)
explicit

Creates a new PIDSubsystem.

Parameters
controllerthe PIDController to use
initialPositionthe initial setpoint of the subsystem

Member Function Documentation

◆ Disable()

virtual void frc2::PIDSubsystem::Disable ( )
virtual

Disables the PID control.

Sets output to zero.

◆ Enable()

virtual void frc2::PIDSubsystem::Enable ( )
virtual

Enables the PID control.

Resets the controller.

◆ GetController()

frc::PIDController & frc2::PIDSubsystem::GetController ( )

Returns the PIDController.

Returns
The controller.

◆ GetMeasurement()

virtual double frc2::PIDSubsystem::GetMeasurement ( )
protectedpure virtual

Returns the measurement of the process variable used by the PIDController.

Returns
the measurement of the process variable

◆ GetSetpoint()

double frc2::PIDSubsystem::GetSetpoint ( ) const

Gets the setpoint for the subsystem.

Returns
the setpoint for the subsystem

◆ IsEnabled()

bool frc2::PIDSubsystem::IsEnabled ( )

Returns whether the controller is enabled.

Returns
Whether the controller is enabled.

◆ Periodic()

void frc2::PIDSubsystem::Periodic ( )
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.

◆ SetSetpoint()

void frc2::PIDSubsystem::SetSetpoint ( double  setpoint)

Sets the setpoint for the subsystem.

Parameters
setpointthe setpoint for the subsystem

◆ UseOutput()

virtual void frc2::PIDSubsystem::UseOutput ( double  output,
double  setpoint 
)
protectedpure virtual

Uses the output from the PIDController.

Parameters
outputthe output of the PIDController
setpointthe setpoint of the PIDController (for feedforward)

Member Data Documentation

◆ m_controller

frc::PIDController frc2::PIDSubsystem::m_controller
protected

PID controller.

◆ m_enabled

bool frc2::PIDSubsystem::m_enabled {false}
protected

Whether PID controller output is enabled.


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