LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
okapi::IterativePosPIDController Class Reference

#include <iterativePosPidController.hpp>

Inheritance diagram for okapi::IterativePosPIDController:
okapi::IterativePositionController< double, double > okapi::IterativeController< Input, Output > okapi::ClosedLoopController< Input, Output > okapi::ControllerOutput< Input >

Classes

struct  Gains
 

Public Member Functions

 IterativePosPIDController (double ikP, double ikI, double ikD, double ikBias, const TimeUtil &itimeUtil, std::unique_ptr< Filter > iderivativeFilter=std::make_unique< PassthroughFilter >(), std::shared_ptr< Logger > ilogger=Logger::getDefaultLogger())
 Position PID controller.
 
 IterativePosPIDController (const Gains &igains, const TimeUtil &itimeUtil, std::unique_ptr< Filter > iderivativeFilter=std::make_unique< PassthroughFilter >(), std::shared_ptr< Logger > ilogger=Logger::getDefaultLogger())
 Position PID controller.
 
double step (double inewReading) override
 Do one iteration of the controller.
 
void setTarget (double itarget) override
 Sets the target for the controller.
 
void controllerSet (double ivalue) override
 Writes the value of the controller output.
 
double getTarget () override
 Gets the last set target, or the default target if none was set.
 
double getTarget () const
 Gets the last set target, or the default target if none was set.
 
double getProcessValue () const override
 
double getOutput () const override
 Returns the last calculated output of the controller.
 
double getMaxOutput () override
 Get the upper output bound.
 
double getMinOutput () override
 Get the lower output bound.
 
double getError () const override
 Returns the last error of the controller.
 
bool isSettled () override
 Returns whether the controller has settled at the target.
 
void setSampleTime (QTime isampleTime) override
 Set time between loops in ms.
 
void setOutputLimits (double imax, double imin) override
 Set controller output bounds.
 
void setControllerSetTargetLimits (double itargetMax, double itargetMin) override
 Sets the (soft) limits for the target range that controllerSet() scales into.
 
void reset () override
 Resets the controller's internal state so it is similar to when it was first initialized, while keeping any user-configured information.
 
void flipDisable () override
 Changes whether the controller is off or on.
 
void flipDisable (bool iisDisabled) override
 Sets whether the controller is off or on.
 
bool isDisabled () const override
 Returns whether the controller is currently disabled.
 
QTime getSampleTime () const override
 Get the last set sample time.
 
virtual void setIntegralLimits (double imax, double imin)
 Set integrator bounds.
 
virtual void setErrorSumLimits (double imax, double imin)
 Set the error sum bounds.
 
virtual void setIntegratorReset (bool iresetOnZero)
 Set whether the integrator should be reset when error is 0 or changes sign.
 
virtual void setGains (const Gains &igains)
 Set controller gains.
 
Gains getGains () const
 Gets the current gains.
 
- Public Member Functions inherited from okapi::IterativeController< Input, Output >
virtual Output step (Input ireading)=0
 Do one iteration of the controller.
 
virtual void setOutputLimits (Output imax, Output imin)=0
 Set controller output bounds.
 
virtual void setControllerSetTargetLimits (Output itargetMax, Output itargetMin)=0
 Sets the (soft) limits for the target range that controllerSet() scales into.
 
- Public Member Functions inherited from okapi::ClosedLoopController< Input, Output >
virtual ~ClosedLoopController ()=default
 
virtual void setTarget (Input itarget)=0
 Sets the target for the controller.
 
- Public Member Functions inherited from okapi::ControllerOutput< Input >
virtual void controllerSet (Input ivalue)=0
 Writes the value of the controller output.
 

Protected Attributes

std::shared_ptr< Loggerlogger
 
double kP
 
double kI
 
double kD
 
double kBias
 
QTime sampleTime {10_ms}
 
double target {0}
 
double lastReading {0}
 
double error {0}
 
double lastError {0}
 
std::unique_ptr< FilterderivativeFilter
 
double integral {0}
 
double integralMax {1}
 
double integralMin {-1}
 
double errorSumMin {0}
 
double errorSumMax {std::numeric_limits<double>::max()}
 
double derivative {0}
 
double output {0}
 
double outputMax {1}
 
double outputMin {-1}
 
double controllerSetTargetMax {1}
 
double controllerSetTargetMin {-1}
 
bool shouldResetOnCross {true}
 
bool controllerIsDisabled {false}
 
std::unique_ptr< AbstractTimerloopDtTimer
 
std::unique_ptr< SettledUtilsettledUtil
 

Detailed Description

Definition at line 20 of file iterativePosPidController.hpp.

Constructor & Destructor Documentation

◆ IterativePosPIDController() [1/2]

okapi::IterativePosPIDController::IterativePosPIDController ( double  ikP,
double  ikI,
double  ikD,
double  ikBias,
const TimeUtil itimeUtil,
std::unique_ptr< Filter iderivativeFilter = std::make_unique< PassthroughFilter >(),
std::shared_ptr< Logger ilogger = Logger::getDefaultLogger() 
)

Position PID controller.

Parameters
ikPthe proportional gain
ikIthe integration gain
ikDthe derivative gain
ikBiasthe controller bias
itimeUtilsee TimeUtil docs
iderivativeFiltera filter for filtering the derivative term
iloggerThe logger this instance will log to.

◆ IterativePosPIDController() [2/2]

okapi::IterativePosPIDController::IterativePosPIDController ( const Gains igains,
const TimeUtil itimeUtil,
std::unique_ptr< Filter iderivativeFilter = std::make_unique< PassthroughFilter >(),
std::shared_ptr< Logger ilogger = Logger::getDefaultLogger() 
)

Position PID controller.

Parameters
igainsthe controller gains
itimeUtilsee TimeUtil docs
iderivativeFiltera filter for filtering the derivative term

Member Function Documentation

◆ controllerSet()

void okapi::IterativePosPIDController::controllerSet ( double  ivalue)
override

Writes the value of the controller output.

This method might be automatically called in another thread by the controller. The range of input values is expected to be [-1, 1].

Parameters
ivaluethe controller's output in the range [-1, 1]

◆ flipDisable() [1/2]

void okapi::IterativePosPIDController::flipDisable ( )
overridevirtual

Changes whether the controller is off or on.

Turning the controller on after it was off will cause the controller to move to its last set target, unless it was reset in that time.

Implements okapi::ClosedLoopController< Input, Output >.

◆ flipDisable() [2/2]

void okapi::IterativePosPIDController::flipDisable ( bool  iisDisabled)
overridevirtual

Sets whether the controller is off or on.

Turning the controller on after it was off will cause the controller to move to its last set target, unless it was reset in that time.

Parameters
iisDisabledwhether the controller is disabled

Implements okapi::ClosedLoopController< Input, Output >.

◆ getError()

double okapi::IterativePosPIDController::getError ( ) const
overridevirtual

Returns the last error of the controller.

Does not update when disabled.

Implements okapi::ClosedLoopController< Input, Output >.

◆ getGains()

Gains okapi::IterativePosPIDController::getGains ( ) const

Gets the current gains.

Returns
The current gains.

◆ getMaxOutput()

double okapi::IterativePosPIDController::getMaxOutput ( )
overridevirtual

Get the upper output bound.

Returns
the upper output bound

Implements okapi::IterativeController< Input, Output >.

◆ getMinOutput()

double okapi::IterativePosPIDController::getMinOutput ( )
overridevirtual

Get the lower output bound.

Returns
the lower output bound

Implements okapi::IterativeController< Input, Output >.

◆ getOutput()

double okapi::IterativePosPIDController::getOutput ( ) const
overridevirtual

Returns the last calculated output of the controller.

Output is in the range [-1, 1] unless the bounds have been changed with setOutputLimits().

Implements okapi::IterativeController< Input, Output >.

◆ getProcessValue()

double okapi::IterativePosPIDController::getProcessValue ( ) const
overridevirtual
Returns
The most recent value of the process variable.

Implements okapi::ClosedLoopController< Input, Output >.

◆ getSampleTime()

QTime okapi::IterativePosPIDController::getSampleTime ( ) const
overridevirtual

Get the last set sample time.

Returns
sample time

Implements okapi::IterativeController< Input, Output >.

◆ getTarget() [1/2]

double okapi::IterativePosPIDController::getTarget ( ) const

Gets the last set target, or the default target if none was set.

Returns
the last target

◆ getTarget() [2/2]

double okapi::IterativePosPIDController::getTarget ( )
overridevirtual

Gets the last set target, or the default target if none was set.

Returns
the last target

Implements okapi::ClosedLoopController< Input, Output >.

◆ isDisabled()

bool okapi::IterativePosPIDController::isDisabled ( ) const
overridevirtual

Returns whether the controller is currently disabled.

Returns
whether the controller is currently disabled

Implements okapi::ClosedLoopController< Input, Output >.

◆ isSettled()

bool okapi::IterativePosPIDController::isSettled ( )
overridevirtual

Returns whether the controller has settled at the target.

Determining what settling means is implementation-dependent.

If the controller is disabled, this method must return true.

Returns
whether the controller is settled

Implements okapi::ClosedLoopController< Input, Output >.

◆ reset()

void okapi::IterativePosPIDController::reset ( )
overridevirtual

Resets the controller's internal state so it is similar to when it was first initialized, while keeping any user-configured information.

Implements okapi::ClosedLoopController< Input, Output >.

◆ setControllerSetTargetLimits()

void okapi::IterativePosPIDController::setControllerSetTargetLimits ( double  itargetMax,
double  itargetMin 
)
override

Sets the (soft) limits for the target range that controllerSet() scales into.

The target computed by controllerSet() is scaled into the range [-itargetMin, itargetMax].

Parameters
itargetMaxThe new max target for controllerSet().
itargetMinThe new min target for controllerSet().

◆ setErrorSumLimits()

virtual void okapi::IterativePosPIDController::setErrorSumLimits ( double  imax,
double  imin 
)
virtual

Set the error sum bounds.

Default bounds are [0, std::numeric_limits<double>::max()]. Error will only be added to the integral term when its absolute value is between these bounds of either side of the target.

Parameters
imaxmax error value that will be summed
iminmin error value that will be summed

◆ setGains()

virtual void okapi::IterativePosPIDController::setGains ( const Gains igains)
virtual

Set controller gains.

Parameters
igainsThe new gains.

◆ setIntegralLimits()

virtual void okapi::IterativePosPIDController::setIntegralLimits ( double  imax,
double  imin 
)
virtual

Set integrator bounds.

Default bounds are [-1, 1].

Parameters
imaxmax integrator value
iminmin integrator value

◆ setIntegratorReset()

virtual void okapi::IterativePosPIDController::setIntegratorReset ( bool  iresetOnZero)
virtual

Set whether the integrator should be reset when error is 0 or changes sign.

Parameters
iresetOnZerotrue to reset

◆ setOutputLimits()

void okapi::IterativePosPIDController::setOutputLimits ( double  imax,
double  imin 
)
override

Set controller output bounds.

Default bounds are [-1, 1].

Parameters
imaxmax output
iminmin output

◆ setSampleTime()

void okapi::IterativePosPIDController::setSampleTime ( QTime  isampleTime)
overridevirtual

Set time between loops in ms.

Parameters
isampleTimetime between loops

Implements okapi::IterativeController< Input, Output >.

◆ setTarget()

void okapi::IterativePosPIDController::setTarget ( double  itarget)
override

Sets the target for the controller.

Parameters
itargetnew target position

◆ step()

double okapi::IterativePosPIDController::step ( double  inewReading)
override

Do one iteration of the controller.

Returns the reading in the range [-1, 1] unless the bounds have been changed with setOutputLimits().

Parameters
inewReadingnew measurement
Returns
controller output

Member Data Documentation

◆ controllerIsDisabled

bool okapi::IterativePosPIDController::controllerIsDisabled {false}
protected

Definition at line 271 of file iterativePosPidController.hpp.

◆ controllerSetTargetMax

double okapi::IterativePosPIDController::controllerSetTargetMax {1}
protected

Definition at line 265 of file iterativePosPidController.hpp.

◆ controllerSetTargetMin

double okapi::IterativePosPIDController::controllerSetTargetMin {-1}
protected

Definition at line 266 of file iterativePosPidController.hpp.

◆ derivative

double okapi::IterativePosPIDController::derivative {0}
protected

Definition at line 259 of file iterativePosPidController.hpp.

◆ derivativeFilter

std::unique_ptr<Filter> okapi::IterativePosPIDController::derivativeFilter
protected

Definition at line 248 of file iterativePosPidController.hpp.

◆ error

double okapi::IterativePosPIDController::error {0}
protected

Definition at line 246 of file iterativePosPidController.hpp.

◆ errorSumMax

double okapi::IterativePosPIDController::errorSumMax {std::numeric_limits<double>::max()}
protected

Definition at line 257 of file iterativePosPidController.hpp.

◆ errorSumMin

double okapi::IterativePosPIDController::errorSumMin {0}
protected

Definition at line 256 of file iterativePosPidController.hpp.

◆ integral

double okapi::IterativePosPIDController::integral {0}
protected

Definition at line 251 of file iterativePosPidController.hpp.

◆ integralMax

double okapi::IterativePosPIDController::integralMax {1}
protected

Definition at line 252 of file iterativePosPidController.hpp.

◆ integralMin

double okapi::IterativePosPIDController::integralMin {-1}
protected

Definition at line 253 of file iterativePosPidController.hpp.

◆ kBias

double okapi::IterativePosPIDController::kBias
protected

Definition at line 242 of file iterativePosPidController.hpp.

◆ kD

double okapi::IterativePosPIDController::kD
protected

Definition at line 242 of file iterativePosPidController.hpp.

◆ kI

double okapi::IterativePosPIDController::kI
protected

Definition at line 242 of file iterativePosPidController.hpp.

◆ kP

double okapi::IterativePosPIDController::kP
protected

Definition at line 242 of file iterativePosPidController.hpp.

◆ lastError

double okapi::IterativePosPIDController::lastError {0}
protected

Definition at line 247 of file iterativePosPidController.hpp.

◆ lastReading

double okapi::IterativePosPIDController::lastReading {0}
protected

Definition at line 245 of file iterativePosPidController.hpp.

◆ logger

std::shared_ptr<Logger> okapi::IterativePosPIDController::logger
protected

Definition at line 241 of file iterativePosPidController.hpp.

◆ loopDtTimer

std::unique_ptr<AbstractTimer> okapi::IterativePosPIDController::loopDtTimer
protected

Definition at line 273 of file iterativePosPidController.hpp.

◆ output

double okapi::IterativePosPIDController::output {0}
protected

Definition at line 262 of file iterativePosPidController.hpp.

◆ outputMax

double okapi::IterativePosPIDController::outputMax {1}
protected

Definition at line 263 of file iterativePosPidController.hpp.

◆ outputMin

double okapi::IterativePosPIDController::outputMin {-1}
protected

Definition at line 264 of file iterativePosPidController.hpp.

◆ sampleTime

QTime okapi::IterativePosPIDController::sampleTime {10_ms}
protected

Definition at line 243 of file iterativePosPidController.hpp.

◆ settledUtil

std::unique_ptr<SettledUtil> okapi::IterativePosPIDController::settledUtil
protected

Definition at line 274 of file iterativePosPidController.hpp.

◆ shouldResetOnCross

bool okapi::IterativePosPIDController::shouldResetOnCross {true}
protected

Definition at line 269 of file iterativePosPidController.hpp.

◆ target

double okapi::IterativePosPIDController::target {0}
protected

Definition at line 244 of file iterativePosPidController.hpp.


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