Skip to content

Commit

Permalink
Add mixer override passthrough option (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
gongtao0607 authored Dec 28, 2024
1 parent c06de51 commit 2f5b4e3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/main/flight/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,53 @@ static inline void mixerApplyInputLimit(int index, float value)
}
}

/*
* Check if the mixer index is one of the stabilized axes. If so,
* return the overriden value (directly from RC). Otherwise, return original
* value.
*/
static float mixerGetPassthroughInput(const int index,
const float original_value)
{
float rc = 0;
switch (index) {
case MIXER_IN_STABILIZED_ROLL:
rc = getRcDeflection(ROLL);
break;
case MIXER_IN_STABILIZED_PITCH:
rc = getRcDeflection(PITCH);
break;
case MIXER_IN_STABILIZED_YAW:
// Normally, yaw command is reversed in setpoint.c (unlike other axes).
// As we passthrough RC commands we want to keep the same reversal.
rc = -getRcDeflection(YAW);
break;
case MIXER_IN_STABILIZED_COLLECTIVE:
rc = getRcDeflection(COLLECTIVE);
break;
default:
return original_value;
}

// Scale rc by 120% for easier observing endpoints.
rc *= 1.2f;

if (rc > 0) {
return scaleRangef(rc, 0, 1.0f, 0, mixerInputs(index)->max / 1000.0f);
}
return scaleRangef(rc, 0, -1.0f, 0, mixerInputs(index)->min / 1000.0f);
}

static void mixerSetInput(int index, float value)
{
// Use override or wiggle only if not armed
if (!ARMING_FLAG(ARMED)) {
if (mixer.override[index] >= MIXER_OVERRIDE_MIN && mixer.override[index] <= MIXER_OVERRIDE_MAX) {
value = mixer.override[index] / 1000.0f;
}
else if (mixer.override[index] == MIXER_OVERRIDE_PASSTHROUGH) {
value = mixerGetPassthroughInput(index, value);
}
else if (wiggleActive()) {
if (index >= MIXER_IN_STABILIZED_ROLL && index <= MIXER_IN_STABILIZED_COLLECTIVE)
value = wiggleGetAxis(index - MIXER_IN_STABILIZED_ROLL);
Expand Down
1 change: 1 addition & 0 deletions src/main/flight/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#define MIXER_OVERRIDE_MIN -2500
#define MIXER_OVERRIDE_MAX 2500
#define MIXER_OVERRIDE_OFF (MIXER_OVERRIDE_MAX + 1)
#define MIXER_OVERRIDE_PASSTHROUGH (MIXER_OVERRIDE_MAX + 2)

#define MIXER_SATURATION_TIME 5

Expand Down

0 comments on commit 2f5b4e3

Please sign in to comment.