WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
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::NamedSendable frc::Sendable

Public Member Functions

 PIDSubsystem (const std::string &name, double p, double i, double d)
 Instantiates a PIDSubsystem that will use the given p, i and d values. More...
 
 PIDSubsystem (const std::string &name, double p, double i, double d, double f)
 Instantiates a PIDSubsystem that will use the given p, i and d values. More...
 
 PIDSubsystem (const std::string &name, double p, double i, double d, double f, double period)
 Instantiates a PIDSubsystem that will use the given p, i and d 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 and d values. More...
 
 PIDSubsystem (double p, double i, double d, double f, double period)
 Instantiates a PIDSubsystem that will use the given p, i and d values. More...
 
void Enable ()
 Enables the internal PIDController.
 
void Disable ()
 Disables the internal PIDController.
 
virtual void PIDWrite (double output)
 
virtual double PIDGet ()
 
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...
 
void InitTable (std::shared_ptr< ITable > subtable) override
 Initializes a table for this sendable object. More...
 
std::string GetSmartDashboardType () const override
 
- Public Member Functions inherited from frc::Subsystem
 Subsystem (const std::string &name)
 Creates a subsystem with the given name. More...
 
void SetDefaultCommand (Command *command)
 Sets the default command. More...
 
CommandGetDefaultCommand ()
 Returns the default command (or null if there is none). More...
 
void SetCurrentCommand (Command *command)
 Sets the current command. More...
 
CommandGetCurrentCommand () const
 Returns the command which currently claims this subsystem. More...
 
virtual void InitDefaultCommand ()
 Initialize the default command for this subsystem. More...
 
std::string GetName () const override
 
void InitTable (std::shared_ptr< ITable > subtable) override
 Initializes a table for this sendable object. More...
 
std::shared_ptr< ITableGetTable () const override
 
std::string GetSmartDashboardType () const override
 
- Public Member Functions inherited from frc::ErrorBase
 ErrorBase (const ErrorBase &)=delete
 
ErrorBaseoperator= (const ErrorBase &)=delete
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (llvm::StringRef contextMessage, llvm::StringRef filename, llvm::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, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::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, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (llvm::StringRef errorMessage, Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const ErrorBase &rhs) const
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. 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...
 
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
 

Additional Inherited Members

- Static Public Member Functions inherited from frc::ErrorBase
static void SetGlobalError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber)
 
static void SetGlobalWPIError (llvm::StringRef errorMessage, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber)
 
static ErrorGetGlobalError ()
 Retrieve the current global error.
 
- Protected Attributes inherited from frc::Subsystem
std::shared_ptr< ITablem_table
 
- Protected Attributes inherited from frc::ErrorBase
Error m_error
 
- Protected Attributes inherited from frc::PIDSource
PIDSourceType m_pidSource = PIDSourceType::kDisplacement
 
- Static Protected Attributes inherited from frc::ErrorBase
static priority_mutex _globalErrorMutex
 
static Error _globalError
 

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::PIDSubsystem ( const std::string &  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::PIDSubsystem ( const std::string &  name,
double  p,
double  i,
double  d,
double  f 
)

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
fthe feedforward value
PIDSubsystem::PIDSubsystem ( const std::string &  name,
double  p,
double  i,
double  d,
double  f,
double  period 
)

Instantiates a PIDSubsystem that will use the given p, i and d 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::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::PIDSubsystem ( double  p,
double  i,
double  d,
double  f 
)

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
fthe feedforward value
PIDSubsystem::PIDSubsystem ( double  p,
double  i,
double  d,
double  f,
double  period 
)

Instantiates a PIDSubsystem that will use the given p, i and d 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

std::shared_ptr< PIDController > 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
double PIDSubsystem::GetPosition ( )

Returns the current position.

Returns
the current position
double PIDSubsystem::GetRate ( )

Returns the current rate.

Returns
the current rate
double PIDSubsystem::GetSetpoint ( )

Return the current setpoint.

Returns
The current setpoint
std::string PIDSubsystem::GetSmartDashboardType ( ) const
overridevirtual
Returns
the string representation of the named data type that will be used by the smart dashboard for this sendable

Implements frc::Sendable.

void PIDSubsystem::InitTable ( std::shared_ptr< ITable subtable)
overridevirtual

Initializes a table for this sendable object.

Parameters
subtableThe table to put the values in.

Implements frc::Sendable.

bool 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
void PIDSubsystem::SetAbsoluteTolerance ( double  absValue)
virtual

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

Parameters
absValueabsolute error which is tolerable
void 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
void 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
void PIDSubsystem::SetPercentTolerance ( double  percent)
virtual

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

Parameters
percentpercentage error which is tolerable
void 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
void 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 files: