00001 /** 00002 * @file PIDsmoothedValue.h 00003 * Contains class PIDsmoothedValue 00004 * that calculates the PIDvalue for a given value 00005 * 00006 * @author <a href="mailto:goehring@informatik.hu-berlin.de">Daniel Goehring</a> 00007 */ 00008 00009 00010 #ifndef __PIDsmoothedValue_h__ 00011 #define __PIDsmoothedValue_h__ 00012 00013 00014 /**@class PIDsmoothedValue 00015 * Calculation of the PID-value for a given target value, 00016 * with or without boundary checks 00017 */ 00018 00019 class PIDsmoothedValue 00020 { 00021 00022 double lastDifference; //previous difference between object and its target 00023 double lastTargetVal; //previous target position 00024 double value; //value contains the so called PIDvalue to be returned 00025 double lastValue; //the previously returned value 00026 bool started; //is set true after the first difference is set 00027 00028 double oldTargetVal; //last value of target position 00029 double integralError; //last integralsumme 00030 double lastTime; //last timespot the PID-value was calculated 00031 00032 double p; //p-Koeffizient 00033 double i; //i-Koeffizient 00034 double d; //d-Koeffizient 00035 double min; //obere Bereichsgrenze 00036 double max; //untere Bereichsgrenze 00037 double maxaction; //maximale Wertaenderung 00038 00039 00040 public: 00041 00042 00043 /** 00044 * Default constructor contains default vaules and weights. 00045 * Value types are: First result value = 0; P-weight,I-weight,D-weight, 00046 * Min PID - Value, Max PID - Value, Max PID - value change since recent PID - value. 00047 * 00048 */ 00049 PIDsmoothedValue(); 00050 00051 00052 /** 00053 * Constructor for user chosen weights and value 00054 * types as above in the default constructor. 00055 */ 00056 PIDsmoothedValue(double value, double p, double i, double d, double min = -100, double max = 100.0, double maxaction = 100.0); 00057 00058 /** 00059 * Set the min value 00060 */ 00061 void setMin(double m); 00062 00063 /** 00064 * Set the max value 00065 */ 00066 void setMax(double m); 00067 00068 /** set the P-weight */ 00069 void setWeightP(double p); 00070 /** set the P-weight */ 00071 void setWeightI(double i); 00072 /** set the P-weight */ 00073 void setWeightD(double d); 00074 00075 /** 00076 * Calculation of the PID-value to return 00077 * thereby it will not just calculate the PID-sum but also ensure that it lies 00078 * within the given boundaries 00079 */ 00080 double approximateVal(double newTargetVal); 00081 00082 /* 00083 * 2do: do these work properly? 00084 */ 00085 double addOffset(double offset); 00086 double setTo(double val); 00087 00088 00089 00090 /** Discreet and iterative value calculation 00091 */ 00092 double apprDiscrVal(double targetVal, double time, double maxIteration); 00093 00094 00095 00096 /** return the - if necessary modified - PID-value */ 00097 double getVal(); 00098 00099 00100 /** 00101 * Calculation of the PID-value to return, just an alternative approach 00102 * without any boundary checks and the D-value is not just calculated by 00103 * the change of the target to object difference but by the object position change. 00104 * During first tests the upper algorithm "approximateValue" showed a better 00105 * convergence behavior that this one and is considered as the original algorithm 00106 */ 00107 double approximateValNew(double newTargetVal); 00108 00109 00110 00111 /** Calculate the PID value as a continuous function*/ 00112 double apprContVal(double targetVal, double time); 00113 00114 00115 /** get the P-weight */ 00116 double getWeightP(); 00117 /** get the I-weight */ 00118 double getWeightI(); 00119 /** get the D-weight */ 00120 double getWeightD(); 00121 00122 /** get the Min-border */ 00123 double getMin(); 00124 /** get the Max-border */ 00125 double getMax(); 00126 00127 00128 /** 00129 * reset all values and the sums necessary for its calculation 00130 */ 00131 void reset(void ); 00132 00133 /** 00134 * reset all values and the sums necessary for its calculation 00135 * and set the value to val 00136 */ 00137 void resetTo(double val); 00138 }; 00139 00140 #endif // __PIDsmoothedValue_h__ 00141