mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-21 11:54:15 +01:00
OP-1534 Add expo and acro insanity factor to TxPID
This commit is contained in:
parent
19a7f4cd22
commit
bedb749f72
@ -83,6 +83,7 @@
|
|||||||
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 updateUint8(uint8_t *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);
|
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:
|
case TXPIDSETTINGS_PIDS_YAWATTITUDERESP:
|
||||||
needsUpdateBank |= updateUint8(&bank.YawMax, value);
|
needsUpdateBank |= updateUint8(&bank.YawMax, value);
|
||||||
break;
|
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:
|
case TXPIDSETTINGS_PIDS_GYROTAU:
|
||||||
needsUpdateStab |= update(&stab.GyroTau, value);
|
needsUpdateStab |= update(&stab.GyroTau, value);
|
||||||
break;
|
break;
|
||||||
|
case TXPIDSETTINGS_PIDS_ACROPLUSFACTOR:
|
||||||
|
needsUpdateBank |= update(&bank.AcroInsanityFactor, value);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
PIOS_Assert(0);
|
PIOS_Assert(0);
|
||||||
}
|
}
|
||||||
@ -430,6 +446,21 @@ static uint8_t updateUint8(uint8_t *var, float val)
|
|||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
@ -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>
|
template <class StabilizationSettingsBankX>
|
||||||
static float defaultValueForPidOption(const StabilizationSettingsBankX *bank, int pidOption)
|
static float defaultValueForPidOption(const StabilizationSettingsBankX *bank, int pidOption)
|
||||||
{
|
{
|
||||||
@ -260,6 +279,18 @@ static float defaultValueForPidOption(const StabilizationSettingsBankX *bank, in
|
|||||||
case TxPIDSettings::PIDS_YAWATTITUDERESP:
|
case TxPIDSettings::PIDS_YAWATTITUDERESP:
|
||||||
return bank->getYawMax();
|
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.
|
case -1: // The PID Option field was uninitialized.
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
|
|
||||||
@ -337,6 +368,20 @@ void ConfigTxPIDWidget::updateSpinBoxProperties(int selectedPidOption)
|
|||||||
maxPID->setSingleStep(1);
|
maxPID->setSingleStep(1);
|
||||||
minPID->setDecimals(0);
|
minPID->setDecimals(0);
|
||||||
maxPID->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 {
|
} else {
|
||||||
minPID->setRange(0, 99.99);
|
minPID->setRange(0, 99.99);
|
||||||
maxPID->setRange(0, 99.99);
|
maxPID->setRange(0, 99.99);
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
Pitch Attitude.Kp, Pitch Attitude.Ki, Pitch Attitude.ILimit, Pitch Attitude.Resp,
|
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,
|
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,
|
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"/>
|
defaultvalue="Disabled"/>
|
||||||
<field name="MinPID" units="" type="float" elementnames="Instance1,Instance2,Instance3" defaultvalue="0"/>
|
<field name="MinPID" units="" type="float" elementnames="Instance1,Instance2,Instance3" defaultvalue="0"/>
|
||||||
<field name="MaxPID" units="" type="float" elementnames="Instance1,Instance2,Instance3" defaultvalue="0"/>
|
<field name="MaxPID" units="" type="float" elementnames="Instance1,Instance2,Instance3" defaultvalue="0"/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user