From 7f344da9778ae6b615e45dd846dadaca6f6b3690 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 1 Aug 2014 14:51:39 +0200 Subject: [PATCH] OP-1397 Round to instead of floor to uint8_t values in txpid.c --- flight/modules/TxPID/txpid.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/flight/modules/TxPID/txpid.c b/flight/modules/TxPID/txpid.c index c49ed49d7..f356558e8 100644 --- a/flight/modules/TxPID/txpid.c +++ b/flight/modules/TxPID/txpid.c @@ -83,7 +83,7 @@ // Private functions static void updatePIDs(UAVObjEvent *ev); 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); /** @@ -240,7 +240,7 @@ static void updatePIDs(UAVObjEvent *ev) needsUpdateBank |= update(&bank.RollPI.ILimit, value); break; case TXPIDSETTINGS_PIDS_ROLLATTITUDERESP: - needsUpdateBank |= updateResponsiveness(&bank.RollMax, value); + needsUpdateBank |= updateUint8(&bank.RollMax, value); break; case TXPIDSETTINGS_PIDS_PITCHRATEKP: needsUpdateBank |= update(&bank.PitchRatePID.Kp, value); @@ -267,7 +267,7 @@ static void updatePIDs(UAVObjEvent *ev) needsUpdateBank |= update(&bank.PitchPI.ILimit, value); break; case TXPIDSETTINGS_PIDS_PITCHATTITUDERESP: - needsUpdateBank |= updateResponsiveness(&bank.PitchMax, value); + needsUpdateBank |= updateUint8(&bank.PitchMax, value); break; case TXPIDSETTINGS_PIDS_ROLLPITCHRATEKP: needsUpdateBank |= update(&bank.RollRatePID.Kp, value); @@ -302,8 +302,8 @@ static void updatePIDs(UAVObjEvent *ev) needsUpdateBank |= update(&bank.PitchPI.ILimit, value); break; case TXPIDSETTINGS_PIDS_ROLLPITCHATTITUDERESP: - needsUpdateBank |= updateResponsiveness(&bank.RollMax, value); - needsUpdateBank |= updateResponsiveness(&bank.PitchMax, value); + needsUpdateBank |= updateUint8(&bank.RollMax, value); + needsUpdateBank |= updateUint8(&bank.PitchMax, value); break; case TXPIDSETTINGS_PIDS_YAWRATEKP: needsUpdateBank |= update(&bank.YawRatePID.Kp, value); @@ -330,7 +330,7 @@ static void updatePIDs(UAVObjEvent *ev) needsUpdateBank |= update(&bank.YawPI.ILimit, value); break; case TXPIDSETTINGS_PIDS_YAWATTITUDERESP: - needsUpdateBank |= updateResponsiveness(&bank.YawMax, value); + needsUpdateBank |= updateUint8(&bank.YawMax, value); break; case TXPIDSETTINGS_PIDS_GYROTAU: needsUpdateStab |= update(&stab.GyroTau, value); @@ -420,10 +420,9 @@ static uint8_t update(float *var, float val) * Updates var using val if needed. * \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)val; + uint8_t roundedVal = (uint8_t)roundf(val); if (*var != roundedVal) { *var = roundedVal;