Go to the documentation of this file.00001
00002
00005
00006 #ifndef PID_h
00007 #define PID_h
00008
00009 #include <stdint.h>
00010
00013 class PID {
00014 public:
00016
00017 enum storage_t
00018 {
00019 STORE_OFF,
00020 STORE_EEPROM_FLOAT,
00021 STORE_EEPROM_UINT16
00022 } _storage;
00023
00030 PID() :
00031 _storage(STORE_OFF),
00032 _address(0),
00033 _gain_array(&_local_gains[0])
00034 {}
00035
00044 PID(uint16_t address, storage_t storage = STORE_EEPROM_UINT16) :
00045 _storage(storage),
00046 _address(address),
00047 _gain_array(&_local_gains[0])
00048 {
00049 load_gains();
00050 }
00051
00060
00061 PID(float *gain_array) :
00062 _storage(STORE_OFF),
00063 _gain_array(gain_array)
00064 {
00065 }
00066
00080 long get_pid(int32_t error, uint16_t dt, float scaler = 1.0);
00081
00084 void reset_I() {
00085 _integrator = 0;
00086 _last_error = 0;
00087 _last_derivative = 0;
00088 }
00089
00092 void load_gains();
00093
00096 void save_gains();
00097
00099
00100 float kP() { return _gain_array[0]; }
00101 float kI() { return _gain_array[1]; }
00102 float kD() { return _gain_array[2]; }
00103 float imax() { return _gain_array[3]; }
00104
00105 void kP(const float v) { _gain_array[0] = v; }
00106 void kI(const float v) { _gain_array[1] = v; }
00107 void kD(const float v) { _gain_array[2] = v; }
00108 void imax(const float v);
00109
00110 void address(const uint16_t v) { _address = v; }
00111
00112
00113
00114
00116
00117 float get_integrator() { return _integrator; }
00118
00119 private:
00120 uint16_t _address;
00121 float *_gain_array;
00122
00123 float _local_gains[4];
00124
00125 float _integrator;
00126 int32_t _last_error;
00127 float _last_derivative;
00128
00134 static const uint8_t _fCut = 20;
00135 };
00136
00137 #endif