wu

Dependencies:   mbed-rtos mbed

Fork of Bov3 by kao yi

Committer:
backman
Date:
Thu Jun 26 09:15:35 2014 +0000
Revision:
10:03d5aa2511c4
Parent:
9:33b99cb45e99
without os

Who changed what in which revision?

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