1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

OP-1397 Round to instead of floor to uint8_t values in txpid.c

This commit is contained in:
Stefan Karlsson 2014-08-01 14:51:39 +02:00
parent 04d9d3191d
commit 7f344da977

View File

@ -83,7 +83,7 @@
// Private functions // Private functions
static void updatePIDs(UAVObjEvent *ev); static void updatePIDs(UAVObjEvent *ev);
static uint8_t update(float *var, float val); static uint8_t update(float *var, float val);
static uint8_t updateResponsiveness(uint8_t *var, float val); static uint8_t updateUint8(uint8_t *var, float val);
static float scale(float val, float inMin, float inMax, float outMin, float outMax); static float scale(float val, float inMin, float inMax, float outMin, float outMax);
/** /**
@ -240,7 +240,7 @@ static void updatePIDs(UAVObjEvent *ev)
needsUpdateBank |= update(&bank.RollPI.ILimit, value); needsUpdateBank |= update(&bank.RollPI.ILimit, value);
break; break;
case TXPIDSETTINGS_PIDS_ROLLATTITUDERESP: case TXPIDSETTINGS_PIDS_ROLLATTITUDERESP:
needsUpdateBank |= updateResponsiveness(&bank.RollMax, value); needsUpdateBank |= updateUint8(&bank.RollMax, value);
break; break;
case TXPIDSETTINGS_PIDS_PITCHRATEKP: case TXPIDSETTINGS_PIDS_PITCHRATEKP:
needsUpdateBank |= update(&bank.PitchRatePID.Kp, value); needsUpdateBank |= update(&bank.PitchRatePID.Kp, value);
@ -267,7 +267,7 @@ static void updatePIDs(UAVObjEvent *ev)
needsUpdateBank |= update(&bank.PitchPI.ILimit, value); needsUpdateBank |= update(&bank.PitchPI.ILimit, value);
break; break;
case TXPIDSETTINGS_PIDS_PITCHATTITUDERESP: case TXPIDSETTINGS_PIDS_PITCHATTITUDERESP:
needsUpdateBank |= updateResponsiveness(&bank.PitchMax, value); needsUpdateBank |= updateUint8(&bank.PitchMax, value);
break; break;
case TXPIDSETTINGS_PIDS_ROLLPITCHRATEKP: case TXPIDSETTINGS_PIDS_ROLLPITCHRATEKP:
needsUpdateBank |= update(&bank.RollRatePID.Kp, value); needsUpdateBank |= update(&bank.RollRatePID.Kp, value);
@ -302,8 +302,8 @@ static void updatePIDs(UAVObjEvent *ev)
needsUpdateBank |= update(&bank.PitchPI.ILimit, value); needsUpdateBank |= update(&bank.PitchPI.ILimit, value);
break; break;
case TXPIDSETTINGS_PIDS_ROLLPITCHATTITUDERESP: case TXPIDSETTINGS_PIDS_ROLLPITCHATTITUDERESP:
needsUpdateBank |= updateResponsiveness(&bank.RollMax, value); needsUpdateBank |= updateUint8(&bank.RollMax, value);
needsUpdateBank |= updateResponsiveness(&bank.PitchMax, value); needsUpdateBank |= updateUint8(&bank.PitchMax, value);
break; break;
case TXPIDSETTINGS_PIDS_YAWRATEKP: case TXPIDSETTINGS_PIDS_YAWRATEKP:
needsUpdateBank |= update(&bank.YawRatePID.Kp, value); needsUpdateBank |= update(&bank.YawRatePID.Kp, value);
@ -330,7 +330,7 @@ static void updatePIDs(UAVObjEvent *ev)
needsUpdateBank |= update(&bank.YawPI.ILimit, value); needsUpdateBank |= update(&bank.YawPI.ILimit, value);
break; break;
case TXPIDSETTINGS_PIDS_YAWATTITUDERESP: case TXPIDSETTINGS_PIDS_YAWATTITUDERESP:
needsUpdateBank |= updateResponsiveness(&bank.YawMax, value); needsUpdateBank |= updateUint8(&bank.YawMax, value);
break; break;
case TXPIDSETTINGS_PIDS_GYROTAU: case TXPIDSETTINGS_PIDS_GYROTAU:
needsUpdateStab |= update(&stab.GyroTau, value); needsUpdateStab |= update(&stab.GyroTau, value);
@ -420,10 +420,9 @@ static uint8_t update(float *var, float val)
* Updates var using val if needed. * Updates var using val if needed.
* \returns 1 if updated, 0 otherwise * \returns 1 if updated, 0 otherwise
*/ */
static uint8_t updateResponsiveness(uint8_t *var, float val) static uint8_t updateUint8(uint8_t *var, float val)
{ {
// Just floor it for now. uint8_t roundedVal = (uint8_t)roundf(val);
uint8_t roundedVal = (uint8_t)val;
if (*var != roundedVal) { if (*var != roundedVal) {
*var = roundedVal; *var = roundedVal;