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