mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
OP-1397 Round to instead of floor to uint8_t values in txpid.c
This commit is contained in:
parent
04d9d3191d
commit
7f344da977
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user