Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

additional fixes for mixer profile #9363

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/fc/fc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,8 @@ void processRx(timeUs_t currentTimeUs)
} else {
DISABLE_FLIGHT_MODE(MANUAL_MODE);
}
}else{
DISABLE_FLIGHT_MODE(MANUAL_MODE);
}

/* In airmode Iterm should be prevented to grow when Low thottle and Roll + Pitch Centered.
Expand Down
11 changes: 6 additions & 5 deletions src/main/fc/fc_msp_box.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void initActiveBoxIds(void)
//Camstab mode is enabled always
ADD_ACTIVE_BOX(BOXCAMSTAB);

if (STATE(MULTIROTOR)) {
if (STATE(MULTIROTOR) || platformTypeConfigured(PLATFORM_MULTIROTOR) || platformTypeConfigured(PLATFORM_TRICOPTER)) {
if ((sensors(SENSOR_ACC) || sensors(SENSOR_MAG))) {
ADD_ACTIVE_BOX(BOXHEADFREE);
ADD_ACTIVE_BOX(BOXHEADADJ);
Expand Down Expand Up @@ -244,13 +244,13 @@ void initActiveBoxIds(void)
#endif
}

if (STATE(AIRPLANE)) {
if (STATE(AIRPLANE) || platformTypeConfigured(PLATFORM_AIRPLANE)) {
ADD_ACTIVE_BOX(BOXSOARING);
}
}

#ifdef USE_MR_BRAKING_MODE
if (mixerConfig()->platformType == PLATFORM_MULTIROTOR) {
if (mixerConfig()->platformType == PLATFORM_MULTIROTOR || platformTypeConfigured(PLATFORM_MULTIROTOR)) {
ADD_ACTIVE_BOX(BOXBRAKING);
}
#endif
Expand All @@ -259,11 +259,12 @@ void initActiveBoxIds(void)
ADD_ACTIVE_BOX(BOXNAVALTHOLD);
}

if (STATE(AIRPLANE) || STATE(ROVER) || STATE(BOAT)) {
if (STATE(AIRPLANE) || STATE(ROVER) || STATE(BOAT) ||
platformTypeConfigured(PLATFORM_AIRPLANE) || platformTypeConfigured(PLATFORM_ROVER) || platformTypeConfigured(PLATFORM_BOAT)) {
ADD_ACTIVE_BOX(BOXMANUAL);
}

if (STATE(AIRPLANE)) {
if (STATE(AIRPLANE) || platformTypeConfigured(PLATFORM_AIRPLANE)) {
if (!feature(FEATURE_FW_LAUNCH)) {
ADD_ACTIVE_BOX(BOXNAVLAUNCH);
}
Expand Down
12 changes: 11 additions & 1 deletion src/main/flight/mixer_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "fc/runtime_config.h"
#include "fc/settings.h"
#include "fc/rc_modes.h"
#include "fc/cli.h"

#include "programming/logic_condition.h"
#include "navigation/navigation.h"
Expand Down Expand Up @@ -107,6 +108,14 @@ void setMixerProfileAT(void)
mixerProfileAT.transitionTransEndTime = mixerProfileAT.transitionStartTime + (timeMs_t)currentMixerConfig.switchTransitionTimer * 100;
}

bool platformTypeConfigured(flyingPlatformType_e platformType)
{
if (!isModeActivationConditionPresent(BOXMIXERPROFILE)){
return false;
}
return mixerConfigByIndex(nextProfileIndex)->platformType == platformType;
}

bool checkMixerATRequired(mixerProfileATRequest_e required_action)
{
//return false if mixerAT condition is not required or setting is not valid
Expand Down Expand Up @@ -187,8 +196,9 @@ bool checkMixerProfileHotSwitchAvalibility(void)
}

void outputProfileUpdateTask(timeUs_t currentTimeUs)
{
{
UNUSED(currentTimeUs);
if(cliMode) return;
bool mixerAT_inuse = mixerProfileAT.phase != MIXERAT_PHASE_IDLE;
// transition mode input for servo mix and motor mix
if (!FLIGHT_MODE(FAILSAFE_MODE) && (!mixerAT_inuse))
Expand Down
1 change: 1 addition & 0 deletions src/main/flight/mixer_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ static inline const mixerProfile_t* mixerProfiles_CopyArray_by_index(int _index)
#define mixerMotorMixersByIndex(index) (mixerProfiles(index)->MotorMixers)
#define mixerServoMixersByIndex(index) (mixerProfiles(index)->ServoMixers)

bool platformTypeConfigured(flyingPlatformType_e platformType);
bool outputProfileHotSwitch(int profile_index);
bool checkMixerProfileHotSwitchAvalibility(void);
void activateMixerConfig(void);
Expand Down
2 changes: 1 addition & 1 deletion src/main/flight/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ void FAST_CODE pidController(float dT)
canUseFpvCameraMix = false; // FPVANGLEMIX is incompatible with TURN_ASSISTANT
}

if (canUseFpvCameraMix && IS_RC_MODE_ACTIVE(BOXFPVANGLEMIX) && currentControlRateProfile->misc.fpvCamAngleDegrees) {
if (canUseFpvCameraMix && IS_RC_MODE_ACTIVE(BOXFPVANGLEMIX) && currentControlRateProfile->misc.fpvCamAngleDegrees && STATE(MULTIROTOR)) {
pidApplyFpvCameraAngleMix(pidState, currentControlRateProfile->misc.fpvCamAngleDegrees);
}

Expand Down
71 changes: 38 additions & 33 deletions src/main/flight/servos.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,14 @@ void pgResetFn_servoParams(servoParam_t *instance)
int16_t servo[MAX_SUPPORTED_SERVOS];

static uint8_t servoRuleCount = 0;
static servoMixer_t currentServoMixer[MAX_SERVO_RULES];

/*
//Was used to keep track of servo rules in all mixer_profile, In order to Apply mixer speed limit when rules turn off
static servoMixer_t currentServoMixer[MAX_SERVO_RULES*MAX_MIXER_PROFILE_COUNT];
static bool currentServoMixerActivative[MAX_SERVO_RULES*MAX_MIXER_PROFILE_COUNT];// if true, the rule is used by current servo mixer
static bool currentServoMixerActivative[MAX_SERVO_RULES*MAX_MIXER_PROFILE_COUNT]; // if true, the rule is used by current servo mixer
*/

static bool servoOutputEnabled;

static bool mixerUsesServos;
Expand All @@ -115,7 +121,7 @@ static biquadFilter_t servoFilter[MAX_SUPPORTED_SERVOS];
static bool servoFilterIsSet;

static servoMetadata_t servoMetadata[MAX_SUPPORTED_SERVOS];
static rateLimitFilter_t servoSpeedLimitFilter[MAX_SERVO_RULES*MAX_MIXER_PROFILE_COUNT];
static rateLimitFilter_t servoSpeedLimitFilter[MAX_SERVO_RULES];

STATIC_FASTRAM pt1Filter_t rotRateFilter;
STATIC_FASTRAM pt1Filter_t targetRateFilter;
Expand Down Expand Up @@ -161,8 +167,27 @@ void servosInit(void)
}

int getServoCount(void)
{
if (servoRuleCount) {
{
bool servoRuleDetected = false;
minServoIndex = 0;
maxServoIndex = 255;
for (int j = 0; j < MAX_MIXER_PROFILE_COUNT; j++) {
for (int i = 0; i < MAX_SERVO_RULES; i++) {
// check if done
if (mixerServoMixersByIndex(j)[i].rate == 0){
break;
}
if (mixerServoMixersByIndex(j)[i].targetChannel < minServoIndex) {
minServoIndex = mixerServoMixersByIndex(j)[i].targetChannel;
}

if (mixerServoMixersByIndex(j)[i].targetChannel > maxServoIndex) {
maxServoIndex = mixerServoMixersByIndex(j)[i].targetChannel;
}
servoRuleDetected = true;
}
}
if (servoRuleDetected) {
return 1 + maxServoIndex - minServoIndex;
}
else {
Expand All @@ -173,30 +198,17 @@ int getServoCount(void)
void loadCustomServoMixer(void)
{
servoRuleCount = 0;
minServoIndex = 255;
maxServoIndex = 0;
memset(currentServoMixer, 0, sizeof(currentServoMixer));

for (int j = 0; j < MAX_MIXER_PROFILE_COUNT; j++) {
const servoMixer_t* tmp_customServoMixers = &mixerServoMixersByIndex(j)[0];
// load custom mixer into currentServoMixer
for (int i = 0; i < MAX_SERVO_RULES; i++) {
// check if done
if (tmp_customServoMixers[i].rate == 0)
break;

if (tmp_customServoMixers[i].targetChannel < minServoIndex) {
minServoIndex = tmp_customServoMixers[i].targetChannel;
}

if (tmp_customServoMixers[i].targetChannel > maxServoIndex) {
maxServoIndex = tmp_customServoMixers[i].targetChannel;
}

memcpy(&currentServoMixer[servoRuleCount], &tmp_customServoMixers[i], sizeof(servoMixer_t));
currentServoMixerActivative[servoRuleCount] = j==currentMixerProfileIndex;
servoRuleCount++;
// load custom mixer into currentServoMixer
for (int i = 0; i < MAX_SERVO_RULES; i++) {
// check if done
if (customServoMixers(i)->rate == 0){
break;
}
currentServoMixer[servoRuleCount] = *customServoMixers(i);
servoSpeedLimitFilter[servoRuleCount].state = 0;
servoRuleCount++;
}
}

Expand Down Expand Up @@ -353,9 +365,6 @@ void servoMixer(float dT)
inputRaw = 0;
}
#endif
if (!currentServoMixerActivative[i]) {
inputRaw = 0;
}
/*
* Apply mixer speed limit. 1 [one] speed unit is defined as 10us/s:
* 0 = no limiting
Expand All @@ -369,7 +378,7 @@ void servoMixer(float dT)
}

/*
* When not armed, apply servo low position to all outputs that include a throttle or stabilizet throttle in the mix
* When not armed, apply servo low position to all outputs that include a throttle or stabilized throttle in the mix
*/
if (!ARMING_FLAG(ARMED)) {
for (int i = 0; i < servoRuleCount; i++) {
Expand Down Expand Up @@ -438,7 +447,6 @@ void processServoAutotrimMode(void)
if (ARMING_FLAG(ARMED)) {
for (int axis = FD_ROLL; axis <= FD_YAW; axis++) {
for (int i = 0; i < servoRuleCount; i++) {
if (!currentServoMixerActivative[i]) {continue;}
// Reset servo middle accumulator
const uint8_t target = currentServoMixer[i].targetChannel;
const uint8_t source = currentServoMixer[i].inputSource;
Expand All @@ -461,7 +469,6 @@ void processServoAutotrimMode(void)
if (ARMING_FLAG(ARMED)) {
for (int axis = FD_ROLL; axis <= FD_YAW; axis++) {
for (int i = 0; i < servoRuleCount; i++) {
if (!currentServoMixerActivative[i]) {continue;}
const uint8_t target = currentServoMixer[i].targetChannel;
const uint8_t source = currentServoMixer[i].inputSource;
if (source == axis) {
Expand All @@ -474,7 +481,6 @@ void processServoAutotrimMode(void)
if ((millis() - trimStartedAt) > SERVO_AUTOTRIM_TIMER_MS) {
for (int axis = FD_ROLL; axis <= FD_YAW; axis++) {
for (int i = 0; i < servoRuleCount; i++) {
if (!currentServoMixerActivative[i]) {continue;}
const uint8_t target = currentServoMixer[i].targetChannel;
const uint8_t source = currentServoMixer[i].inputSource;
if (source == axis) {
Expand Down Expand Up @@ -508,7 +514,6 @@ void processServoAutotrimMode(void)
if (trimState == AUTOTRIM_SAVE_PENDING) {
for (int axis = FD_ROLL; axis <= FD_YAW; axis++) {
for (int i = 0; i < servoRuleCount; i++) {
if (!currentServoMixerActivative[i]) {continue;}
const uint8_t target = currentServoMixer[i].targetChannel;
const uint8_t source = currentServoMixer[i].inputSource;
if (source == axis) {
Expand Down
Loading