From c9227dbcaf4fbdbd499968c25292b4c2d028de43 Mon Sep 17 00:00:00 2001 From: jasonshort Date: Mon, 24 Jan 2011 02:07:25 +0000 Subject: [PATCH] fixed a scaling bug in imax git-svn-id: https://arducopter.googlecode.com/svn/trunk@1553 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- libraries/PID/PID.cpp | 15 +++++---------- libraries/PID/PID.h | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/libraries/PID/PID.cpp b/libraries/PID/PID.cpp index d720ee9356..5e3f330949 100644 --- a/libraries/PID/PID.cpp +++ b/libraries/PID/PID.cpp @@ -58,11 +58,6 @@ PID::get_pid(int32_t error, uint16_t dt, float scaler) return output; } -void -PID::imax(float v) -{ - _imax = fabs(v); -} void PID::load_gains() @@ -76,7 +71,7 @@ PID::load_gains() _kp = (float)(eeprom_read_word((uint16_t *) _address)) / 1000.0; _ki = (float)(eeprom_read_word((uint16_t *) (_address + 2))) / 1000.0; _kd = (float)(eeprom_read_word((uint16_t *) (_address + 4))) / 1000.0; - _imax = eeprom_read_word((uint16_t *) (_address + 6)) * 100; + _imax = (float)(eeprom_read_word((uint16_t *) (_address + 6))); //_kp = (float)_ee.read_int(_address) / 1000.0; //_ki = (float)_ee.read_int(_address + 2) / 1000.0; @@ -103,10 +98,10 @@ PID::save_gains() // save is a NOP if the gain array is managed externally break; case STORE_EEPROM_UINT16: - eeprom_write_word((uint16_t *) _address, (int)(_kp * 1000)); - eeprom_write_word((uint16_t *) (_address + 2), (int)(_ki * 1000)); - eeprom_write_word((uint16_t *) (_address + 4), (int)(_kd * 1000)); - eeprom_write_word((uint16_t *) (_address + 6), (int)_imax/100); + eeprom_write_word((uint16_t *) _address, (int)(_kp * 1000.0)); + eeprom_write_word((uint16_t *) (_address + 2), (int)(_ki * 1000.0)); + eeprom_write_word((uint16_t *) (_address + 4), (int)(_kd * 1000.0)); + eeprom_write_word((uint16_t *) (_address + 6), (int)(_imax)); /*_ee.write_int(_address, (int)(_kp * 1000)); _ee.write_int(_address + 2, (int)(_ki * 1000)); diff --git a/libraries/PID/PID.h b/libraries/PID/PID.h index 2e8edbe126..e160069a43 100644 --- a/libraries/PID/PID.h +++ b/libraries/PID/PID.h @@ -105,7 +105,7 @@ public: void kP(const float v) { _gain_array[0] = v; } void kI(const float v) { _gain_array[1] = v; } void kD(const float v) { _gain_array[2] = v; } - void imax(const float v); + void imax(const float v) { _gain_array[3] = fabs(v); } void address(const uint16_t v) { _address = v; }