okapi::IterativeVelPIDController class

Base classes

template<typename Input, typename Output>
class IterativeVelocityController

Public types

struct Gains

Constructors, destructors, conversion operators

IterativeVelPIDController(double ikP, double ikD, double ikF, double ikSF, std::unique_ptr<VelMath> ivelMath, const TimeUtil& itimeUtil, std::unique_ptr<Filter> iderivativeFilter = std::make_unique<PassthroughFilter>(), std::shared_ptr<Logger> ilogger = Logger::getDefaultLogger())
Velocity PD controller.
IterativeVelPIDController(const Gains& igains, std::unique_ptr<VelMath> ivelMath, const TimeUtil& itimeUtil, std::unique_ptr<Filter> iderivativeFilter = std::make_unique<PassthroughFilter>(), std::shared_ptr<Logger> ilogger = Logger::getDefaultLogger())
Velocity PD 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.
auto stepVel(double inewReading) -> QAngularSpeed virtual
Do one iteration of velocity calculation.
void setGains(const Gains& igains) virtual
Set controller gains.
auto getGains() const -> Gains
Gets the current gains.
void setTicksPerRev(double tpr) virtual
Sets the number of encoder ticks per revolution.
auto getVel() const -> QAngularSpeed virtual
Returns the current velocity.

Protected variables

std::shared_ptr<Logger> logger
double kP
double kD
double kF
double kSF
QTime sampleTime
double error
double derivative
double target
double outputSum
double output
double outputMax
double outputMin
double controllerSetTargetMax
double controllerSetTargetMin
bool controllerIsDisabled
std::unique_ptr<VelMath> velMath
std::unique_ptr<Filter> derivativeFilter
std::unique_ptr<AbstractTimer> loopDtTimer
std::unique_ptr<SettledUtil> settledUtil

Function documentation

okapi::IterativeVelPIDController::IterativeVelPIDController(double ikP, double ikD, double ikF, double ikSF, std::unique_ptr<VelMath> ivelMath, const TimeUtil& itimeUtil, std::unique_ptr<Filter> iderivativeFilter = std::make_unique<PassthroughFilter>(), std::shared_ptr<Logger> ilogger = Logger::getDefaultLogger())

Velocity PD controller.

Parameters
ikP the proportional gain
ikD the derivative gain
ikF the feed-forward gain
ikSF a feed-forward gain to counteract static friction
ivelMath The VelMath used for calculating velocity.
itimeUtil see TimeUtil docs
iderivativeFilter a filter for filtering the derivative term
ilogger The logger this instance will log to.

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

Velocity PD controller.

Parameters
igains The controller gains.
ivelMath The VelMath used for calculating velocity.
itimeUtil see TimeUtil docs
iderivativeFilter a filter for filtering the derivative term
ilogger The logger this instance will log to.

double okapi::IterativeVelPIDController::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::IterativeVelPIDController::setTarget(double itarget) override

Sets the target for the controller.

Parameters
itarget new target velocity

void okapi::IterativeVelPIDController::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::IterativeVelPIDController::getTarget() override

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

Returns the last target

double okapi::IterativeVelPIDController::getTarget() const

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

Returns the last target

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

Returns The most recent value of the process variable.

double okapi::IterativeVelPIDController::getMaxOutput() override

Get the upper output bound.

Returns the upper output bound

double okapi::IterativeVelPIDController::getMinOutput() override

Get the lower output bound.

Returns the lower output bound

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

Returns the last error of the controller.

Does not update when disabled.

bool okapi::IterativeVelPIDController::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::IterativeVelPIDController::setSampleTime(QTime isampleTime) override

Set time between loops in ms.

Parameters
isampleTime time between loops

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

Set controller output bounds.

Parameters
imax max output
imin min output

Default bounds are [-1, 1].

void okapi::IterativeVelPIDController::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::IterativeVelPIDController::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::IterativeVelPIDController::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::IterativeVelPIDController::isDisabled() const override

Returns whether the controller is currently disabled.

Returns whether the controller is currently disabled

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

Get the last set sample time.

Returns sample time

QAngularSpeed okapi::IterativeVelPIDController::stepVel(double inewReading) virtual

Do one iteration of velocity calculation.

Parameters
inewReading new measurement
Returns filtered velocity

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

Set controller gains.

Parameters
igains The new gains.

Gains okapi::IterativeVelPIDController::getGains() const

Gets the current gains.

Returns The current gains.

void okapi::IterativeVelPIDController::setTicksPerRev(double tpr) virtual

Sets the number of encoder ticks per revolution.

Parameters
tpr number of measured units per revolution

Default is 1800.