1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

OP-1534 Add expo and acro insanity factor to TxPID

This commit is contained in:
Stefan Karlsson 2014-10-10 17:57:24 +02:00
parent 19a7f4cd22
commit bedb749f72
3 changed files with 78 additions and 1 deletions

View File

@ -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;
}
/**
* @}
*/

View File

@ -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 <class StabilizationSettingsBankX>
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);

View File

@ -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"/>
<field name="MinPID" units="" type="float" elementnames="Instance1,Instance2,Instance3" defaultvalue="0"/>
<field name="MaxPID" units="" type="float" elementnames="Instance1,Instance2,Instance3" defaultvalue="0"/>