1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 09:45:37 +03:00

Tidy rc_adjustments

This commit is contained in:
Martin Budden 2017-03-29 15:56:37 +01:00
parent c39ab90bc6
commit 9f07785e33
2 changed files with 177 additions and 218 deletions

View file

@ -100,122 +100,99 @@ static const adjustmentConfig_t defaultAdjustmentConfigs[ADJUSTMENT_FUNCTION_COU
{ {
.adjustmentFunction = ADJUSTMENT_RC_RATE, .adjustmentFunction = ADJUSTMENT_RC_RATE,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_RC_EXPO, .adjustmentFunction = ADJUSTMENT_RC_EXPO,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_THROTTLE_EXPO, .adjustmentFunction = ADJUSTMENT_THROTTLE_EXPO,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_PITCH_ROLL_RATE, .adjustmentFunction = ADJUSTMENT_PITCH_ROLL_RATE,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_YAW_RATE, .adjustmentFunction = ADJUSTMENT_YAW_RATE,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_PITCH_ROLL_P, .adjustmentFunction = ADJUSTMENT_PITCH_ROLL_P,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_PITCH_ROLL_I, .adjustmentFunction = ADJUSTMENT_PITCH_ROLL_I,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_PITCH_ROLL_D, .adjustmentFunction = ADJUSTMENT_PITCH_ROLL_D,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_YAW_P, .adjustmentFunction = ADJUSTMENT_YAW_P,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_YAW_I, .adjustmentFunction = ADJUSTMENT_YAW_I,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_YAW_D, .adjustmentFunction = ADJUSTMENT_YAW_D,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_RATE_PROFILE, .adjustmentFunction = ADJUSTMENT_RATE_PROFILE,
.mode = ADJUSTMENT_MODE_SELECT, .mode = ADJUSTMENT_MODE_SELECT,
.data = { .selectConfig = { .switchPositions = 3 }} .data = { .switchPositions = 3 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_PITCH_RATE, .adjustmentFunction = ADJUSTMENT_PITCH_RATE,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_ROLL_RATE, .adjustmentFunction = ADJUSTMENT_ROLL_RATE,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_PITCH_P, .adjustmentFunction = ADJUSTMENT_PITCH_P,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_PITCH_I, .adjustmentFunction = ADJUSTMENT_PITCH_I,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_PITCH_D, .adjustmentFunction = ADJUSTMENT_PITCH_D,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_ROLL_P, .adjustmentFunction = ADJUSTMENT_ROLL_P,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_ROLL_I, .adjustmentFunction = ADJUSTMENT_ROLL_I,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_ROLL_D, .adjustmentFunction = ADJUSTMENT_ROLL_D,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_RC_RATE_YAW, .adjustmentFunction = ADJUSTMENT_RC_RATE_YAW,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_D_SETPOINT, .adjustmentFunction = ADJUSTMENT_D_SETPOINT,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_D_SETPOINT_TRANSITION, .adjustmentFunction = ADJUSTMENT_D_SETPOINT_TRANSITION,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .step = 1 }
}, }, {
{
.adjustmentFunction = ADJUSTMENT_HORIZON_STRENGTH, .adjustmentFunction = ADJUSTMENT_HORIZON_STRENGTH,
.mode = ADJUSTMENT_MODE_SELECT, .mode = ADJUSTMENT_MODE_SELECT,
.data = { .selectConfig = { .switchPositions = 255 }} .data = { .switchPositions = 255 }
} }
}; };
@ -241,13 +218,9 @@ static void configureAdjustment(uint8_t index, uint8_t auxSwitchChannelIndex, co
static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustmentFunction, int delta) static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustmentFunction, int delta)
{ {
int newValue;
if (delta > 0) { beeperConfirmationBeeps(delta > 0 ? 2 : 1);
beeperConfirmationBeeps(2); int newValue;
} else {
beeperConfirmationBeeps(1);
}
switch(adjustmentFunction) { switch(adjustmentFunction) {
case ADJUSTMENT_RC_RATE: case ADJUSTMENT_RC_RATE:
newValue = constrain((int)controlRateConfig->rcRate8 + delta, 0, 250); // FIXME magic numbers repeated in cli.c newValue = constrain((int)controlRateConfig->rcRate8 + delta, 0, 250); // FIXME magic numbers repeated in cli.c
@ -304,11 +277,10 @@ static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t
newValue = constrain((int)pidProfile->I8[PIDPITCH] + delta, 0, 200); // FIXME magic numbers repeated in cli.c newValue = constrain((int)pidProfile->I8[PIDPITCH] + delta, 0, 200); // FIXME magic numbers repeated in cli.c
pidProfile->I8[PIDPITCH] = newValue; pidProfile->I8[PIDPITCH] = newValue;
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_PITCH_I, newValue); blackboxLogInflightAdjustmentEvent(ADJUSTMENT_PITCH_I, newValue);
if (adjustmentFunction == ADJUSTMENT_PITCH_I) { if (adjustmentFunction == ADJUSTMENT_PITCH_I) {
break; break;
} }
// follow though for combined ADJUSTMENT_PITCH_ROLL_I // fall though for combined ADJUSTMENT_PITCH_ROLL_I
case ADJUSTMENT_ROLL_I: case ADJUSTMENT_ROLL_I:
newValue = constrain((int)pidProfile->I8[PIDROLL] + delta, 0, 200); // FIXME magic numbers repeated in cli.c newValue = constrain((int)pidProfile->I8[PIDROLL] + delta, 0, 200); // FIXME magic numbers repeated in cli.c
pidProfile->I8[PIDROLL] = newValue; pidProfile->I8[PIDROLL] = newValue;
@ -319,11 +291,10 @@ static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t
newValue = constrain((int)pidProfile->D8[PIDPITCH] + delta, 0, 200); // FIXME magic numbers repeated in cli.c newValue = constrain((int)pidProfile->D8[PIDPITCH] + delta, 0, 200); // FIXME magic numbers repeated in cli.c
pidProfile->D8[PIDPITCH] = newValue; pidProfile->D8[PIDPITCH] = newValue;
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_PITCH_D, newValue); blackboxLogInflightAdjustmentEvent(ADJUSTMENT_PITCH_D, newValue);
if (adjustmentFunction == ADJUSTMENT_PITCH_D) { if (adjustmentFunction == ADJUSTMENT_PITCH_D) {
break; break;
} }
// follow though for combined ADJUSTMENT_PITCH_ROLL_D // fall though for combined ADJUSTMENT_PITCH_ROLL_D
case ADJUSTMENT_ROLL_D: case ADJUSTMENT_ROLL_D:
newValue = constrain((int)pidProfile->D8[PIDROLL] + delta, 0, 200); // FIXME magic numbers repeated in cli.c newValue = constrain((int)pidProfile->D8[PIDROLL] + delta, 0, 200); // FIXME magic numbers repeated in cli.c
pidProfile->D8[PIDROLL] = newValue; pidProfile->D8[PIDROLL] = newValue;
@ -432,9 +403,9 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig)
if (adjustmentState->config->mode == ADJUSTMENT_MODE_STEP) { if (adjustmentState->config->mode == ADJUSTMENT_MODE_STEP) {
int delta; int delta;
if (rcData[channelIndex] > rxConfig()->midrc + 200) { if (rcData[channelIndex] > rxConfig()->midrc + 200) {
delta = adjustmentState->config->data.stepConfig.step; delta = adjustmentState->config->data.step;
} else if (rcData[channelIndex] < rxConfig()->midrc - 200) { } else if (rcData[channelIndex] < rxConfig()->midrc - 200) {
delta = 0 - adjustmentState->config->data.stepConfig.step; delta = -adjustmentState->config->data.step;
} else { } else {
// returning the switch to the middle immediately resets the ready state // returning the switch to the middle immediately resets the ready state
MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentIndex); MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentIndex);
@ -445,10 +416,10 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig)
continue; continue;
} }
applyStepAdjustment(controlRateConfig,adjustmentFunction,delta); applyStepAdjustment(controlRateConfig, adjustmentFunction, delta);
pidInitConfig(pidProfile); pidInitConfig(pidProfile);
} else if (adjustmentState->config->mode == ADJUSTMENT_MODE_SELECT) { } else if (adjustmentState->config->mode == ADJUSTMENT_MODE_SELECT) {
const uint16_t rangeWidth = ((2100 - 900) / adjustmentState->config->data.selectConfig.switchPositions); const uint16_t rangeWidth = ((2100 - 900) / adjustmentState->config->data.switchPositions);
const uint8_t position = (constrain(rcData[channelIndex], 900, 2100 - 1) - 900) / rangeWidth; const uint8_t position = (constrain(rcData[channelIndex], 900, 2100 - 1) - 900) / rangeWidth;
applySelectAdjustment(adjustmentFunction, position); applySelectAdjustment(adjustmentFunction, position);
} }

View file

@ -56,17 +56,9 @@ typedef enum {
ADJUSTMENT_MODE_SELECT ADJUSTMENT_MODE_SELECT
} adjustmentMode_e; } adjustmentMode_e;
typedef struct adjustmentStepConfig_s {
uint8_t step;
} adjustmentStepConfig_t;
typedef struct adjustmentSelectConfig_s {
uint8_t switchPositions;
} adjustmentSelectConfig_t;
typedef union adjustmentConfig_u { typedef union adjustmentConfig_u {
adjustmentStepConfig_t stepConfig; uint8_t step;
adjustmentSelectConfig_t selectConfig; uint8_t switchPositions;
} adjustmentData_t; } adjustmentData_t;
typedef struct adjustmentConfig_s { typedef struct adjustmentConfig_s {
@ -105,10 +97,6 @@ typedef struct adjustmentState_s {
PG_DECLARE_ARRAY(adjustmentRange_t, MAX_ADJUSTMENT_RANGE_COUNT, adjustmentRanges); PG_DECLARE_ARRAY(adjustmentRange_t, MAX_ADJUSTMENT_RANGE_COUNT, adjustmentRanges);
typedef struct adjustmentProfile_s {
adjustmentRange_t adjustmentRanges[MAX_ADJUSTMENT_RANGE_COUNT];
} adjustmentProfile_t;
void resetAdjustmentStates(void); void resetAdjustmentStates(void);
void updateAdjustmentStates(void); void updateAdjustmentStates(void);
struct controlRateConfig_s; struct controlRateConfig_s;