Skip to content
Lukáš Dršman edited this page May 10, 2022 · 2 revisions

Contains the structure, necessary for storage of PID coefficients and for transfer of PID-related values. pid.h does not provide a function for calculating PID output, doing so is left up to the user in a hope for more efficient integration in the functions requiring it.

pid type

The struct type for PID is defined as

typedef struct PID
{
    // constant block
    double SP, KP, KI, KD;
    // variable block
    double integral, perror, ptime, stime;
}
pid;

and is divided into constant and variable block.

Constant block

Consists of

  • SP - PID setpoint, the value that the given PID controlled process should achieve/preserve
  • KP - proportional error coefficient, defines how the given process should react to proportional error
  • KI - integral error coefficient, defines how the given process should react to the accumulated error
  • KD - differential error coefficient, defines how the given process should react to the change of error with respect to time

Variable block

This block exists mainly due to non-stop functions, defined in move.h, which must transfer variable PID values from function to function. It consists of

  • integral - value of error integral from the previous call
  • perror - last error value from the previous call
  • ptime - last time value from the previous call
  • stime - epoch time (in seconds) of the initial call

Constructor

The constructor for pid is defined as

pid pidNew(double SP, double KP, double KI, double KD);

taking only constant block parameters.

In run code, pid can be, for example, defined as

pid foo;
foo = pidNew(0.0, 34.0, 1.4, 0.99);
Clone this wiki locally