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

mixer profile switching by cli

This commit is contained in:
shota 2022-11-06 02:28:52 +09:00
parent c398c526ec
commit 0b247d9bfc
12 changed files with 123 additions and 19 deletions

View file

@ -40,6 +40,7 @@
#include "fc/runtime_config.h"
#include "fc/settings.h"
#include "fc/config.h"
static uint8_t currentMotorMixerIndex = 0;
static uint8_t tmpcurrentMotorMixerIndex = 1;

View file

@ -36,7 +36,7 @@
//#define PG_TRANSPONDER_CONFIG 17
#define PG_SYSTEM_CONFIG 18
#define PG_FEATURE_CONFIG 19
#define PG_MIXER_CONFIG 20
#define PG_MIXER_PROFILE 20
#define PG_SERVO_MIXER 21
#define PG_IMU_CONFIG 22
//#define PG_PROFILE_SELECTION 23

View file

@ -3049,6 +3049,33 @@ static void cliDumpBatteryProfile(uint8_t profileIndex, uint8_t dumpMask)
dumpAllValues(BATTERY_CONFIG_VALUE, dumpMask);
}
static void cliMixerProfile(char *cmdline)
{
// CLI profile index is 1-based
if (isEmpty(cmdline)) {
cliPrintLinef("mixer_profile %d", getConfigMixerProfile() + 1);
return;
} else {
const int i = fastA2I(cmdline) - 1;
if (i >= 0 && i < MAX_PROFILE_COUNT) {
setConfigMixerProfileAndWriteEEPROM(i);
cliMixerProfile("");
}
}
}
static void cliDumpMixerProfile(uint8_t profileIndex, uint8_t dumpMask)
{
if (profileIndex >= MAX_MIXER_PROFILE_COUNT) {
// Faulty values
return;
}
setConfigMixerProfile(profileIndex);
cliPrintHashLine("mixer_profile");
cliPrintLinef("mixer_profile %d\r\n", getConfigMixerProfile() + 1);
dumpAllValues(MIXER_CONFIG_VALUE, dumpMask);
}
#ifdef USE_CLI_BATCH
static void cliPrintCommandBatchWarning(const char *warning)
{
@ -3861,6 +3888,8 @@ const clicmd_t cmdTable[] = {
"[<index>]", cliProfile),
CLI_COMMAND_DEF("battery_profile", "change battery profile",
"[<index>]", cliBatteryProfile),
CLI_COMMAND_DEF("mixer_profile", "change mixer profile",
"[<index>]", cliMixerProfile),
CLI_COMMAND_DEF("resource", "view currently used resources", NULL, cliResource),
CLI_COMMAND_DEF("rxrange", "configure rx channel ranges", NULL, cliRxRange),
#if defined(USE_SAFE_HOME)

View file

@ -107,6 +107,7 @@ PG_REGISTER_WITH_RESET_TEMPLATE(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG,
PG_RESET_TEMPLATE(systemConfig_t, systemConfig,
.current_profile_index = 0,
.current_battery_profile_index = 0,
.current_mixer_profile_index = 0,
.debug_mode = SETTING_DEBUG_MODE_DEFAULT,
#ifdef USE_DEV_TOOLS
.groundTestMode = SETTING_GROUND_TEST_MODE_DEFAULT, // disables motors, set heading trusted for FW (for dev use)
@ -417,6 +418,35 @@ void setConfigBatteryProfileAndWriteEEPROM(uint8_t profileIndex)
beeperConfirmationBeeps(profileIndex + 1);
}
uint8_t getConfigMixerProfile(void)
{
return systemConfig()->current_mixer_profile_index;
}
bool setConfigMixerProfile(uint8_t profileIndex)
{
bool ret = true; // return true if current_mixer_profile_index has changed
if (systemConfig()->current_mixer_profile_index == profileIndex) {
ret = false;
}
if (profileIndex >= MAX_MIXER_PROFILE_COUNT) {// sanity check
profileIndex = 0;
}
systemConfigMutable()->current_mixer_profile_index = profileIndex;
// setMixerProfile(profileIndex);
return ret;
}
void setConfigMixerProfileAndWriteEEPROM(uint8_t profileIndex)
{
if (setConfigMixerProfile(profileIndex)) {
// profile has changed, so ensure current values saved before new profile is loaded
writeEEPROM();
readEEPROM();
}
beeperConfirmationBeeps(profileIndex + 1);
}
void setGyroCalibrationAndWriteEEPROM(int16_t getGyroZero[XYZ_AXIS_COUNT]) {
gyroConfigMutable()->gyro_zero_cal[X] = getGyroZero[X];
gyroConfigMutable()->gyro_zero_cal[Y] = getGyroZero[Y];

View file

@ -69,6 +69,7 @@ typedef enum {
typedef struct systemConfig_s {
uint8_t current_profile_index;
uint8_t current_battery_profile_index;
uint8_t current_mixer_profile_index;
uint8_t debug_mode;
#ifdef USE_DEV_TOOLS
bool groundTestMode; // Disables motor ouput, sets heading trusted on FW (for dev use)
@ -135,6 +136,10 @@ uint8_t getConfigBatteryProfile(void);
bool setConfigBatteryProfile(uint8_t profileIndex);
void setConfigBatteryProfileAndWriteEEPROM(uint8_t profileIndex);
uint8_t getConfigMixerProfile(void);
bool setConfigMixerProfile(uint8_t profileIndex);
void setConfigMixerProfileAndWriteEEPROM(uint8_t profileIndex);
void setGyroCalibrationAndWriteEEPROM(int16_t getGyroZero[XYZ_AXIS_COUNT]);
void setGravityCalibrationAndWriteEEPROM(float getGravity);

View file

@ -3126,8 +3126,13 @@ static bool mspSettingInfoCommand(sbuf_t *dst, sbuf_t *src)
sbufWriteU8(dst, getConfigBatteryProfile());
sbufWriteU8(dst, MAX_BATTERY_PROFILE_COUNT);
break;
case MIXER_CONFIG_VALUE:
sbufWriteU8(dst, getConfigMixerProfile());
sbufWriteU8(dst, MAX_MIXER_PROFILE_COUNT);
break;
}
// If the setting uses a table, send each possible string (null terminated)
if (SETTING_MODE(setting) == MODE_LOOKUP) {
for (int ii = (int)min; ii <= (int)max; ii++) {

View file

@ -239,6 +239,8 @@ static uint16_t getValueOffset(const setting_t *value)
return value->offset + sizeof(controlRateConfig_t) * getConfigProfile();
case BATTERY_CONFIG_VALUE:
return value->offset + sizeof(batteryProfile_t) * getConfigBatteryProfile();
case MIXER_CONFIG_VALUE:
return value->offset + sizeof(batteryProfile_t) * getConfigBatteryProfile();
}
return 0;
}

View file

@ -15,7 +15,7 @@ typedef struct lookupTableEntry_s {
#define SETTING_TYPE_OFFSET 0
#define SETTING_SECTION_OFFSET 4
#define SETTING_MODE_OFFSET 6
#define SETTING_MODE_OFFSET 7
typedef enum {
// value type, bits 0-3
@ -29,15 +29,16 @@ typedef enum {
} setting_type_e;
typedef enum {
// value section, bits 4-5
// value section, bits 4-6
MASTER_VALUE = (0 << SETTING_SECTION_OFFSET),
PROFILE_VALUE = (1 << SETTING_SECTION_OFFSET),
CONTROL_RATE_VALUE = (2 << SETTING_SECTION_OFFSET), // 0x20
BATTERY_CONFIG_VALUE = (3 << SETTING_SECTION_OFFSET),
MIXER_CONFIG_VALUE = (4 << SETTING_SECTION_OFFSET),
} setting_section_e;
typedef enum {
// value mode, bits 6-7
// value mode, bits 7
MODE_DIRECT = (0 << SETTING_MODE_OFFSET),
MODE_LOOKUP = (1 << SETTING_MODE_OFFSET), // 0x40
} setting_mode_e;

View file

@ -206,6 +206,7 @@ constants:
MAX_CONTROL_RATE_PROFILE_COUNT: 3
MAX_BATTERY_PROFILE_COUNT: 3
MAX_MIXER_PROFILE_COUNT: 2
groups:
@ -1145,8 +1146,8 @@ groups:
field: powerLimits.burstPowerFalldownTime
max: 3000
- name: PG_MIXER_CONFIG
type: mixerConfig_t
- name: PG_MIXER_PROFILE
type: mixerProfile_t
members:
- name: motor_direction_inverted
description: "Use if you need to inverse yaw motor direction."

View file

@ -33,6 +33,7 @@ FILE_COMPILE_FOR_SPEED
#include "config/feature.h"
#include "config/parameter_group.h"
#include "config/parameter_group_ids.h"
#include "config/config_reset.h"
#include "drivers/pwm_output.h"
#include "drivers/pwm_mapping.h"
@ -82,16 +83,34 @@ PG_RESET_TEMPLATE(reversibleMotorsConfig_t, reversibleMotorsConfig,
.deadband_high = SETTING_3D_DEADBAND_HIGH_DEFAULT,
.neutral = SETTING_3D_NEUTRAL_DEFAULT
);
PG_REGISTER_ARRAY_WITH_RESET_FN(mixerProfile_t, MAX_MIXER_PROFILE_COUNT, mixerProfiles, PG_MIXER_PROFILE, 1);
PG_REGISTER_WITH_RESET_TEMPLATE(mixerConfig_t, mixerConfig, PG_MIXER_CONFIG, 5);
PG_RESET_TEMPLATE(mixerConfig_t, mixerConfig,
void pgResetFn_mixerProfiles(mixerProfile_t *instance)
{
for (int i = 0; i < MAX_MIXER_PROFILE_COUNT; i++) {
RESET_CONFIG(mixerProfile_t, &instance[i],
.motorDirectionInverted = SETTING_MOTOR_DIRECTION_INVERTED_DEFAULT,
.platformType = SETTING_PLATFORM_TYPE_DEFAULT,
.hasFlaps = SETTING_HAS_FLAPS_DEFAULT,
.appliedMixerPreset = SETTING_MODEL_PREVIEW_TYPE_DEFAULT, //This flag is not available in CLI and used by Configurator only
.outputMode = SETTING_OUTPUT_MODE_DEFAULT,
);
);
motorMixer_t tmp_mixer = {.throttle=0,.roll=0,.pitch=0,.yaw=0};
for (int j = 0; j < MAX_SUPPORTED_MOTORS; j++) {
instance->MotorMixer[j] = tmp_mixer;
}
}
}
// PG_REGISTER_WITH_RESET_TEMPLATE(mixerConfig_t, mixerConfig, PG_MIXER_PROFILE, 5);
// PG_RESET_TEMPLATE(mixerConfig_t, mixerConfig,
// .motorDirectionInverted = SETTING_MOTOR_DIRECTION_INVERTED_DEFAULT,
// .platformType = SETTING_PLATFORM_TYPE_DEFAULT,
// .hasFlaps = SETTING_HAS_FLAPS_DEFAULT,
// .appliedMixerPreset = SETTING_MODEL_PREVIEW_TYPE_DEFAULT, //This flag is not available in CLI and used by Configurator only
// .outputMode = SETTING_OUTPUT_MODE_DEFAULT,
// );
PG_REGISTER_WITH_RESET_TEMPLATE(motorConfig_t, motorConfig, PG_MOTOR_CONFIG, 9);

View file

@ -19,12 +19,17 @@
#include "config/parameter_group.h"
#ifndef MAX_MIXER_PROFILE_COUNT
#define MAX_MIXER_PROFILE_COUNT 2
#endif
#if defined(TARGET_MOTOR_COUNT)
#define MAX_SUPPORTED_MOTORS TARGET_MOTOR_COUNT
#else
#define MAX_SUPPORTED_MOTORS 12
#endif
// Digital protocol has fixed values
#define DSHOT_DISARM_COMMAND 0
#define DSHOT_MIN_THROTTLE 48
@ -64,15 +69,21 @@ typedef struct motorMixer_s {
PG_DECLARE_ARRAY(motorMixer_t, MAX_SUPPORTED_MOTORS, primaryMotorMixer);
typedef struct mixerConfig_s {
typedef struct mixerProfile_s {
int8_t motorDirectionInverted;
uint8_t platformType;
bool hasFlaps;
int16_t appliedMixerPreset;
uint8_t outputMode;
} mixerConfig_t;
motorMixer_t MotorMixer[MAX_SUPPORTED_MOTORS];
} mixerProfile_t;
PG_DECLARE(mixerConfig_t, mixerConfig);
PG_DECLARE_ARRAY(mixerProfile_t, MAX_MIXER_PROFILE_COUNT, mixerProfiles);
#define mixerConfig() mixerProfiles(systemConfig()->current_mixer_profile_index)
#define mixerConfigMutable() ((mixerProfile_t *)mixerConfig())
#define primaryMotorMixer(_index) (&((mixerConfig()->MotorMixer)[_index]))
#define primaryMotorMixerMutable(_index) ((motorMixer_t *)primaryMotorMixer(_index))
extern motorMixer_t primaryMotorMixer_CopyArray[12];
typedef struct reversibleMotorsConfig_s {
uint16_t deadband_low; // min 3d value

View file

@ -144,7 +144,7 @@ TEST_F(ChannelForwardingTest, TestForwardAuxChannelsToServosWithLessRemainingSer
class BasicMixerIntegrationTest : public ::testing::Test {
protected:
mixerConfig_t mixerConfig;
mixerProfile_t mixerConfig;
rxConfig_t rxConfig;
escAndServoConfig_t escAndServoConfig;
servoParam_t servoConf[MAX_SUPPORTED_SERVOS];