1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-26 17:55:28 +03:00

mixer_profile draft pr

This commit is contained in:
shota 2022-11-13 23:02:35 +09:00
parent 80a3dee407
commit cbbef19721
12 changed files with 53 additions and 11 deletions

View file

@ -37,7 +37,7 @@
#define PG_SYSTEM_CONFIG 18 #define PG_SYSTEM_CONFIG 18
#define PG_FEATURE_CONFIG 19 #define PG_FEATURE_CONFIG 19
#define PG_MIXER_PROFILE 20 #define PG_MIXER_PROFILE 20
#define PG_SERVO_MIXER 21 // #define PG_SERVO_MIXER 21
#define PG_IMU_CONFIG 22 #define PG_IMU_CONFIG 22
//#define PG_PROFILE_SELECTION 23 //#define PG_PROFILE_SELECTION 23
#define PG_RX_CONFIG 24 #define PG_RX_CONFIG 24

View file

@ -1864,7 +1864,8 @@ static void cliServoMix(char *cmdline)
printServoMix(DUMP_MASTER, customServoMixers(0), NULL); printServoMix(DUMP_MASTER, customServoMixers(0), NULL);
} else if (sl_strncasecmp(cmdline, "reset", 5) == 0) { } else if (sl_strncasecmp(cmdline, "reset", 5) == 0) {
// erase custom mixer // erase custom mixer
pgResetCopy(customServoMixersMutable(0), PG_SERVO_MIXER); // pgResetCopy(customServoMixersMutable(0), PG_SERVO_MIXER);
Reset_servoMixers(customServoMixersMutable(0));
} else { } else {
enum {RULE = 0, TARGET, INPUT, RATE, SPEED, CONDITION, ARGS_COUNT}; enum {RULE = 0, TARGET, INPUT, RATE, SPEED, CONDITION, ARGS_COUNT};
char *ptr = strtok_r(cmdline, " ", &saveptr); char *ptr = strtok_r(cmdline, " ", &saveptr);
@ -3589,12 +3590,14 @@ static void printConfig(const char *cmdline, bool doDiff)
const int currentProfileIndexSave = getConfigProfile(); const int currentProfileIndexSave = getConfigProfile();
const int currentBatteryProfileIndexSave = getConfigBatteryProfile(); const int currentBatteryProfileIndexSave = getConfigBatteryProfile();
const int currentMixerProfileIndexSave = getConfigMixerProfile();
backupConfigs(); backupConfigs();
// reset all configs to defaults to do differencing // reset all configs to defaults to do differencing
resetConfigs(); resetConfigs();
// restore the profile indices, since they should not be reset for proper comparison // restore the profile indices, since they should not be reset for proper comparison
setConfigProfile(currentProfileIndexSave); setConfigProfile(currentProfileIndexSave);
setConfigBatteryProfile(currentBatteryProfileIndexSave); setConfigBatteryProfile(currentBatteryProfileIndexSave);
setConfigMixerProfile(currentMixerProfileIndexSave);
if (checkCommand(options, "showdefaults")) { if (checkCommand(options, "showdefaults")) {
dumpMask = dumpMask | SHOW_DEFAULTS; // add default values as comments for changed values dumpMask = dumpMask | SHOW_DEFAULTS; // add default values as comments for changed values
@ -3622,8 +3625,8 @@ static void printConfig(const char *cmdline, bool doDiff)
#endif #endif
} }
// cliPrintHashLine("resources"); cliPrintHashLine("resources");
//printResource(dumpMask, &defaultConfig); // printResource(dumpMask, &defaultConfig);
// cliPrintHashLine("mixer"); // cliPrintHashLine("mixer");
// cliDumpPrintLinef(dumpMask, primaryMotorMixer_CopyArray[0].throttle == 0.0f, "\r\nmmix reset\r\n"); // cliDumpPrintLinef(dumpMask, primaryMotorMixer_CopyArray[0].throttle == 0.0f, "\r\nmmix reset\r\n");
@ -3716,6 +3719,7 @@ static void printConfig(const char *cmdline, bool doDiff)
// dump all profiles // dump all profiles
const int currentProfileIndexSave = getConfigProfile(); const int currentProfileIndexSave = getConfigProfile();
const int currentBatteryProfileIndexSave = getConfigBatteryProfile(); const int currentBatteryProfileIndexSave = getConfigBatteryProfile();
const int currentMixerProfileIndexSave = getConfigMixerProfile();
for (int ii = 0; ii < MAX_PROFILE_COUNT; ++ii) { for (int ii = 0; ii < MAX_PROFILE_COUNT; ++ii) {
cliDumpProfile(ii, dumpMask); cliDumpProfile(ii, dumpMask);
} }
@ -3727,10 +3731,11 @@ static void printConfig(const char *cmdline, bool doDiff)
} }
setConfigProfile(currentProfileIndexSave); setConfigProfile(currentProfileIndexSave);
setConfigBatteryProfile(currentBatteryProfileIndexSave); setConfigBatteryProfile(currentBatteryProfileIndexSave);
setConfigMixerProfile(currentMixerProfileIndexSave);
cliPrintHashLine("restore original profile selection"); cliPrintHashLine("restore original profile selection");
cliPrintLinef("profile %d", currentProfileIndexSave + 1); cliPrintLinef("profile %d", currentProfileIndexSave + 1);
cliPrintLinef("battery_profile %d", currentBatteryProfileIndexSave + 1); cliPrintLinef("mixer_profile %d", currentMixerProfileIndexSave + 1);
#ifdef USE_CLI_BATCH #ifdef USE_CLI_BATCH
batchModeEnabled = false; batchModeEnabled = false;

View file

@ -321,6 +321,7 @@ void readEEPROM(void)
setConfigProfile(getConfigProfile()); setConfigProfile(getConfigProfile());
setConfigBatteryProfile(getConfigBatteryProfile()); setConfigBatteryProfile(getConfigBatteryProfile());
setConfigMixerProfile(getConfigMixerProfile());
validateAndFixConfig(); validateAndFixConfig();
activateConfig(); activateConfig();

View file

@ -62,12 +62,12 @@ void pgResetFn_mixerProfiles(mixerProfile_t *instance)
// PG_REGISTER_ARRAY(motorMixer_t, MAX_SUPPORTED_MOTORS, primaryMotorMixer, PG_MOTOR_MIXER, 0); // PG_REGISTER_ARRAY(motorMixer_t, MAX_SUPPORTED_MOTORS, primaryMotorMixer, PG_MOTOR_MIXER, 0);
bool OutputProfileHotSwitch(int profile_index) bool OutputProfileHotSwitch(int profile_index)
{ {
// does not work with timerHardwareOverride // does not work with timerHardwareOverride
LOG_INFO(PWM, "OutputProfileHotSwitch"); LOG_INFO(PWM, "OutputProfileHotSwitch");
//do not allow switching between multi rotor and non multi rotor //do not allow switching between multi rotor and non multi rotor
#ifdef ENABLE_MCFW_MIXER_PROFILE_HOTSWAP #ifdef ENABLE_MIXER_PROFILE_MCFW_HOTSWAP
bool MCFW_hotswap_unavailable = false; bool MCFW_hotswap_unavailable = false;
#else #else
bool MCFW_hotswap_unavailable = true; bool MCFW_hotswap_unavailable = true;
@ -88,6 +88,7 @@ bool OutputProfileHotSwitch(int profile_index)
LOG_INFO(PWM, "navModesEnabled"); LOG_INFO(PWM, "navModesEnabled");
return false; return false;
} }
//TODO add check of each motor/servo is mapped before and after the switch
if (!setConfigMixerProfile(profile_index)){ if (!setConfigMixerProfile(profile_index)){
LOG_INFO(PWM, "failed to set config"); LOG_INFO(PWM, "failed to set config");
@ -104,7 +105,7 @@ bool OutputProfileHotSwitch(int profile_index)
pidInit(); pidInit();
pidInitFilters(); pidInitFilters();
schedulePidGainsUpdate(); schedulePidGainsUpdate();
navigationInit(); // navigationInit(); //may need to initilize FW_HEADING_USE_YAW on rover or boat
} }
return true; return true;
} }

View file

@ -30,5 +30,7 @@ static inline const mixerProfile_t* mixerProfiles_CopyArray_by_index(int _index)
#define customServoMixers_CopyArray() (mixerProfiles_CopyArray_by_index(systemConfig()->current_mixer_profile_index)->ServoMixers) #define customServoMixers_CopyArray() (mixerProfiles_CopyArray_by_index(systemConfig()->current_mixer_profile_index)->ServoMixers)
#define mixerConfigByIndex(index) (&(mixerProfiles(index)->mixer_config)) #define mixerConfigByIndex(index) (&(mixerProfiles(index)->mixer_config))
#define mixerMotorMixersByIndex(index) (&(mixerProfiles(index)->MotorMixers))
#define mixerServoMixersByIndex(index) (&(mixerProfiles(index)->ServoMixers))
bool OutputProfileHotSwitch(int profile_index); bool OutputProfileHotSwitch(int profile_index);

View file

@ -87,6 +87,22 @@ PG_RESET_TEMPLATE(servoConfig_t, servoConfig,
// } // }
// } // }
void Reset_servoMixers(servoMixer_t *instance)
{
for (int i = 0; i < MAX_SERVO_RULES; i++)
{
RESET_CONFIG(servoMixer_t, &instance[i],
.targetChannel = 0,
.inputSource = 0,
.rate = 0,
.speed = 0
#ifdef USE_PROGRAMMING_FRAMEWORK
,.conditionId = -1
#endif
);
}
}
PG_REGISTER_ARRAY_WITH_RESET_FN(servoParam_t, MAX_SUPPORTED_SERVOS, servoParams, PG_SERVO_PARAMS, 3); PG_REGISTER_ARRAY_WITH_RESET_FN(servoParam_t, MAX_SUPPORTED_SERVOS, servoParams, PG_SERVO_PARAMS, 3);
void pgResetFn_servoParams(servoParam_t *instance) void pgResetFn_servoParams(servoParam_t *instance)

View file

@ -151,6 +151,7 @@ typedef struct servoMetadata_s {
extern int16_t servo[MAX_SUPPORTED_SERVOS]; extern int16_t servo[MAX_SUPPORTED_SERVOS];
void Reset_servoMixers(servoMixer_t* instance);
bool isServoOutputEnabled(void); bool isServoOutputEnabled(void);
void setServoOutputEnabled(bool flag); void setServoOutputEnabled(bool flag);
bool isMixerUsingServos(void); bool isMixerUsingServos(void);

View file

@ -23,7 +23,7 @@
timerHardware_t timerHardware[] = { timerHardware_t timerHardware[] = {
DEF_TIM(TIM9, CH2, PA3, TIM_USE_PPM, 0, 0), // PPM DEF_TIM(TIM9, CH2, PA3, TIM_USE_PPM, 0, 0), // PPM
#ifdef MATEKF405VTOL #ifdef MATEKF405VTOL//development purpose, TODO: remove it in the release
DEF_TIM(TIM3, CH1, PC6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1 DEF_TIM(TIM3, CH1, PC6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1
DEF_TIM(TIM8, CH2, PC7, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 1), // S2 UP(2,1) DEF_TIM(TIM8, CH2, PC7, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 1), // S2 UP(2,1)
DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 1), // S3 UP(2,1) DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 1), // S3 UP(2,1)

View file

@ -197,5 +197,5 @@
#define MAX_PWM_OUTPUT_PORTS 6 #define MAX_PWM_OUTPUT_PORTS 6
#ifdef MATEKF405VTOL #ifdef MATEKF405VTOL
#define ENABLE_MCFW_MIXER_PROFILE_HOTSWAP #define ENABLE_MIXER_PROFILE_MCFW_HOTSWAP
#endif #endif

View file

@ -1,2 +1,3 @@
target_stm32f405xg(MATEKF405TE) target_stm32f405xg(MATEKF405TE)
target_stm32f405xg(MATEKF405TE_SD) target_stm32f405xg(MATEKF405TE_SD)
target_stm32f405xg(MATEKF405TE_SD_VTOL)

View file

@ -25,6 +25,18 @@
#include "drivers/timer_def_stm32f4xx.h" #include "drivers/timer_def_stm32f4xx.h"
timerHardware_t timerHardware[] = { timerHardware_t timerHardware[] = {
#ifdef MATEKF405TE_SD_VTOL
//using d-shot on motors seems to have problems on s3,maybe dma related,maybe my board problem
DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1 D(2,7,7) UP217
DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S2 D(2,2,0) UP217
DEF_TIM(TIM1, CH3N, PB15, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S3 D(2,6,0) UP256
DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 1), // S4 D(2,1,6) UP256
DEF_TIM(TIM2, CH4, PB11, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S5 D(1,7,3) UP173
DEF_TIM(TIM2, CH3, PB10, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S6 D(1,1,3) UP173
DEF_TIM(TIM2, CH2, PB3, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S7 D(1,6,3) UP173
DEF_TIM(TIM2, CH1, PA15, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S8 D(1,5,3) UP173
#else
DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1 D(2,7,7) UP217 DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1 D(2,7,7) UP217
DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S2 D(2,2,0) UP217 DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S2 D(2,2,0) UP217
DEF_TIM(TIM1, CH3N, PB15, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S3 D(2,6,0) UP256 DEF_TIM(TIM1, CH3N, PB15, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S3 D(2,6,0) UP256
@ -34,7 +46,7 @@ timerHardware_t timerHardware[] = {
DEF_TIM(TIM2, CH3, PB10, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S6 D(1,1,3) UP173 DEF_TIM(TIM2, CH3, PB10, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S6 D(1,1,3) UP173
DEF_TIM(TIM2, CH2, PB3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S7 D(1,6,3) UP173 DEF_TIM(TIM2, CH2, PB3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S7 D(1,6,3) UP173
DEF_TIM(TIM2, CH1, PA15, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S8 D(1,5,3) UP173 DEF_TIM(TIM2, CH1, PA15, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S8 D(1,5,3) UP173
#endif
DEF_TIM(TIM12, CH1, PB14, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S9 DMA NONE DEF_TIM(TIM12, CH1, PB14, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S9 DMA NONE
DEF_TIM(TIM13, CH1, PA6, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S10 DMA NONE DEF_TIM(TIM13, CH1, PA6, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S10 DMA NONE
DEF_TIM(TIM4, CH1, PB6, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S11 D(1,0,2) DEF_TIM(TIM4, CH1, PB6, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S11 D(1,0,2)

View file

@ -180,3 +180,6 @@
#define USE_DSHOT #define USE_DSHOT
#define USE_ESC_SENSOR #define USE_ESC_SENSOR
#ifdef MATEKF405TE_SD_VTOL
#define ENABLE_MIXER_PROFILE_MCFW_HOTSWAP
#endif