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

Removed inflight adjustment of rate profile

This commit is contained in:
Martin Budden 2017-01-23 07:55:06 +00:00
parent 5a1e390a1c
commit 0ca01635a6
5 changed files with 63 additions and 71 deletions

View file

@ -23,6 +23,8 @@
#define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0])) #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))
#define ARRAYEND(x) (&(x)[ARRAYLEN(x)]) #define ARRAYEND(x) (&(x)[ARRAYLEN(x)])
#define CONST_CAST(type, value) ((type)(value))
#define CONCAT_HELPER(x,y) x ## y #define CONCAT_HELPER(x,y) x ## y
#define CONCAT(x,y) CONCAT_HELPER(x, y) #define CONCAT(x,y) CONCAT_HELPER(x, y)

View file

@ -95,7 +95,6 @@ PG_RESET_TEMPLATE(featureConfig_t, featureConfig,
PG_REGISTER_WITH_RESET_TEMPLATE(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 0); PG_REGISTER_WITH_RESET_TEMPLATE(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 0);
PG_RESET_TEMPLATE(systemConfig_t, systemConfig, PG_RESET_TEMPLATE(systemConfig_t, systemConfig,
.currentControlRateProfileIndex = 0,
.current_profile_index = 0, .current_profile_index = 0,
.debug_mode = DEBUG_NONE, .debug_mode = DEBUG_NONE,
.i2c_overclock = 0, .i2c_overclock = 0,

View file

@ -363,7 +363,7 @@ void processRx(timeUs_t currentTimeUs)
if (!cliMode) { if (!cliMode) {
updateAdjustmentStates(); updateAdjustmentStates();
processRcAdjustments(currentControlRateProfile); processRcAdjustments(CONST_CAST(controlRateConfig_t*, currentControlRateProfile));
} }
bool canUseHorizonMode = true; bool canUseHorizonMode = true;

View file

@ -47,7 +47,7 @@
PG_REGISTER_ARRAY(adjustmentRange_t, MAX_ADJUSTMENT_RANGE_COUNT, adjustmentRanges, PG_ADJUSTMENT_RANGE_CONFIG, 0); PG_REGISTER_ARRAY(adjustmentRange_t, MAX_ADJUSTMENT_RANGE_COUNT, adjustmentRanges, PG_ADJUSTMENT_RANGE_CONFIG, 0);
uint8_t adjustmentStateMask = 0; static uint8_t adjustmentStateMask = 0;
#define MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentIndex) adjustmentStateMask |= (1 << adjustmentIndex) #define MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentIndex) adjustmentStateMask |= (1 << adjustmentIndex)
#define MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentIndex) adjustmentStateMask &= ~(1 << adjustmentIndex) #define MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentIndex) adjustmentStateMask &= ~(1 << adjustmentIndex)
@ -60,110 +60,94 @@ 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 = { .stepConfig = { .step = 1 }}
}, }, {
{
.adjustmentFunction = ADJUSTMENT_RC_EXPO, .adjustmentFunction = ADJUSTMENT_RC_EXPO,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .stepConfig = { .step = 1 }}
}, }, {
{
.adjustmentFunction = ADJUSTMENT_THROTTLE_EXPO, .adjustmentFunction = ADJUSTMENT_THROTTLE_EXPO,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .stepConfig = { .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 = { .stepConfig = { .step = 1 }}
}, }, {
{
.adjustmentFunction = ADJUSTMENT_YAW_RATE, .adjustmentFunction = ADJUSTMENT_YAW_RATE,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .stepConfig = { .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 = { .stepConfig = { .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 = { .stepConfig = { .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 = { .stepConfig = { .step = 1 }}
}, }, {
{
.adjustmentFunction = ADJUSTMENT_YAW_P, .adjustmentFunction = ADJUSTMENT_YAW_P,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .stepConfig = { .step = 1 }}
}, }, {
{
.adjustmentFunction = ADJUSTMENT_YAW_I, .adjustmentFunction = ADJUSTMENT_YAW_I,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .stepConfig = { .step = 1 }}
}, }, {
{
.adjustmentFunction = ADJUSTMENT_YAW_D, .adjustmentFunction = ADJUSTMENT_YAW_D,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .stepConfig = { .step = 1 }}
}, }, {
{
.adjustmentFunction = ADJUSTMENT_RATE_PROFILE,
.mode = ADJUSTMENT_MODE_SELECT,
.data = { .selectConfig = { .switchPositions = 3 }}
},
{
.adjustmentFunction = ADJUSTMENT_PITCH_RATE, .adjustmentFunction = ADJUSTMENT_PITCH_RATE,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .stepConfig = { .step = 1 }}
}, }, {
{
.adjustmentFunction = ADJUSTMENT_ROLL_RATE, .adjustmentFunction = ADJUSTMENT_ROLL_RATE,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .stepConfig = { .step = 1 }}
}, }, {
{
.adjustmentFunction = ADJUSTMENT_PITCH_P, .adjustmentFunction = ADJUSTMENT_PITCH_P,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .stepConfig = { .step = 1 }}
}, }, {
{
.adjustmentFunction = ADJUSTMENT_PITCH_I, .adjustmentFunction = ADJUSTMENT_PITCH_I,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .stepConfig = { .step = 1 }}
}, }, {
{
.adjustmentFunction = ADJUSTMENT_PITCH_D, .adjustmentFunction = ADJUSTMENT_PITCH_D,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .stepConfig = { .step = 1 }}
}, }, {
{
.adjustmentFunction = ADJUSTMENT_ROLL_P, .adjustmentFunction = ADJUSTMENT_ROLL_P,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .stepConfig = { .step = 1 }}
}, }, {
{
.adjustmentFunction = ADJUSTMENT_ROLL_I, .adjustmentFunction = ADJUSTMENT_ROLL_I,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .stepConfig = { .step = 1 }}
}, }, {
{
.adjustmentFunction = ADJUSTMENT_ROLL_D, .adjustmentFunction = ADJUSTMENT_ROLL_D,
.mode = ADJUSTMENT_MODE_STEP, .mode = ADJUSTMENT_MODE_STEP,
.data = { .stepConfig = { .step = 1 }} .data = { .stepConfig = { .step = 1 }}
#ifdef USE_INFLIGHT_PROFILE_ADJUSTMENT
}, {
.adjustmentFunction = ADJUSTMENT_PROFILE,
.mode = ADJUSTMENT_MODE_SELECT,
.data = { .selectConfig = { .switchPositions = 3 }}
#endif
} }
}; };
#define ADJUSTMENT_FUNCTION_CONFIG_INDEX_OFFSET 1 #define ADJUSTMENT_FUNCTION_CONFIG_INDEX_OFFSET 1
adjustmentState_t adjustmentStates[MAX_SIMULTANEOUS_ADJUSTMENT_COUNT]; static adjustmentState_t adjustmentStates[MAX_SIMULTANEOUS_ADJUSTMENT_COUNT];
static void configureAdjustment(uint8_t index, uint8_t auxSwitchChannelIndex, const adjustmentConfig_t *adjustmentConfig) { static void configureAdjustment(uint8_t index, uint8_t auxSwitchChannelIndex, const adjustmentConfig_t *adjustmentConfig)
adjustmentState_t *adjustmentState = &adjustmentStates[index]; {
adjustmentState_t * const adjustmentState = &adjustmentStates[index];
if (adjustmentState->config == adjustmentConfig) { if (adjustmentState->config == adjustmentConfig) {
// already configured // already configured
@ -176,7 +160,8 @@ static void configureAdjustment(uint8_t index, uint8_t auxSwitchChannelIndex, co
MARK_ADJUSTMENT_FUNCTION_AS_READY(index); MARK_ADJUSTMENT_FUNCTION_AS_READY(index);
} }
static void blackboxLogInflightAdjustmentEvent(adjustmentFunction_e adjustmentFunction, int32_t newValue) { static void blackboxLogInflightAdjustmentEvent(adjustmentFunction_e adjustmentFunction, int32_t newValue)
{
#ifndef BLACKBOX #ifndef BLACKBOX
UNUSED(adjustmentFunction); UNUSED(adjustmentFunction);
UNUSED(newValue); UNUSED(newValue);
@ -192,7 +177,8 @@ static void blackboxLogInflightAdjustmentEvent(adjustmentFunction_e adjustmentFu
} }
#if 0 #if 0
static void blackboxLogInflightAdjustmentEventFloat(adjustmentFunction_e adjustmentFunction, float newFloatValue) { static void blackboxLogInflightAdjustmentEventFloat(adjustmentFunction_e adjustmentFunction, float newFloatValue)
{
#ifndef BLACKBOX #ifndef BLACKBOX
UNUSED(adjustmentFunction); UNUSED(adjustmentFunction);
UNUSED(newFloatValue); UNUSED(newFloatValue);
@ -208,14 +194,14 @@ static void blackboxLogInflightAdjustmentEventFloat(adjustmentFunction_e adjustm
} }
#endif #endif
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) { if (delta > 0) {
beeperConfirmationBeeps(2); beeperConfirmationBeeps(2);
} else { } else {
beeperConfirmationBeeps(1); beeperConfirmationBeeps(1);
} }
int newValue;
switch(adjustmentFunction) { switch(adjustmentFunction) {
case ADJUSTMENT_RC_EXPO: case ADJUSTMENT_RC_EXPO:
newValue = constrain((int)controlRateConfig->rcExpo8 + delta, 0, 100); // FIXME magic numbers repeated in serial_cli.c newValue = constrain((int)controlRateConfig->rcExpo8 + delta, 0, 100); // FIXME magic numbers repeated in serial_cli.c
@ -321,6 +307,7 @@ static void applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t
}; };
} }
#ifdef USE_INFLIGHT_PROFILE_ADJUSTMENT
static void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position) static void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position)
{ {
bool applied = false; bool applied = false;
@ -339,30 +326,29 @@ static void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position)
beeperConfirmationBeeps(position + 1); beeperConfirmationBeeps(position + 1);
} }
} }
#endif
#define RESET_FREQUENCY_2HZ (1000 / 2) #define RESET_FREQUENCY_2HZ (1000 / 2)
void processRcAdjustments(const controlRateConfig_t *controlRateConfig) void processRcAdjustments(controlRateConfig_t *controlRateConfig)
{ {
uint8_t adjustmentIndex; const uint32_t now = millis();
uint32_t now = millis();
bool canUseRxData = rxIsReceivingSignal(); const bool canUseRxData = rxIsReceivingSignal();
for (int adjustmentIndex = 0; adjustmentIndex < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT; adjustmentIndex++) {
for (adjustmentIndex = 0; adjustmentIndex < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT; adjustmentIndex++) { adjustmentState_t * const adjustmentState = &adjustmentStates[adjustmentIndex];
adjustmentState_t *adjustmentState = &adjustmentStates[adjustmentIndex];
if (!adjustmentState->config) { if (!adjustmentState->config) {
continue; continue;
} }
uint8_t adjustmentFunction = adjustmentState->config->adjustmentFunction; const uint8_t adjustmentFunction = adjustmentState->config->adjustmentFunction;
if (adjustmentFunction == ADJUSTMENT_NONE) { if (adjustmentFunction == ADJUSTMENT_NONE) {
continue; continue;
} }
int32_t signedDiff = now - adjustmentState->timeoutAt; const int32_t signedDiff = now - adjustmentState->timeoutAt;
bool canResetReadyStates = signedDiff >= 0L; const bool canResetReadyStates = signedDiff >= 0L;
if (canResetReadyStates) { if (canResetReadyStates) {
adjustmentState->timeoutAt = now + RESET_FREQUENCY_2HZ; adjustmentState->timeoutAt = now + RESET_FREQUENCY_2HZ;
@ -373,7 +359,7 @@ void processRcAdjustments(const controlRateConfig_t *controlRateConfig)
continue; continue;
} }
uint8_t channelIndex = NON_AUX_CHANNEL_COUNT + adjustmentState->auxChannelIndex; const uint8_t channelIndex = NON_AUX_CHANNEL_COUNT + adjustmentState->auxChannelIndex;
if (adjustmentState->config->mode == ADJUSTMENT_MODE_STEP) { if (adjustmentState->config->mode == ADJUSTMENT_MODE_STEP) {
int delta; int delta;
@ -392,12 +378,14 @@ void processRcAdjustments(const controlRateConfig_t *controlRateConfig)
} }
// it is legitimate to adjust an otherwise const item here // it is legitimate to adjust an otherwise const item here
applyStepAdjustment((controlRateConfig_t*)controlRateConfig, adjustmentFunction, delta); applyStepAdjustment(controlRateConfig, adjustmentFunction, delta);
#ifdef USE_INFLIGHT_PROFILE_ADJUSTMENT
} else if (adjustmentState->config->mode == ADJUSTMENT_MODE_SELECT) { } else if (adjustmentState->config->mode == ADJUSTMENT_MODE_SELECT) {
uint16_t rangeWidth = ((2100 - 900) / adjustmentState->config->data.selectConfig.switchPositions); const uint16_t rangeWidth = ((2100 - 900) / adjustmentState->config->data.selectConfig.switchPositions);
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);
#endif
} }
MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentIndex); MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentIndex);
} }
@ -411,7 +399,7 @@ void resetAdjustmentStates(void)
void updateAdjustmentStates(void) void updateAdjustmentStates(void)
{ {
for (int index = 0; index < MAX_ADJUSTMENT_RANGE_COUNT; index++) { for (int index = 0; index < MAX_ADJUSTMENT_RANGE_COUNT; index++) {
const adjustmentRange_t *adjustmentRange = adjustmentRanges(index); const adjustmentRange_t * const adjustmentRange = adjustmentRanges(index);
if (isRangeActive(adjustmentRange->auxChannelIndex, &adjustmentRange->range)) { if (isRangeActive(adjustmentRange->auxChannelIndex, &adjustmentRange->range)) {

View file

@ -21,6 +21,8 @@
#include "fc/rc_controls.h" #include "fc/rc_controls.h"
//#define USE_INFLIGHT_PROFILE_ADJUSTMENT - not currently enabled
typedef enum { typedef enum {
ADJUSTMENT_NONE = 0, ADJUSTMENT_NONE = 0,
ADJUSTMENT_RC_RATE, ADJUSTMENT_RC_RATE,
@ -34,7 +36,6 @@ typedef enum {
ADJUSTMENT_YAW_P, ADJUSTMENT_YAW_P,
ADJUSTMENT_YAW_I, ADJUSTMENT_YAW_I,
ADJUSTMENT_YAW_D, ADJUSTMENT_YAW_D,
ADJUSTMENT_RATE_PROFILE,
ADJUSTMENT_PITCH_RATE, ADJUSTMENT_PITCH_RATE,
ADJUSTMENT_ROLL_RATE, ADJUSTMENT_ROLL_RATE,
ADJUSTMENT_PITCH_P, ADJUSTMENT_PITCH_P,
@ -43,10 +44,12 @@ typedef enum {
ADJUSTMENT_ROLL_P, ADJUSTMENT_ROLL_P,
ADJUSTMENT_ROLL_I, ADJUSTMENT_ROLL_I,
ADJUSTMENT_ROLL_D, ADJUSTMENT_ROLL_D,
#ifdef USE_INFLIGHT_PROFILE_ADJUSTMENT
ADJUSTMENT_PROFILE,
#endif
ADJUSTMENT_FUNCTION_COUNT // must be last
} adjustmentFunction_e; } adjustmentFunction_e;
#define ADJUSTMENT_FUNCTION_COUNT 21
typedef enum { typedef enum {
ADJUSTMENT_MODE_STEP, ADJUSTMENT_MODE_STEP,
ADJUSTMENT_MODE_SELECT ADJUSTMENT_MODE_SELECT
@ -104,4 +107,4 @@ PG_DECLARE_ARRAY(adjustmentRange_t, MAX_ADJUSTMENT_RANGE_COUNT, adjustmentRanges
void resetAdjustmentStates(void); void resetAdjustmentStates(void);
void updateAdjustmentStates(void); void updateAdjustmentStates(void);
struct controlRateConfig_s; struct controlRateConfig_s;
void processRcAdjustments(const struct controlRateConfig_s *controlRateConfig); void processRcAdjustments(struct controlRateConfig_s *controlRateConfig);