Samgd14 / miniPID

Simple and light library to calculate a PID

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

miniPID

Simple and light library to calculate a PID! I'm currently working on this version, so use the previous release if you use it in projects. This new version will break compatibility on the value limiter and introduce new rate and acceleration limiters. The new version of the value limiter and the rate limiter are now implemented.

Constructors

miniPID(double kp, double ki, double kd)

Creates an object using the specified PID parameters and with the limited output set to the default values (-1 to 1).


miniPID(double kp, double ki, double kd, double maxValue, double minValue)

Creates an object using the specified PID parameters and with the value limiter enabled on the output.


miniPID(double kp, double ki, double kd, double maxValue, double minValue, double maxRate, double minRate)

Creates an object using the specified PID parameters and with the value limiter enabled on the output.

Functions

void setKs(double kp, double ki, double kd)

Sets the ki, kp, and kd values after initialization.


void setKp(double kp)
void setKi(double ki)
void setKd(double kd)

Individually sets the PID constants for the controller.


bool getVLimitState()

Get the current state of the value limiter.


bool enableVLimit(bool vLimiter)

Enables/disables the value limiter and returns it's state.


void setVLimit(double maxValue, double minValue)

Changes the values to which the output is clamped to.


bool getRLimitState()

Get the current state of the rate limiter.


bool enableRLimit(bool rLimiter)

Enables/disables the rate limiter and returns it's state.


void setRLimit(double maxRate, double minRate)

Sets the rates of change to which the output is clamped to.


bool update(double input, double target, double delay)

Updates the PID controller's calculation. input is the input value for the controller, and target is the target the PID is trying to achieve. Both of these values are used to calculate the error that is used for computing the output, which is clamped by the value/rate limiters, if they are enabled. delay is the time in ms between each update and can be used to compensate for irregular timing in the controller. Still, the update function should be updated as regularly as possible.


double getOutput()

Returns the output last computed by the update function.


double getRawOutput()

Returns the output last computed by the update function without the value/rate limiters.


bool isDone()
bool isDone(double range)

Returns true if the last calculated error is equal to zero. If a range is specified, it will return true if the last calculated error is in that range.


double getError()

Returns the last calculated error.


void reset()

Resets every accumulated/output value to 0.

About

Simple and light library to calculate a PID


Languages

Language:C++ 100.0%