123

Dependencies:   mbed

Fork of Boboobooo by Clark Lin

Committer:
even
Date:
Thu Jul 10 10:22:14 2014 +0000
Revision:
12:a3cee7619b77
Parent:
7:f04bde0ca846
lots of weird things

Who changed what in which revision?

UserRevisionLine numberNew contents of line
even 7:f04bde0ca846 1 #include "mbed.h"
even 7:f04bde0ca846 2
even 7:f04bde0ca846 3
even 7:f04bde0ca846 4
even 7:f04bde0ca846 5 class PID
even 7:f04bde0ca846 6 {
even 7:f04bde0ca846 7 public:
even 7:f04bde0ca846 8
even 7:f04bde0ca846 9
even 7:f04bde0ca846 10 float de_kp;
even 7:f04bde0ca846 11 float de_ip;
even 7:f04bde0ca846 12 float de_dp;
even 7:f04bde0ca846 13
even 7:f04bde0ca846 14
even 7:f04bde0ca846 15
even 7:f04bde0ca846 16 float de_output;
even 7:f04bde0ca846 17
even 7:f04bde0ca846 18
even 7:f04bde0ca846 19 /*
even 7:f04bde0ca846 20 * Constructeur
even 7:f04bde0ca846 21 * Sets default limits, calculates tuning parameters, and sets manual mode with no bias.
even 7:f04bde0ca846 22 * @param Kc - Tuning parameter
even 7:f04bde0ca846 23 * @param tauI - Tuning parameter
even 7:f04bde0ca846 24 * @param tauD - Tuning parameter
even 7:f04bde0ca846 25 * @param interval PID calculation performed every interval seconds.
even 7:f04bde0ca846 26 */
even 7:f04bde0ca846 27 PID(float in_min,float in_max,float out_min,float out_max,float Kc, float tauI, float tauD, float interval);
even 7:f04bde0ca846 28
even 7:f04bde0ca846 29 /*
even 7:f04bde0ca846 30 * Scale from inputs to 0-100%.
even 7:f04bde0ca846 31 * @param InMin The real world value corresponding to 0%.
even 7:f04bde0ca846 32 * @param InMax The real world value corresponding to 100%.
even 7:f04bde0ca846 33 */
even 7:f04bde0ca846 34 void setInputLimits(float inMin, float inMax);
even 7:f04bde0ca846 35
even 7:f04bde0ca846 36 /*
even 7:f04bde0ca846 37 * Scale from outputs to 0-100%.
even 7:f04bde0ca846 38 * @param outMin The real world value corresponding to 0%.
even 7:f04bde0ca846 39 * @param outMax The real world value corresponding to 100%.
even 7:f04bde0ca846 40 */
even 7:f04bde0ca846 41 void setOutputLimits(float outMin, float outMax);
even 7:f04bde0ca846 42
even 7:f04bde0ca846 43 /*
even 7:f04bde0ca846 44 * Calculate PID constants.
even 7:f04bde0ca846 45 * Allows parameters to be changed on the fly without ruining calculations.
even 7:f04bde0ca846 46 * @param Kc - Tuning parameter
even 7:f04bde0ca846 47 * @param tauI - Tuning parameter
even 7:f04bde0ca846 48 * @param tauD - Tuning parameter
even 7:f04bde0ca846 49 */
even 7:f04bde0ca846 50 void setTunings(float Kc, float tauI, float tauD);
even 7:f04bde0ca846 51
even 7:f04bde0ca846 52 /*
even 7:f04bde0ca846 53 * Reinitializes controller internals. Automatically
even 7:f04bde0ca846 54 * called on a manual to auto transition.
even 7:f04bde0ca846 55 */
even 7:f04bde0ca846 56 // void reset(void);
even 7:f04bde0ca846 57
even 7:f04bde0ca846 58 /*
even 7:f04bde0ca846 59 * Set how fast the PID loop is run.
even 7:f04bde0ca846 60 * @param interval PID calculation peformed every interval seconds.
even 7:f04bde0ca846 61 */
even 7:f04bde0ca846 62 // void setInterval(float interval);
even 7:f04bde0ca846 63
even 7:f04bde0ca846 64 /*
even 7:f04bde0ca846 65 * Set the bias.
even 7:f04bde0ca846 66 * @param bias The bias for the controller output.
even 7:f04bde0ca846 67 */
even 7:f04bde0ca846 68 // void setBias(float bias);
even 7:f04bde0ca846 69
even 7:f04bde0ca846 70 /*
even 7:f04bde0ca846 71 * PID calculation.
even 7:f04bde0ca846 72 * @return The controller output as a float between outMin and outMax.
even 7:f04bde0ca846 73 */
even 7:f04bde0ca846 74 float compute(float center, float sp);
even 7:f04bde0ca846 75
even 7:f04bde0ca846 76 //Getters.
even 7:f04bde0ca846 77 float getInMin();
even 7:f04bde0ca846 78 float getInMax();
even 7:f04bde0ca846 79 float getOutMin();
even 7:f04bde0ca846 80 float getOutMax();
even 7:f04bde0ca846 81 float getInterval();
even 7:f04bde0ca846 82 float getPParam();
even 7:f04bde0ca846 83 float getIParam();
even 7:f04bde0ca846 84 float getDParam();
even 7:f04bde0ca846 85
even 7:f04bde0ca846 86 private:
even 7:f04bde0ca846 87
even 7:f04bde0ca846 88 // bool usingFeedForward;
even 7:f04bde0ca846 89
even 7:f04bde0ca846 90 //Actual tuning parameters used in PID calculation.
even 7:f04bde0ca846 91 float Kp;
even 7:f04bde0ca846 92 float Ki;
even 7:f04bde0ca846 93 float Kd;
even 7:f04bde0ca846 94 float Kc_;
even 7:f04bde0ca846 95 float tauI_;
even 7:f04bde0ca846 96 float tauD_;
even 7:f04bde0ca846 97
even 7:f04bde0ca846 98
even 7:f04bde0ca846 99
even 7:f04bde0ca846 100 float pParam_;
even 7:f04bde0ca846 101 float iParam_;
even 7:f04bde0ca846 102 float dParam_;
even 7:f04bde0ca846 103
even 7:f04bde0ca846 104 float accError_;
even 7:f04bde0ca846 105
even 7:f04bde0ca846 106 //Raw tuning parameters.
even 7:f04bde0ca846 107
even 7:f04bde0ca846 108 //The point we want to reach.
even 7:f04bde0ca846 109 float setPoint_;
even 7:f04bde0ca846 110 //The thing we measure.
even 7:f04bde0ca846 111 float processVariable_;
even 7:f04bde0ca846 112 float prevProcessVariable_;
even 7:f04bde0ca846 113 //The output that affects the process variable.
even 7:f04bde0ca846 114 float controllerOutput_;
even 7:f04bde0ca846 115 float prevControllerOutput_;
even 7:f04bde0ca846 116
even 7:f04bde0ca846 117 //We work in % for calculations so these will scale from
even 7:f04bde0ca846 118 //real world values to 0-100% and back again.
even 7:f04bde0ca846 119 float inMin_;
even 7:f04bde0ca846 120 float inMax_;
even 7:f04bde0ca846 121 float inSpan_;
even 7:f04bde0ca846 122
even 7:f04bde0ca846 123 float outMin_;
even 7:f04bde0ca846 124 float outMid_;
even 7:f04bde0ca846 125 float outMax_;
even 7:f04bde0ca846 126 float outSpan_;
even 7:f04bde0ca846 127
even 7:f04bde0ca846 128 float ctrl_Lbound;
even 7:f04bde0ca846 129 float ctrl_Ubound;
even 7:f04bde0ca846 130
even 7:f04bde0ca846 131
even 7:f04bde0ca846 132
even 7:f04bde0ca846 133
even 7:f04bde0ca846 134 //The accumulated error, i.e. integral.
even 7:f04bde0ca846 135 //float accError_;
even 7:f04bde0ca846 136 //The controller output bias.
even 7:f04bde0ca846 137 // float bias_;
even 7:f04bde0ca846 138
even 7:f04bde0ca846 139 //The interval between samples.
even 7:f04bde0ca846 140 float tSample_;
even 7:f04bde0ca846 141
even 7:f04bde0ca846 142 //Controller output as a real world value.
even 7:f04bde0ca846 143 // volatile float realOutput_;
even 7:f04bde0ca846 144
even 7:f04bde0ca846 145 };