WPILibC++  2020.3.2-60-g3011ebe
frc::PIDSubsystem Class Referenceabstract

This class is designed to handle the case where there is a Subsystem which uses a single PIDController almost constantly (for instance, an elevator which attempts to stay at a constant height). More...

#include <PIDSubsystem.h>

Inheritance diagram for frc::PIDSubsystem:
frc::Subsystem frc::PIDOutput frc::PIDSource frc::ErrorBase frc::Sendable frc::SendableHelper< Subsystem >

Public Member Functions

 PIDSubsystem (const wpi::Twine &name, double p, double i, double d)
 Instantiates a PIDSubsystem that will use the given P, I, and D values. More...
 
 PIDSubsystem (const wpi::Twine &name, double p, double i, double d, double f)
 Instantiates a PIDSubsystem that will use the given P, I, D, and F values. More...
 
 PIDSubsystem (const wpi::Twine &name, double p, double i, double d, double f, double period)
 Instantiates a PIDSubsystem that will use the given P, I, D, and F values. More...
 
 PIDSubsystem (double p, double i, double d)
 Instantiates a PIDSubsystem that will use the given P, I, and D values. More...
 
 PIDSubsystem (double p, double i, double d, double f)
 Instantiates a PIDSubsystem that will use the given P, I, D, and F values. More...
 
 PIDSubsystem (double p, double i, double d, double f, double period)
 Instantiates a PIDSubsystem that will use the given P, I, D, and F values. More...
 
 PIDSubsystem (PIDSubsystem &&)=default
 
PIDSubsystemoperator= (PIDSubsystem &&)=default
 
void Enable ()
 Enables the internal PIDController.
 
void Disable ()
 Disables the internal PIDController.
 
void PIDWrite (double output) override
 
double PIDGet () override
 
void SetSetpoint (double setpoint)
 Sets the setpoint to the given value. More...
 
void SetSetpointRelative (double deltaSetpoint)
 Adds the given value to the setpoint. More...
 
void SetInputRange (double minimumInput, double maximumInput)
 Sets the maximum and minimum values expected from the input. More...
 
void SetOutputRange (double minimumOutput, double maximumOutput)
 Sets the maximum and minimum values to write. More...
 
double GetSetpoint ()
 Return the current setpoint. More...
 
double GetPosition ()
 Returns the current position. More...
 
double GetRate ()
 Returns the current rate. More...
 
virtual void SetAbsoluteTolerance (double absValue)
 Set the absolute error which is considered tolerable for use with OnTarget. More...
 
virtual void SetPercentTolerance (double percent)
 Set the percentage error which is considered tolerable for use with OnTarget(). More...
 
virtual bool OnTarget () const
 Return true if the error is within the percentage of the total input range, determined by SetTolerance(). More...
 
- Public Member Functions inherited from frc::Subsystem
 Subsystem (const wpi::Twine &name)
 Creates a subsystem with the given name. More...
 
 Subsystem (Subsystem &&)=default
 
Subsystemoperator= (Subsystem &&)=default
 
void SetDefaultCommand (Command *command)
 Sets the default command. More...
 
CommandGetDefaultCommand ()
 Returns the default command (or null if there is none). More...
 
wpi::StringRef GetDefaultCommandName ()
 Returns the default command name, or empty string is there is none. More...
 
void SetCurrentCommand (Command *command)
 Sets the current command. More...
 
CommandGetCurrentCommand () const
 Returns the command which currently claims this subsystem. More...
 
wpi::StringRef GetCurrentCommandName () const
 Returns the current command name, or empty string if no current command. More...
 
virtual void Periodic ()
 When the run method of the scheduler is called this method will be called.
 
virtual void InitDefaultCommand ()
 Initialize the default command for this subsystem. More...
 
std::string GetName () const
 Gets the name of this Subsystem. More...
 
void SetName (const wpi::Twine &name)
 Sets the name of this Subsystem. More...
 
std::string GetSubsystem () const
 Gets the subsystem name of this Subsystem. More...
 
void SetSubsystem (const wpi::Twine &subsystem)
 Sets the subsystem name of this Subsystem. More...
 
void AddChild (const wpi::Twine &name, std::shared_ptr< Sendable > child)
 Associate a Sendable with this Subsystem. More...
 
void AddChild (const wpi::Twine &name, Sendable *child)
 Associate a Sendable with this Subsystem. More...
 
void AddChild (const wpi::Twine &name, Sendable &child)
 Associate a Sendable with this Subsystem. More...
 
void AddChild (std::shared_ptr< Sendable > child)
 Associate a Sendable with this Subsystem. More...
 
void AddChild (Sendable *child)
 Associate a Sendable with this Subsystem. More...
 
void AddChild (Sendable &child)
 Associate a Sendable with this Subsystem. More...
 
void InitSendable (SendableBuilder &builder) override
 Initializes this Sendable object. More...
 
- Public Member Functions inherited from frc::ErrorBase
 ErrorBase (const ErrorBase &)=default
 
ErrorBaseoperator= (const ErrorBase &)=default
 
 ErrorBase (ErrorBase &&)=default
 
ErrorBaseoperator= (ErrorBase &&)=default
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 Retrieve the current error. More...
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual void SetErrnoError (const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set error information associated with a C library call that set an error to the "errno" global variable. More...
 
virtual void SetImaqError (int success, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetErrorRange (Error::Code code, int32_t minRange, int32_t maxRange, int32_t requestedValue, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const wpi::Twine &errorMessage, Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const ErrorBase &rhs) const
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 
void ClearGlobalErrors ()
 Clear global errors.
 
- Public Member Functions inherited from frc::SendableHelper< Subsystem >
 SendableHelper (const SendableHelper &rhs)=default
 
 SendableHelper (SendableHelper &&rhs)
 
SendableHelperoperator= (const SendableHelper &rhs)=default
 
SendableHelperoperator= (SendableHelper &&rhs)
 
std::string GetName () const
 Gets the name of this Sendable object. More...
 
void SetName (const wpi::Twine &name)
 Sets the name of this Sendable object. More...
 
void SetName (const wpi::Twine &subsystem, const wpi::Twine &name)
 Sets both the subsystem name and device name of this Sendable object. More...
 
std::string GetSubsystem () const
 Gets the subsystem name of this Sendable object. More...
 
void SetSubsystem (const wpi::Twine &subsystem)
 Sets the subsystem name of this Sendable object. More...
 
- Public Member Functions inherited from frc::PIDSource
virtual void SetPIDSourceType (PIDSourceType pidSource)
 Set which parameter you are using as a process control variable. More...
 
virtual PIDSourceType GetPIDSourceType () const
 

Protected Member Functions

std::shared_ptr< PIDControllerGetPIDController ()
 Returns the PIDController used by this PIDSubsystem. More...
 
virtual double ReturnPIDInput ()=0
 
virtual void UsePIDOutput (double output)=0
 
- Protected Member Functions inherited from frc::SendableHelper< Subsystem >
void SetName (const wpi::Twine &moduleType, int channel)
 Sets the name of the sensor with a channel number. More...
 
void SetName (const wpi::Twine &moduleType, int moduleNumber, int channel)
 Sets the name of the sensor with a module and channel number. More...
 
void AddChild (std::shared_ptr< Sendable > child)
 Add a child component. More...
 
void AddChild (void *child)
 Add a child component. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from frc::ErrorBase
static void SetGlobalError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static void SetGlobalWPIError (const wpi::Twine &errorMessage, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static Error GetGlobalError ()
 Retrieve the last global error.
 
static std::vector< ErrorGetGlobalErrors ()
 Retrieve all global errors.
 
- Protected Attributes inherited from frc::ErrorBase
Error m_error
 
- Protected Attributes inherited from frc::PIDSource
PIDSourceType m_pidSource = PIDSourceType::kDisplacement
 

Detailed Description

This class is designed to handle the case where there is a Subsystem which uses a single PIDController almost constantly (for instance, an elevator which attempts to stay at a constant height).

It provides some convenience methods to run an internal PIDController. It also allows access to the internal PIDController in order to give total control to the programmer.

Constructor & Destructor Documentation

◆ PIDSubsystem() [1/6]

frc::PIDSubsystem::PIDSubsystem ( const wpi::Twine name,
double  p,
double  i,
double  d 
)

Instantiates a PIDSubsystem that will use the given P, I, and D values.

Parameters
namethe name
pthe proportional value
ithe integral value
dthe derivative value

◆ PIDSubsystem() [2/6]

frc::PIDSubsystem::PIDSubsystem ( const wpi::Twine name,
double  p,
double  i,
double  d,
double  f 
)

Instantiates a PIDSubsystem that will use the given P, I, D, and F values.

Parameters
namethe name
pthe proportional value
ithe integral value
dthe derivative value
fthe feedforward value

◆ PIDSubsystem() [3/6]

frc::PIDSubsystem::PIDSubsystem ( const wpi::Twine name,
double  p,
double  i,
double  d,
double  f,
double  period 
)

Instantiates a PIDSubsystem that will use the given P, I, D, and F values.

It will also space the time between PID loop calculations to be equal to the given period.

Parameters
namethe name
pthe proportional value
ithe integral value
dthe derivative value
fthe feedfoward value
periodthe time (in seconds) between calculations

◆ PIDSubsystem() [4/6]

frc::PIDSubsystem::PIDSubsystem ( double  p,
double  i,
double  d 
)

Instantiates a PIDSubsystem that will use the given P, I, and D values.

It will use the class name as its name.

Parameters
pthe proportional value
ithe integral value
dthe derivative value

◆ PIDSubsystem() [5/6]

frc::PIDSubsystem::PIDSubsystem ( double  p,
double  i,
double  d,
double  f 
)

Instantiates a PIDSubsystem that will use the given P, I, D, and F values.

It will use the class name as its name.

Parameters
pthe proportional value
ithe integral value
dthe derivative value
fthe feedforward value

◆ PIDSubsystem() [6/6]

frc::PIDSubsystem::PIDSubsystem ( double  p,
double  i,
double  d,
double  f,
double  period 
)

Instantiates a PIDSubsystem that will use the given P, I, D, and F values.

It will use the class name as its name. It will also space the time between PID loop calculations to be equal to the given period.

Parameters
pthe proportional value
ithe integral value
dthe derivative value
fthe feedforward value
periodthe time (in seconds) between calculations

Member Function Documentation

◆ GetPIDController()

std::shared_ptr<PIDController> frc::PIDSubsystem::GetPIDController ( )
protected

Returns the PIDController used by this PIDSubsystem.

Use this if you would like to fine tune the PID loop.

Returns
The PIDController used by this PIDSubsystem

◆ GetPosition()

double frc::PIDSubsystem::GetPosition ( )

Returns the current position.

Returns
the current position

◆ GetRate()

double frc::PIDSubsystem::GetRate ( )

Returns the current rate.

Returns
the current rate

◆ GetSetpoint()

double frc::PIDSubsystem::GetSetpoint ( )

Return the current setpoint.

Returns
The current setpoint

◆ OnTarget()

virtual bool frc::PIDSubsystem::OnTarget ( ) const
virtual

Return true if the error is within the percentage of the total input range, determined by SetTolerance().

This asssumes that the maximum and minimum input were set using SetInput(). Use OnTarget() in the IsFinished() method of commands that use this subsystem.

Currently this just reports on target as the actual value passes through the setpoint. Ideally it should be based on being within the tolerance for some period of time.

Returns
True if the error is within the percentage tolerance of the input range

◆ SetAbsoluteTolerance()

virtual void frc::PIDSubsystem::SetAbsoluteTolerance ( double  absValue)
virtual

Set the absolute error which is considered tolerable for use with OnTarget.

Parameters
absValueabsolute error which is tolerable

◆ SetInputRange()

void frc::PIDSubsystem::SetInputRange ( double  minimumInput,
double  maximumInput 
)

Sets the maximum and minimum values expected from the input.

Parameters
minimumInputthe minimum value expected from the input
maximumInputthe maximum value expected from the output

◆ SetOutputRange()

void frc::PIDSubsystem::SetOutputRange ( double  minimumOutput,
double  maximumOutput 
)

Sets the maximum and minimum values to write.

Parameters
minimumOutputthe minimum value to write to the output
maximumOutputthe maximum value to write to the output

◆ SetPercentTolerance()

virtual void frc::PIDSubsystem::SetPercentTolerance ( double  percent)
virtual

Set the percentage error which is considered tolerable for use with OnTarget().

Parameters
percentpercentage error which is tolerable

◆ SetSetpoint()

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

Sets the setpoint to the given value.

If SetRange() was called, then the given setpoint will be trimmed to fit within the range.

Parameters
setpointthe new setpoint

◆ SetSetpointRelative()

void frc::PIDSubsystem::SetSetpointRelative ( double  deltaSetpoint)

Adds the given value to the setpoint.

If SetRange() was used, then the bounds will still be honored by this method.

Parameters
deltaSetpointthe change in the setpoint

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