DCAITI Robot Hardware  1.0
PID_Beta6.h
Go to the documentation of this file.
1 #ifndef PID_Beta6_h
2 #define PID_Beta6_h
3 
4 class PID
5 {
6 
7 
8  public:
9 
10  #define AUTO 1
11  #define MANUAL 0
12  #define LIBRARY_VERSION 0.6
13 
14  //commonly used functions **************************************************************************
15  PID(int*, int*, int*, // * constructor. links the PID to the Input, Output, and
16  float, float, float); // Setpoint. Initial tuning parameters are also set here
17 
18  PID(int*, int*, int*, // * Overloaded Constructor. if the user wants to implement
19  int*, float, float, float); // feed-forward
20 
21  void SetMode(int Mode); // * sets PID to either Manual (0) or Auto (non-0)
22 
23  void Compute(); // * performs the PID calculation. it should be
24  // called every time loop() cycles. ON/OFF and
25  // calculation frequency can be set using SetMode
26  // SetSampleTime respectively
27 
28  void SetInputLimits(int, int); //Tells the PID what 0-100% are for the Input
29 
30  void SetOutputLimits(int, int); //Tells the PID what 0-100% are for the Output
31 
32 
33  //available but not commonly used functions ********************************************************
34  void SetTunings(float, float, // * While most users will set the tunings once in the
35  float); // constructor, this function gives the user the option
36  // of changing tunings during runtime for Adaptive control
37 
38  void SetSampleTime(int); // * sets the frequency, in Milliseconds, with which
39  // the PID calculation is performed. default is 1000
40 
41  void Reset(); // * reinitializes controller internals. automatically
42  // called on a manual to auto transition
43 
44  bool JustCalculated(); // * in certain situations, it helps to know when the PID has
45  // computed this bit will be true for one cycle after the
46  // pid calculation has occurred
47 
48 
49  //Status functions allow you to query current PID constants ***************************************
50  int GetMode();
51  int GetINMin();
52  int GetINMax();
53  int GetOUTMin();
54  int GetOUTMax();
55  int GetSampleTime();
56  float GetP_Param();
57  float GetI_Param();
58  float GetD_Param();
59 
60 
61  private:
62 
63  void ConstructorCommon(int*, int*, int*, // * code that is shared by the constructors
64  float, float, float);
65 
66  //scaled, tweaked parameters we'll actually be using
67  float kc; // * (P)roportional Tuning Parameter
68  float taur; // * (I)ntegral Tuning Parameter
69  float taud; // * (D)erivative Tuning Parameter
70 
71  float cof_A;
72  float cof_B;
73  float cof_C;
74 
75  //nice, pretty parameters we'll give back to the user if they ask what the tunings are
76  float P_Param;
77  float I_Param;
78  float D_Param;
79 
80 
81  int *myInput; // * Pointers to the Input, Output, and Setpoint variables
82  int *myOutput; // This creates a hard link between the variables and the
83  int *mySetpoint; // PID, freeing the user from having to constantly tell us
84  // what these values are. with pointers we'll just know.
85 
86  int *myBias; // * Pointer to the External FeedForward bias, only used
87  // if the advanced constructor is used
88  bool UsingFeedForward; // * internal flag that tells us if we're using FeedForward or not
89 
90  unsigned long nextCompTime; // * Helps us figure out when the PID Calculation needs to
91  // be performed next
92  // to determine when to compute next
93  unsigned long tSample; // * the frequency, in milliseconds, with which we want the
94  // the PID calculation to occur.
95  bool inAuto; // * Flag letting us know if we are in Automatic or not
96 
97  // the derivative required for the D term
98  //float accError; // * the (I)ntegral term is based on the sum of error over
99  // time. this variable keeps track of that
100  float bias; // * the base output from which the PID operates
101 
102  int Err;
103  int lastErr;
104  int prevErr;
105 
106  float inMin, inSpan; // * input and output limits, and spans. used convert
107  float outMin, outSpan; // real world numbers into percent span, with which
108  // the PID algorithm is more comfortable.
109 
110  bool justCalced; // * flag gets set for one cycle after the pid calculates
111 };
112 #endif
113 
Definition: PID_Beta6.h:5
void Compute()
Definition: PID_Beta6.cpp:207
bool JustCalculated()
Definition: PID_Beta6.cpp:266
int GetOUTMin()
Definition: PID_Beta6.cpp:284
float GetP_Param()
Definition: PID_Beta6.cpp:296
float GetI_Param()
Definition: PID_Beta6.cpp:300
void SetMode(int Mode)
Definition: PID_Beta6.cpp:156
PID(int *, int *, int *, float, float, float)
Definition: PID_Beta6.cpp:18
float GetD_Param()
Definition: PID_Beta6.cpp:305
void SetOutputLimits(int, int)
Definition: PID_Beta6.cpp:91
int GetINMin()
Definition: PID_Beta6.cpp:276
void Reset()
Definition: PID_Beta6.cpp:141
void SetTunings(float, float, float)
Definition: PID_Beta6.cpp:105
void SetInputLimits(int, int)
Definition: PID_Beta6.cpp:73
void SetSampleTime(int)
Definition: PID_Beta6.cpp:169
int GetINMax()
Definition: PID_Beta6.cpp:280
int GetMode()
Definition: PID_Beta6.cpp:270
int GetSampleTime()
Definition: PID_Beta6.cpp:292
int GetOUTMax()
Definition: PID_Beta6.cpp:288