mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 12:25:20 +03:00
Second draft of the tuneup.
This uses ints for the sensitivity instead of mapping floats back and forth. Also the stick position is read directly, without the RC_Rate affecting this value.
This commit is contained in:
parent
6b7c9facd3
commit
69d94c81e1
8 changed files with 23 additions and 11 deletions
|
@ -159,7 +159,7 @@ static void resetPidProfile(pidProfile_t *pidProfile)
|
||||||
pidProfile->D_f[YAW] = 0.05f;
|
pidProfile->D_f[YAW] = 0.05f;
|
||||||
pidProfile->A_level = 5.0f;
|
pidProfile->A_level = 5.0f;
|
||||||
pidProfile->H_level = 3.0f;
|
pidProfile->H_level = 3.0f;
|
||||||
pidProfile->H_sensitivity = 10.0f;
|
pidProfile->H_sensitivity = 75;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GPS
|
#ifdef GPS
|
||||||
|
|
|
@ -96,6 +96,7 @@ static void pidBaseflight(pidProfile_t *pidProfile, controlRateConfig_t *control
|
||||||
{
|
{
|
||||||
float RateError, errorAngle, AngleRate, gyroRate;
|
float RateError, errorAngle, AngleRate, gyroRate;
|
||||||
float ITerm,PTerm,DTerm;
|
float ITerm,PTerm,DTerm;
|
||||||
|
int32_t stickPosAil, stickPosEle, mostDeflectedPos;
|
||||||
static float lastGyroRate[3];
|
static float lastGyroRate[3];
|
||||||
static float delta1[3], delta2[3];
|
static float delta1[3], delta2[3];
|
||||||
float delta, deltaSum;
|
float delta, deltaSum;
|
||||||
|
@ -107,19 +108,23 @@ static void pidBaseflight(pidProfile_t *pidProfile, controlRateConfig_t *control
|
||||||
|
|
||||||
if (FLIGHT_MODE(HORIZON_MODE)) {
|
if (FLIGHT_MODE(HORIZON_MODE)) {
|
||||||
|
|
||||||
if(abs(rcCommand[FD_ROLL]) > abs(rcCommand[FD_PITCH])){
|
// Figure out the raw stick positions
|
||||||
axis = FD_ROLL;
|
stickPosAil = getRcStickPosition(FD_ROLL);
|
||||||
|
stickPosEle = getRcStickPosition(FD_PITCH);
|
||||||
|
|
||||||
|
if(abs(stickPosAil) > abs(stickPosEle)){
|
||||||
|
mostDeflectedPos = abs(stickPosAil);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
axis = FD_PITCH;
|
mostDeflectedPos = abs(stickPosEle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Progressively turn off the horizon self level strength as the stick is banged over
|
// Progressively turn off the horizon self level strength as the stick is banged over
|
||||||
horizonLevelStrength = (float)(500 - abs(rcCommand[axis])) / 500; // 1 at centre stick, 0 = max stick deflection
|
horizonLevelStrength = (float)(500 - mostDeflectedPos) / 500; // 1 at centre stick, 0 = max stick deflection
|
||||||
if(pidProfile->H_sensitivity == 0){
|
if(pidProfile->H_sensitivity == 0){
|
||||||
horizonLevelStrength = 0;
|
horizonLevelStrength = 0;
|
||||||
} else {
|
} else {
|
||||||
horizonLevelStrength = constrainf(((horizonLevelStrength - 1) * (10 / pidProfile->H_sensitivity)) + 1, 0, 1);
|
horizonLevelStrength = constrainf(((horizonLevelStrength - 1) * (100 / pidProfile->H_sensitivity)) + 1, 0, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ typedef struct pidProfile_s {
|
||||||
float D_f[3];
|
float D_f[3];
|
||||||
float A_level;
|
float A_level;
|
||||||
float H_level;
|
float H_level;
|
||||||
float H_sensitivity;
|
uint8_t H_sensitivity;
|
||||||
} pidProfile_t;
|
} pidProfile_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -140,7 +140,7 @@ throttleStatus_e calculateThrottleStatus(rxConfig_t *rxConfig, uint16_t deadband
|
||||||
void processRcStickPositions(rxConfig_t *rxConfig, throttleStatus_e throttleStatus, bool retarded_arm, bool disarm_kill_switch);
|
void processRcStickPositions(rxConfig_t *rxConfig, throttleStatus_e throttleStatus, bool retarded_arm, bool disarm_kill_switch);
|
||||||
|
|
||||||
void updateActivatedModes(modeActivationCondition_t *modeActivationConditions);
|
void updateActivatedModes(modeActivationCondition_t *modeActivationConditions);
|
||||||
|
int32_t getRcStickPosition(int32_t axis);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ADJUSTMENT_NONE = 0,
|
ADJUSTMENT_NONE = 0,
|
||||||
|
|
|
@ -392,7 +392,7 @@ const clivalue_t valueTable[] = {
|
||||||
|
|
||||||
{ "level_horizon", VAR_FLOAT | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.H_level, 0, 10 },
|
{ "level_horizon", VAR_FLOAT | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.H_level, 0, 10 },
|
||||||
{ "level_angle", VAR_FLOAT | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.A_level, 0, 10 },
|
{ "level_angle", VAR_FLOAT | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.A_level, 0, 10 },
|
||||||
{ "sensitivity_horizon", VAR_FLOAT | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.H_sensitivity, 0, 250 },
|
{ "sensitivity_horizon", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.H_sensitivity, 0, 250 },
|
||||||
|
|
||||||
{ "p_alt", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDALT], 0, 200 },
|
{ "p_alt", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PIDALT], 0, 200 },
|
||||||
{ "i_alt", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDALT], 0, 200 },
|
{ "i_alt", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDALT], 0, 200 },
|
||||||
|
|
|
@ -846,7 +846,7 @@ static bool processOutCommand(uint8_t cmdMSP)
|
||||||
if (i == PIDLEVEL) {
|
if (i == PIDLEVEL) {
|
||||||
serialize8(constrain(lrintf(currentProfile->pidProfile.A_level * 10.0f), 0, 250));
|
serialize8(constrain(lrintf(currentProfile->pidProfile.A_level * 10.0f), 0, 250));
|
||||||
serialize8(constrain(lrintf(currentProfile->pidProfile.H_level * 10.0f), 0, 250));
|
serialize8(constrain(lrintf(currentProfile->pidProfile.H_level * 10.0f), 0, 250));
|
||||||
serialize8(constrain(lrintf(currentProfile->pidProfile.H_sensitivity * 10.0f), 0, 250));
|
serialize8(constrain(lrintf(currentProfile->pidProfile.H_sensitivity), 0, 250));
|
||||||
} else {
|
} else {
|
||||||
serialize8(currentProfile->pidProfile.P8[i]);
|
serialize8(currentProfile->pidProfile.P8[i]);
|
||||||
serialize8(currentProfile->pidProfile.I8[i]);
|
serialize8(currentProfile->pidProfile.I8[i]);
|
||||||
|
@ -1165,7 +1165,7 @@ static bool processInCommand(void)
|
||||||
if (i == PIDLEVEL) {
|
if (i == PIDLEVEL) {
|
||||||
currentProfile->pidProfile.A_level = (float)read8() / 10.0f;
|
currentProfile->pidProfile.A_level = (float)read8() / 10.0f;
|
||||||
currentProfile->pidProfile.H_level = (float)read8() / 10.0f;
|
currentProfile->pidProfile.H_level = (float)read8() / 10.0f;
|
||||||
currentProfile->pidProfile.H_sensitivity = (float)read8() / 10.0f;
|
currentProfile->pidProfile.H_sensitivity = read8();
|
||||||
} else {
|
} else {
|
||||||
currentProfile->pidProfile.P8[i] = read8();
|
currentProfile->pidProfile.P8[i] = read8();
|
||||||
currentProfile->pidProfile.I8[i] = read8();
|
currentProfile->pidProfile.I8[i] = read8();
|
||||||
|
|
|
@ -338,6 +338,11 @@ void mwArm(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t getRcStickPosition(int32_t axis) {
|
||||||
|
|
||||||
|
return min(abs(rcData[axis] - masterConfig.rxConfig.midrc), 500);
|
||||||
|
}
|
||||||
|
|
||||||
// Automatic ACC Offset Calibration
|
// Automatic ACC Offset Calibration
|
||||||
bool AccInflightCalibrationArmed = false;
|
bool AccInflightCalibrationArmed = false;
|
||||||
bool AccInflightCalibrationMeasurementDone = false;
|
bool AccInflightCalibrationMeasurementDone = false;
|
||||||
|
|
|
@ -22,3 +22,5 @@ void handleInflightCalibrationStickPosition();
|
||||||
|
|
||||||
void mwDisarm(void);
|
void mwDisarm(void);
|
||||||
void mwArm(void);
|
void mwArm(void);
|
||||||
|
|
||||||
|
int32_t getRcStickPosition(int32_t axis);
|
Loading…
Add table
Add a link
Reference in a new issue