1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-13 11:29:56 +03:00

Allow to override mixer throttle by global function

This commit is contained in:
Pawel Spychalski (DzikuVx) 2019-10-17 15:14:32 +02:00
parent 8ec311e906
commit f689ed1be4
4 changed files with 37 additions and 1 deletions

View file

@ -25,6 +25,7 @@ _Global Functions_ (abbr. GF) are a mechanism allowing to override certain fligh
| 4 | INVERT_ROLL | Inverts ROLL axis input for PID/PIFF controller |
| 5 | INVERT_PITCH | Inverts PITCH axis input for PID/PIFF controller |
| 6 | INVERT_YAW | Inverts YAW axis input for PID/PIFF controller |
| 7 | OVERRIDE_THROTTLE | Override throttle value that is fed to the motors by mixer. Operand is scaled in us. `1000` means throttle cut, `1500` means half throttle |
## Flags
@ -53,4 +54,23 @@ gf 0 1 0 4 0 0 0
gf 1 1 0 5 0 0 0
```
Inverts ROLL and PITCH input when Logic Condition `0` evaluates as `true`. Moving Pitch stick up will cause pitch down (up for rear facing camera). Moving Roll stick right will cause roll left of a quad (right in rear facing camera)
Inverts ROLL and PITCH input when Logic Condition `0` evaluates as `true`. Moving Pitch stick up will cause pitch down (up for rear facing camera). Moving Roll stick right will cause roll left of a quad (right in rear facing camera)
### Cut motors but keep other throttle bindings active
`gf 0 1 0 7 0 1000 0`
Sets Thhrottle output to `0%` when Logic Condition `0` evaluates as `true`
### Set throttle to 50% and keep other throttle bindings active
`gf 0 1 0 7 0 1500 0`
Sets Thhrottle output to about `50%` when Logic Condition `0` evaluates as `true`
### Set throttle control to different RC channel
`gf 0 1 0 7 1 7 0`
If Logic Condition `0` evaluates as `true`, motor throttle control is bound to RC channel 7 instead of throttle channel

View file

@ -113,6 +113,12 @@ void globalFunctionsProcess(int8_t functionId) {
GLOBAL_FUNCTION_FLAG_ENABLE(GLOBAL_FUNCTION_FLAG_OVERRIDE_INVERT_YAW);
}
break;
case GLOBAL_FUNCTION_ACTION_OVERRIDE_THROTTLE:
if (conditionValue) {
globalFunctionValues[GLOBAL_FUNCTION_ACTION_OVERRIDE_THROTTLE] = globalFunctionsStates[functionId].value;
GLOBAL_FUNCTION_FLAG_ENABLE(GLOBAL_FUNCTION_FLAG_OVERRIDE_THROTTLE);
}
break;
}
}
}

View file

@ -36,6 +36,7 @@ typedef enum {
GLOBAL_FUNCTION_ACTION_INVERT_ROLL,
GLOBAL_FUNCTION_ACTION_INVERT_PITCH,
GLOBAL_FUNCTION_ACTION_INVERT_YAW,
GLOBAL_FUNCTION_ACTION_OVERRIDE_THROTTLE,
GLOBAL_FUNCTION_ACTION_LAST
} globalFunctionActions_e;
@ -46,6 +47,7 @@ typedef enum {
GLOBAL_FUNCTION_FLAG_OVERRIDE_INVERT_ROLL = (1 << 3),
GLOBAL_FUNCTION_FLAG_OVERRIDE_INVERT_PITCH = (1 << 4),
GLOBAL_FUNCTION_FLAG_OVERRIDE_INVERT_YAW = (1 << 5),
GLOBAL_FUNCTION_FLAG_OVERRIDE_THROTTLE = (1 << 6),
} globalFunctionFlags_t;
typedef struct globalFunction_s {
@ -69,6 +71,7 @@ extern uint64_t globalFunctionsFlags;
#define GLOBAL_FUNCTION_FLAG(mask) (globalFunctionsFlags & (mask))
PG_DECLARE_ARRAY(globalFunction_t, MAX_GLOBAL_FUNCTIONS, globalFunctions);
extern int globalFunctionValues[GLOBAL_FUNCTION_ACTION_LAST];
void globalFunctionsUpdateTask(timeUs_t currentTimeUs);
float getThrottleScale(float globalThrottleScale);

View file

@ -320,6 +320,13 @@ void FAST_CODE NOINLINE mixTable(const float dT)
static int16_t throttlePrevious = 0; // Store the last throttle direction for deadband transitions
// Find min and max throttle based on condition.
#ifdef USE_GLOBAL_FUNCTIONS
if (GLOBAL_FUNCTION_FLAG(GLOBAL_FUNCTION_FLAG_OVERRIDE_THROTTLE)) {
throttleMin = motorConfig()->minthrottle;
throttleMax = motorConfig()->maxthrottle;
mixerThrottleCommand = constrain(globalFunctionValues[GLOBAL_FUNCTION_ACTION_OVERRIDE_THROTTLE], throttleMin, throttleMax);
} else
#endif
if (feature(FEATURE_3D)) {
if (!ARMING_FLAG(ARMED)) throttlePrevious = PWM_RANGE_MIDDLE; // When disarmed set to mid_rc. It always results in positive direction after arming.