1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 21:05:35 +03:00

Add hooks for triflight

This commit is contained in:
Martin Budden 2017-12-31 15:40:35 +00:00
parent b71fe232c3
commit ccb49583e9
9 changed files with 175 additions and 10 deletions

View file

@ -49,6 +49,7 @@
#include "flight/failsafe.h"
#include "flight/imu.h"
#include "flight/mixer.h"
#include "flight/mixer_tricopter.h"
#include "flight/pid.h"
#include "rx/rx.h"
@ -106,8 +107,6 @@ PG_REGISTER_ARRAY(motorMixer_t, MAX_SUPPORTED_MOTORS, customMotorMixer, PG_MOTOR
#define PWM_RANGE_MID 1500
#define TRICOPTER_ERROR_RATE_YAW_SATURATED 75 // rate at which tricopter yaw axis becomes saturated, determined experimentally by TriFlight
static FAST_RAM uint8_t motorCount;
static FAST_RAM float motorMixRange;
@ -341,10 +340,19 @@ bool areMotorsRunning(void)
return motorsRunning;
}
bool mixerIsTricopter(void)
{
#ifdef USE_SERVOS
return (currentMixerMode == MIXER_TRI || currentMixerMode == MIXER_CUSTOM_TRI);
#else
return false;
#endif
}
bool mixerIsOutputSaturated(int axis, float errorRate)
{
if (axis == FD_YAW && (currentMixerMode == MIXER_TRI || currentMixerMode == MIXER_CUSTOM_TRI)) {
return errorRate > TRICOPTER_ERROR_RATE_YAW_SATURATED;
if (axis == FD_YAW && mixerIsTricopter()) {
return mixerTricopterIsServoSaturated(errorRate);
} else {
return motorMixRange >= 1.0f;
}
@ -404,6 +412,9 @@ void mixerInit(mixerMode_e mixerMode)
currentMixerMode = mixerMode;
initEscEndpoints();
if (mixerIsTricopter()) {
mixerTricopterInit();
}
}
#ifndef USE_QUAD_MIXER_ONLY
@ -641,8 +652,11 @@ static void applyMixToMotors(float motorMix[MAX_SUPPORTED_MOTORS])
{
// Now add in the desired throttle, but keep in a range that doesn't clip adjusted
// roll/pitch/yaw. This could move throttle down, but also up for those low throttle flips.
for (uint32_t i = 0; i < motorCount; i++) {
for (int i = 0; i < motorCount; i++) {
float motorOutput = motorOutputMin + (motorOutputRange * (motorOutputMixSign * motorMix[i] + throttle * currentMixer[i].throttle));
if (mixerIsTricopter()) {
motorOutput += mixerTricopterMotorCorrection(i);
}
if (failsafeIsActive()) {
if (isMotorProtocolDshot()) {
motorOutput = (motorOutput < motorRangeMin) ? disarmMotorOutput : motorOutput; // Prevent getting into special reserved range