mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 15:25:36 +03:00
Added DYNAMIC mixer
This commit is contained in:
parent
75da17a00e
commit
4a916af6a9
5 changed files with 28 additions and 11 deletions
|
@ -501,6 +501,10 @@ static const char * const lookupTableOsdLogoOnArming[] = {
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static const char* const lookupTableMixerType[] = {
|
||||||
|
"LEGACY", "LINEAR", "DYNAMIC",
|
||||||
|
};
|
||||||
|
|
||||||
#define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) }
|
#define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) }
|
||||||
|
|
||||||
const lookupTableEntry_t lookupTables[] = {
|
const lookupTableEntry_t lookupTables[] = {
|
||||||
|
@ -622,6 +626,7 @@ const lookupTableEntry_t lookupTables[] = {
|
||||||
#ifdef USE_OSD
|
#ifdef USE_OSD
|
||||||
LOOKUP_TABLE_ENTRY(lookupTableOsdLogoOnArming),
|
LOOKUP_TABLE_ENTRY(lookupTableOsdLogoOnArming),
|
||||||
#endif
|
#endif
|
||||||
|
LOOKUP_TABLE_ENTRY(lookupTableMixerType),
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef LOOKUP_TABLE_ENTRY
|
#undef LOOKUP_TABLE_ENTRY
|
||||||
|
@ -907,7 +912,7 @@ const clivalue_t valueTable[] = {
|
||||||
|
|
||||||
// PG_MIXER_CONFIG
|
// PG_MIXER_CONFIG
|
||||||
{ "yaw_motors_reversed", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MIXER_CONFIG, offsetof(mixerConfig_t, yaw_motors_reversed) },
|
{ "yaw_motors_reversed", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MIXER_CONFIG, offsetof(mixerConfig_t, yaw_motors_reversed) },
|
||||||
{ "linear_mixer", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MIXER_CONFIG, offsetof(mixerConfig_t, linear_mixer) },
|
{ "mixer_type", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_MIXER_TYPE }, PG_MIXER_CONFIG, offsetof(mixerConfig_t, mixer_type) },
|
||||||
{ "crashflip_motor_percent", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_MIXER_CONFIG, offsetof(mixerConfig_t, crashflip_motor_percent) },
|
{ "crashflip_motor_percent", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_MIXER_CONFIG, offsetof(mixerConfig_t, crashflip_motor_percent) },
|
||||||
{ "crashflip_expo", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_MIXER_CONFIG, offsetof(mixerConfig_t, crashflip_expo) },
|
{ "crashflip_expo", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_MIXER_CONFIG, offsetof(mixerConfig_t, crashflip_expo) },
|
||||||
|
|
||||||
|
|
|
@ -141,6 +141,7 @@ typedef enum {
|
||||||
#ifdef USE_OSD
|
#ifdef USE_OSD
|
||||||
TABLE_OSD_LOGO_ON_ARMING,
|
TABLE_OSD_LOGO_ON_ARMING,
|
||||||
#endif
|
#endif
|
||||||
|
TABLE_MIXER_TYPE,
|
||||||
|
|
||||||
LOOKUP_TABLE_COUNT
|
LOOKUP_TABLE_COUNT
|
||||||
} lookupTableIndex_e;
|
} lookupTableIndex_e;
|
||||||
|
|
|
@ -425,19 +425,23 @@ static void updateDynLpfCutoffs(timeUs_t currentTimeUs, float throttle)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void applyLinearMixerAdjustment(float *motorMix, float motorMixRange, bool airmodeEnabled) {
|
static void applyMixerAdjustmentLinear(float *motorMix, const bool airmodeEnabled) {
|
||||||
float motorMixNormalizationFactor = motorMixRange > 1.0f ? motorMixRange : 1.0f;
|
const float motorMixNormalizationFactor = motorMixRange > 1.0f ? motorMixRange : 1.0f;
|
||||||
float motorMixDelta = 0.5f * motorMixRange;
|
const float motorMixDelta = 0.5f * motorMixRange;
|
||||||
|
|
||||||
for (int i = 0; i < mixerRuntime.motorCount; ++i) {
|
for (int i = 0; i < mixerRuntime.motorCount; ++i) {
|
||||||
if (airmodeEnabled || throttle > 0.5f) {
|
if (airmodeEnabled || throttle > 0.5f) {
|
||||||
motorMix[i] = scaleRangef(throttle, 0.0f, 1.0f, motorMix[i] + motorMixDelta, motorMix[i] - motorMixDelta);
|
if (mixerConfig()->mixer_type == MIXER_LINEAR) {
|
||||||
|
motorMix[i] = scaleRangef(throttle, 0.0f, 1.0f, motorMix[i] + motorMixDelta, motorMix[i] - motorMixDelta);
|
||||||
|
} else {
|
||||||
|
motorMix[i] = scaleRangef(throttle, 0.0f, 1.0f, motorMix[i] + ABS(motorMix[i]), motorMix[i] - ABS(motorMix[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
motorMix[i] /= motorMixNormalizationFactor;
|
motorMix[i] /= motorMixNormalizationFactor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void applyMixerAdjustment(float *motorMix, float motorMixMin, float motorMixMax, float motorMixRange, bool airmodeEnabled) {
|
static void applyMixerAdjustment(float *motorMix, const float motorMixMin, const float motorMixMax, const bool airmodeEnabled) {
|
||||||
#ifdef USE_AIRMODE_LPF
|
#ifdef USE_AIRMODE_LPF
|
||||||
const float unadjustedThrottle = throttle;
|
const float unadjustedThrottle = throttle;
|
||||||
throttle += pidGetAirmodeThrottleOffset();
|
throttle += pidGetAirmodeThrottleOffset();
|
||||||
|
@ -591,10 +595,10 @@ FAST_CODE_NOINLINE void mixTable(timeUs_t currentTimeUs)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
motorMixRange = motorMixMax - motorMixMin;
|
motorMixRange = motorMixMax - motorMixMin;
|
||||||
if (mixerConfig()->linear_mixer) {
|
if (mixerConfig()->mixer_type > MIXER_LEGACY) {
|
||||||
applyLinearMixerAdjustment(motorMix, motorMixRange, airmodeEnabled);
|
applyMixerAdjustmentLinear(motorMix, airmodeEnabled);
|
||||||
} else {
|
} else {
|
||||||
applyMixerAdjustment(motorMix, motorMixMin, motorMixMax, motorMixRange, airmodeEnabled);
|
applyMixerAdjustment(motorMix, motorMixMin, motorMixMax, airmodeEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (featureIsEnabled(FEATURE_MOTOR_STOP)
|
if (featureIsEnabled(FEATURE_MOTOR_STOP)
|
||||||
|
|
|
@ -60,6 +60,13 @@ typedef enum mixerMode
|
||||||
MIXER_QUADX_1234 = 26
|
MIXER_QUADX_1234 = 26
|
||||||
} mixerMode_e;
|
} mixerMode_e;
|
||||||
|
|
||||||
|
typedef enum mixerType
|
||||||
|
{
|
||||||
|
MIXER_LEGACY = 0,
|
||||||
|
MIXER_LINEAR = 1,
|
||||||
|
MIXER_DYNAMIC = 2,
|
||||||
|
} mixerType_e;
|
||||||
|
|
||||||
// Custom mixer data per motor
|
// Custom mixer data per motor
|
||||||
typedef struct motorMixer_s {
|
typedef struct motorMixer_s {
|
||||||
float throttle;
|
float throttle;
|
||||||
|
@ -82,7 +89,7 @@ typedef struct mixerConfig_s {
|
||||||
bool yaw_motors_reversed;
|
bool yaw_motors_reversed;
|
||||||
uint8_t crashflip_motor_percent;
|
uint8_t crashflip_motor_percent;
|
||||||
uint8_t crashflip_expo;
|
uint8_t crashflip_expo;
|
||||||
uint8_t linear_mixer;
|
uint8_t mixer_type;
|
||||||
} mixerConfig_t;
|
} mixerConfig_t;
|
||||||
|
|
||||||
PG_DECLARE(mixerConfig_t, mixerConfig);
|
PG_DECLARE(mixerConfig_t, mixerConfig);
|
||||||
|
|
|
@ -51,7 +51,7 @@ PG_RESET_TEMPLATE(mixerConfig_t, mixerConfig,
|
||||||
.yaw_motors_reversed = false,
|
.yaw_motors_reversed = false,
|
||||||
.crashflip_motor_percent = 0,
|
.crashflip_motor_percent = 0,
|
||||||
.crashflip_expo = 35,
|
.crashflip_expo = 35,
|
||||||
.linear_mixer = false,
|
.mixer_type = MIXER_LEGACY,
|
||||||
);
|
);
|
||||||
|
|
||||||
PG_REGISTER_ARRAY(motorMixer_t, MAX_SUPPORTED_MOTORS, customMotorMixer, PG_MOTOR_MIXER, 0);
|
PG_REGISTER_ARRAY(motorMixer_t, MAX_SUPPORTED_MOTORS, customMotorMixer, PG_MOTOR_MIXER, 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue