3
#define LIBRARY_VERSION 1.2.1
11
//Constants used in some of the functions below
19
//commonly used functions **************************************************************************
20
PID(double*, double*, double*, // * constructor. links the PID to the Input, Output, and
21
double, double, double, int, int);// Setpoint. Initial tuning parameters are also set here.
22
// (overload for specifying proportional mode)
24
PID(double*, double*, double*, // * constructor. links the PID to the Input, Output, and
25
double, double, double, int); // Setpoint. Initial tuning parameters are also set here
27
void SetMode(uint8_t Mode); // * sets PID to either Manual (0) or Auto (non-0)
29
bool Compute(); // * performs the PID calculation. it should be
30
// called every time loop() cycles. ON/OFF and
31
// calculation frequency can be set using SetMode
32
// SetSampleTime respectively
34
void SetOutputLimits(double, double); // * clamps the output to a specific range. 0-255 by default, but
35
// it's likely the user will want to change this depending on
40
//available but not commonly used functions ********************************************************
41
void SetTunings(double, double, // * While most users will set the tunings once in the
42
double); // constructor, this function gives the user the option
43
// of changing tunings during runtime for Adaptive control
44
void SetTunings(double, double, // * overload for specifying proportional mode
47
void SetControllerDirection(int); // * Sets the Direction, or "Action" of the controller. DIRECT
48
// means the output will increase when error is positive. REVERSE
49
// means the opposite. it's very unlikely that this will be needed
50
// once it is set in the constructor.
51
void SetSampleTime(int); // * sets the frequency, in Milliseconds, with which
52
// the PID calculation is performed. default is 100
56
//Display functions ****************************************************************
57
double GetKp(); // These functions query the pid for interal values.
58
double GetKi(); // they were created mainly for the pid front-end,
59
double GetKd(); // where it's important to know what is actually
60
int GetMode(); // inside the PID.
61
int GetDirection(); //
66
double dispKp; // * we'll hold on to the tuning parameters in user-entered
67
double dispKi; // format for display purposes
70
double kp; // * (P)roportional Tuning Parameter
71
double ki; // * (I)ntegral Tuning Parameter
72
double kd; // * (D)erivative Tuning Parameter
74
int controllerDirection;
77
double *myInput; // * Pointers to the Input, Output, and Setpoint variables
78
double *myOutput; // This creates a hard link between the variables and the
79
double *mySetpoint; // PID, freeing the user from having to constantly tell us
80
// what these values are. with pointers we'll just know.
82
unsigned long lastTime;
83
double outputSum, lastInput;
85
unsigned long SampleTime;
86
double outMin, outMax;