forked from br3ttb/Arduino-PID-Library
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBasicPIDLibraryClass.h
More file actions
65 lines (46 loc) · 2.5 KB
/
BasicPIDLibraryClass.h
File metadata and controls
65 lines (46 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef BASICPIDLIBRARY_h
#define BASICPIDLIBRARY_h
#define DECIMAL double
//#define DECIMAL float
class BasicPIDLibrary
{
public:
//commonly used functions **************************************************************************
BasicPIDLibrary(DECIMAL Kp, DECIMAL Ki, DECIMAL Kd);
bool Compute(DECIMAL, DECIMAL,DECIMAL&); // * performs the PID calculation. it should be
// called every time loop() cycles.
void SetOutputLimits(DECIMAL, DECIMAL); // * clamps the output to a specific range. 0-255 by default, but
// it's likely the user will want to change this depending on
// the application
//available but not commonly used functions ********************************************************
void SetTunings(DECIMAL, DECIMAL, // * While most users will set the tunings once in the
DECIMAL); // constructor, this function gives the user the option
void SetControllerDirection(int); // * Sets the Direction, or "Action" of the controller. DIRECT
// means the output will increase when error is positive. REVERSE
// means the opposite. it's very unlikely that this will be needed
// once it is set in the constructor.
void SetSampleTimeMilliseconds(int); // * sets the frequency, in Milliseconds, with which
// the PID calculation is performed. default is 100
//Display functions ****************************************************************
DECIMAL GetKp(){return kp;}; // These functions query the pid for interal values.
DECIMAL GetKi(){return ki;}; // they were created mainly for the pid front-end,
DECIMAL GetKd(){return kd;}; // where it's important to know what is actually
void DisableController(void);
void EnableController(void);
DECIMAL GetIValue() { return mOutputSum; };
DECIMAL GetDValue() { return mLastChange; };
private:
void Initialize();
bool mEnabled;
DECIMAL kp; // * (P)roportional Tuning Parameter
DECIMAL ki; // * (I)ntegral Tuning Parameter
DECIMAL kd; // * (D)erivative Tuning Parameter
unsigned long mLastTime;
DECIMAL mOutputSum;
DECIMAL mLastInput;
DECIMAL mLastChange=0.0;
unsigned long mSampleTime;
DECIMAL mOutMax;
DECIMAL mOutMin;
};
#endif