okapi::IterativePosPIDController class

Base classes

template<typename Input, typename Output>
class IterativePositionController

Public types

struct Gains

Constructors, destructors, conversion operators

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.

Public functions

auto step(double inewReading) -> double 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.
auto getTarget() -> double override
Gets the last set target, or the default target if none was set.
auto getTarget() const -> double
Gets the last set target, or the default target if none was set.
auto getProcessValue() const -> double override
auto getOutput() const -> double override
Returns the last calculated output of the controller.
auto getMaxOutput() -> double override
Get the upper output bound.
auto getMinOutput() -> double override
Get the lower output bound.
auto getError() const -> double override
Returns the last error of the controller.
auto isSettled() -> bool 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.
auto isDisabled() const -> bool override
Returns whether the controller is currently disabled.
auto getSampleTime() const -> QTime override
Get the last set sample time.
void setIntegralLimits(double imax, double imin) virtual
Set integrator bounds.
void setErrorSumLimits(double imax, double imin) virtual
Set the error sum bounds.
void setIntegratorReset(bool iresetOnZero) virtual
Set whether the integrator should be reset when error is 0 or changes sign.
void setGains(const Gains& igains) virtual
Set controller gains.
auto getGains() const -> Gains
Gets the current gains.

Protected variables

std::shared_ptr<Logger> logger
double kP
double kI
double kD
double kBias
QTime sampleTime
double target
double lastReading
double error
double lastError
std::unique_ptr<Filter> derivativeFilter
double integral
double integralMax
double integralMin
double errorSumMin
double errorSumMax
double derivative
double output
double outputMax
double outputMin
double controllerSetTargetMax
double controllerSetTargetMin
bool shouldResetOnCross
bool controllerIsDisabled
std::unique_ptr<AbstractTimer> loopDtTimer
std::unique_ptr<SettledUtil> settledUtil

Function documentation

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
ikP the proportional gain
ikI the integration gain
ikD the derivative gain
ikBias the controller bias
itimeUtil see TimeUtil docs
iderivativeFilter a filter for filtering the derivative term
ilogger The logger this instance will log to.

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
igains the controller gains
itimeUtil see TimeUtil docs
iderivativeFilter a filter for filtering the derivative term
ilogger

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

Do one iteration of the controller.

Parameters
inewReading new measurement
Returns controller output

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

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

Sets the target for the controller.

Parameters
itarget new target position

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

Writes the value of the controller output.

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

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

double okapi::IterativePosPIDController::getTarget() override

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

Returns the last target

double okapi::IterativePosPIDController::getTarget() const

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

Returns the last target

double okapi::IterativePosPIDController::getProcessValue() const override

Returns The most recent value of the process variable.

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

Returns the last calculated output of the controller.

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

double okapi::IterativePosPIDController::getMaxOutput() override

Get the upper output bound.

Returns the upper output bound

double okapi::IterativePosPIDController::getMinOutput() override

Get the lower output bound.

Returns the lower output bound

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

Returns the last error of the controller.

Does not update when disabled.

bool okapi::IterativePosPIDController::isSettled() override

Returns whether the controller has settled at the target.

Returns whether the controller is settled

Determining what settling means is implementation-dependent.

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

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

Set time between loops in ms.

Parameters
isampleTime time between loops

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

Set controller output bounds.

Parameters
imax max output
imin min output

Default bounds are [-1, 1].

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

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

Parameters
itargetMax The new max target for controllerSet().
itargetMin The new min target for controllerSet().

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

void okapi::IterativePosPIDController::flipDisable() override

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.

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

Sets whether the controller is off or on.

Parameters
iisDisabled whether the controller is disabled

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.

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

Returns whether the controller is currently disabled.

Returns whether the controller is currently disabled

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

Get the last set sample time.

Returns sample time

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

Set integrator bounds.

Parameters
imax max integrator value
imin min integrator value

Default bounds are [-1, 1].

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

Set the error sum bounds.

Parameters
imax max error value that will be summed
imin min error value that will be summed

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.

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

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

Parameters
iresetOnZero true to reset

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

Set controller gains.

Parameters
igains The new gains.

Gains okapi::IterativePosPIDController::getGains() const

Gets the current gains.

Returns The current gains.