From bedb749f72e111db8f098c34adc8c598f201174d Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 10 Oct 2014 17:57:24 +0200 Subject: [PATCH 1/2] OP-1534 Add expo and acro insanity factor to TxPID --- flight/modules/TxPID/txpid.c | 31 +++++++++++++ .../src/plugins/config/configtxpidwidget.cpp | 45 +++++++++++++++++++ shared/uavobjectdefinition/txpidsettings.xml | 3 +- 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/flight/modules/TxPID/txpid.c b/flight/modules/TxPID/txpid.c index a1e5fd995..ca21c2771 100644 --- a/flight/modules/TxPID/txpid.c +++ b/flight/modules/TxPID/txpid.c @@ -83,6 +83,7 @@ static void updatePIDs(UAVObjEvent *ev); static uint8_t update(float *var, float val); static uint8_t updateUint8(uint8_t *var, float val); +static uint8_t updateInt8(int8_t *var, float val); static float scale(float val, float inMin, float inMax, float outMin, float outMax); /** @@ -331,9 +332,24 @@ static void updatePIDs(UAVObjEvent *ev) case TXPIDSETTINGS_PIDS_YAWATTITUDERESP: needsUpdateBank |= updateUint8(&bank.YawMax, value); break; + case TXPIDSETTINGS_PIDS_ROLLEXPO: + needsUpdateBank |= updateInt8(&bank.StickExpo.Roll, value); + break; + case TXPIDSETTINGS_PIDS_PITCHEXPO: + needsUpdateBank |= updateInt8(&bank.StickExpo.Pitch, value); + break; + case TXPIDSETTINGS_PIDS_ROLLPITCHEXPO: + needsUpdateBank |= updateInt8(&bank.StickExpo.Roll, value); + break; + case TXPIDSETTINGS_PIDS_YAWEXPO: + needsUpdateBank |= updateInt8(&bank.StickExpo.Yaw, value); + break; case TXPIDSETTINGS_PIDS_GYROTAU: needsUpdateStab |= update(&stab.GyroTau, value); break; + case TXPIDSETTINGS_PIDS_ACROPLUSFACTOR: + needsUpdateBank |= update(&bank.AcroInsanityFactor, value); + break; default: PIOS_Assert(0); } @@ -430,6 +446,21 @@ static uint8_t updateUint8(uint8_t *var, float val) return 0; } +/** + * Updates var using val if needed. + * \returns 1 if updated, 0 otherwise + */ +static uint8_t updateInt8(int8_t *var, float val) +{ + int8_t roundedVal = (int8_t)roundf(val); + + if (*var != roundedVal) { + *var = roundedVal; + return 1; + } + return 0; +} + /** * @} */ diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp index 0f0e7fa87..4787056c4 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp @@ -145,6 +145,25 @@ static bool isAttitudeOption(int pidOption) } } +static bool isExpoOption(int pidOption) +{ + switch (pidOption) { + case TxPIDSettings::PIDS_ROLLEXPO: + case TxPIDSettings::PIDS_PITCHEXPO: + case TxPIDSettings::PIDS_ROLLPITCHEXPO: + case TxPIDSettings::PIDS_YAWEXPO: + return true; + + default: + return false; + } +} + +static bool isAcroPlusFactorOption(int pidOption) +{ + return pidOption == TxPIDSettings::PIDS_ACROPLUSFACTOR; +} + template static float defaultValueForPidOption(const StabilizationSettingsBankX *bank, int pidOption) { @@ -260,6 +279,18 @@ static float defaultValueForPidOption(const StabilizationSettingsBankX *bank, in case TxPIDSettings::PIDS_YAWATTITUDERESP: return bank->getYawMax(); + case TxPIDSettings::PIDS_ROLLEXPO: + return bank->getStickExpo_Roll(); + + case TxPIDSettings::PIDS_PITCHEXPO: + return bank->getStickExpo_Pitch(); + + case TxPIDSettings::PIDS_ROLLPITCHEXPO: + return bank->getStickExpo_Roll(); + + case TxPIDSettings::PIDS_YAWEXPO: + return bank->getStickExpo_Yaw(); + case -1: // The PID Option field was uninitialized. return 0.0f; @@ -337,6 +368,20 @@ void ConfigTxPIDWidget::updateSpinBoxProperties(int selectedPidOption) maxPID->setSingleStep(1); minPID->setDecimals(0); maxPID->setDecimals(0); + } else if (isExpoOption(selectedPidOption)) { + minPID->setRange(-100, 100); + maxPID->setRange(-100, 100); + minPID->setSingleStep(1); + maxPID->setSingleStep(1); + minPID->setDecimals(0); + maxPID->setDecimals(0); + } else if (isAcroPlusFactorOption(selectedPidOption)) { + minPID->setRange(0, 1); + maxPID->setRange(0, 1); + minPID->setSingleStep(0.01); + maxPID->setSingleStep(0.01); + minPID->setDecimals(2); + maxPID->setDecimals(2); } else { minPID->setRange(0, 99.99); maxPID->setRange(0, 99.99); diff --git a/shared/uavobjectdefinition/txpidsettings.xml b/shared/uavobjectdefinition/txpidsettings.xml index c1bd56740..28035452b 100644 --- a/shared/uavobjectdefinition/txpidsettings.xml +++ b/shared/uavobjectdefinition/txpidsettings.xml @@ -19,7 +19,8 @@ Pitch Attitude.Kp, Pitch Attitude.Ki, Pitch Attitude.ILimit, Pitch Attitude.Resp, Roll+Pitch Attitude.Kp, Roll+Pitch Attitude.Ki, Roll+Pitch Attitude.ILimit, Roll+Pitch Attitude.Resp, Yaw Attitude.Kp, Yaw Attitude.Ki, Yaw Attitude.ILimit, Yaw Attitude.Resp, - GyroTau" + Roll.Expo, Pitch.Expo, Roll+Pitch.Expo, Yaw.Expo, + GyroTau,AcroPlusFactor" defaultvalue="Disabled"/> From c03d390269bcfb3d4b7485f8940923a1d29a9525 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 10 Oct 2014 18:49:18 +0200 Subject: [PATCH 2/2] OP-1534 Update both roll and pitch with TxPID Roll+Pitch.Expo option --- flight/modules/TxPID/txpid.c | 1 + 1 file changed, 1 insertion(+) diff --git a/flight/modules/TxPID/txpid.c b/flight/modules/TxPID/txpid.c index ca21c2771..c4e94fbc8 100644 --- a/flight/modules/TxPID/txpid.c +++ b/flight/modules/TxPID/txpid.c @@ -340,6 +340,7 @@ static void updatePIDs(UAVObjEvent *ev) break; case TXPIDSETTINGS_PIDS_ROLLPITCHEXPO: needsUpdateBank |= updateInt8(&bank.StickExpo.Roll, value); + needsUpdateBank |= updateInt8(&bank.StickExpo.Pitch, value); break; case TXPIDSETTINGS_PIDS_YAWEXPO: needsUpdateBank |= updateInt8(&bank.StickExpo.Yaw, value);