Skip to content
Open
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"platform.h": "c",
"timer.h": "c",
"bus.h": "c",
"io.h": "c"
"io.h": "c",
"fc_core.h": "c"
},
"editor.tabSize": 4,
"editor.insertSpaces": true,
Expand Down
2 changes: 1 addition & 1 deletion docs/MixerProfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ TailSitter is supported by add a 90deg offset to the board alignment. Set the bo
- motor_direction_inverted, and more·······
- **Motor Mixing (mmix)**
- **Servo Mixing (smix)**
- **PID Profile**
- **Control Profile**
- PIDs for Roll, Pitch, Yaw
- PIDs for Navigation Modes
- TPA (Throttle PID Attenuation) Settings
Expand Down
24 changes: 12 additions & 12 deletions docs/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,16 +582,6 @@ Blackbox logging rate numerator. Use num/denom settings to decide if a frame sho

---

### controlrate_profile

Control rate profile to switch to when the battery profile is selected, 0 to disable and keep the currently selected control rate profile

| Default | Min | Max |
| --- | --- | --- |
| 0 | 0 | 3 |

---

### cruise_power

Power draw at cruise throttle used for remaining flight time/distance estimation in 0.01W unit
Expand Down Expand Up @@ -2992,9 +2982,9 @@ If set to on, This mixer_profile will try to switch to another mixer_profile whe

---

### mixer_pid_profile_linking
### mixer_control_profile_linking

If enabled, pid profile_index will follow mixer_profile index. Set to OFF(default) if you want to handle PID profile by your self. Recommend to set to ON on all mixer_profiles to let the mixer_profile handle the PID profile switching on a VTOL or mixed platform type setup.
If enabled, control_profile_index will follow mixer_profile index. Set to OFF(default) if you want to handle control_profile by your self. Recommend to set to ON on all mixer_profiles to let the mixer_profile handle the control_profile switching on a VTOL or mixed platform type setup.

| Default | Min | Max |
| --- | --- | --- |
Expand Down Expand Up @@ -6532,6 +6522,16 @@ Time zone offset from UTC, in minutes. This is applied to the GPS time for loggi

---

### use_control_profile

Control profile to switch to when the battery profile is selected, 0 to disable and keep the currently selected control profile

| Default | Min | Max |
| --- | --- | --- |
| 0 | 0 | 3 |

---

### vbat_adc_channel

ADC channel to use for battery voltage sensor. Defaults to board VBAT input (if available). 0 = disabled
Expand Down
2 changes: 1 addition & 1 deletion docs/development/msp/inav_enums_ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -4972,7 +4972,7 @@
|---|---:|---|
| `MASTER_VALUE` | (0 << SETTING_SECTION_OFFSET) | |
| `PROFILE_VALUE` | (1 << SETTING_SECTION_OFFSET) | |
| `CONTROL_RATE_VALUE` | (2 << SETTING_SECTION_OFFSET) | |
| `CONTROL_VALUE` | (2 << SETTING_SECTION_OFFSET) | |
| `BATTERY_CONFIG_VALUE` | (3 << SETTING_SECTION_OFFSET) | |
| `MIXER_CONFIG_VALUE` | (4 << SETTING_SECTION_OFFSET) | |
| `EZ_TUNE_VALUE` | (5 << SETTING_SECTION_OFFSET) | |
Expand Down
6 changes: 3 additions & 3 deletions src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ main_sources(COMMON_SRC
fc/cli.h
fc/config.c
fc/config.h
fc/controlrate_profile.c
fc/controlrate_profile.h
fc/controlrate_profile_config_struct.h
fc/control_profile.c
fc/control_profile.h
fc/control_profile_config_struct.h
fc/fc_core.c
fc/fc_core.h
fc/fc_init.c
Expand Down
20 changes: 10 additions & 10 deletions src/main/blackbox/blackbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include "drivers/pwm_output.h"

#include "fc/config.h"
#include "fc/controlrate_profile.h"
#include "fc/control_profile.h"
#include "fc/fc_core.h"
#include "fc/rc_controls.h"
#include "fc/rc_modes.h"
Expand Down Expand Up @@ -1934,15 +1934,15 @@ static bool blackboxWriteSysinfo(void)

BLACKBOX_PRINT_HEADER_LINE("looptime", "%d", getLooptime());
BLACKBOX_PRINT_HEADER_LINE("rc_rate", "%d", 100); //For compatibility reasons write rc_rate 100
BLACKBOX_PRINT_HEADER_LINE("rc_expo", "%d", currentControlRateProfile->stabilized.rcExpo8);
BLACKBOX_PRINT_HEADER_LINE("rc_yaw_expo", "%d", currentControlRateProfile->stabilized.rcYawExpo8);
BLACKBOX_PRINT_HEADER_LINE("thr_mid", "%d", currentControlRateProfile->throttle.rcMid8);
BLACKBOX_PRINT_HEADER_LINE("thr_expo", "%d", currentControlRateProfile->throttle.rcExpo8);
BLACKBOX_PRINT_HEADER_LINE("tpa_rate", "%d", currentControlRateProfile->throttle.dynPID);
BLACKBOX_PRINT_HEADER_LINE("tpa_breakpoint", "%d", currentControlRateProfile->throttle.pa_breakpoint);
BLACKBOX_PRINT_HEADER_LINE("rates", "%d,%d,%d", currentControlRateProfile->stabilized.rates[ROLL],
currentControlRateProfile->stabilized.rates[PITCH],
currentControlRateProfile->stabilized.rates[YAW]);
BLACKBOX_PRINT_HEADER_LINE("rc_expo", "%d", currentControlProfile->stabilized.rcExpo8);
BLACKBOX_PRINT_HEADER_LINE("rc_yaw_expo", "%d", currentControlProfile->stabilized.rcYawExpo8);
BLACKBOX_PRINT_HEADER_LINE("thr_mid", "%d", currentControlProfile->throttle.rcMid8);
BLACKBOX_PRINT_HEADER_LINE("thr_expo", "%d", currentControlProfile->throttle.rcExpo8);
BLACKBOX_PRINT_HEADER_LINE("tpa_rate", "%d", currentControlProfile->throttle.dynPID);
BLACKBOX_PRINT_HEADER_LINE("tpa_breakpoint", "%d", currentControlProfile->throttle.pa_breakpoint);
BLACKBOX_PRINT_HEADER_LINE("rates", "%d,%d,%d", currentControlProfile->stabilized.rates[ROLL],
currentControlProfile->stabilized.rates[PITCH],
currentControlProfile->stabilized.rates[YAW]);
BLACKBOX_PRINT_HEADER_LINE("rollPID", "%d,%d,%d,%d", pidBank()->pid[PID_ROLL].P,
pidBank()->pid[PID_ROLL].I,
pidBank()->pid[PID_ROLL].D,
Expand Down
4 changes: 2 additions & 2 deletions src/main/cms/cms_menu_imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "flight/pid.h"

#include "fc/config.h"
#include "fc/controlrate_profile.h"
#include "fc/control_profile.h"
#include "fc/rc_controls.h"
#include "fc/settings.h"

Expand Down Expand Up @@ -492,7 +492,7 @@ static const OSD_Entry cmsx_menuImuEntries[] =
OSD_SUBMENU_ENTRY("MECHANICS", &cmsx_menuMechanics),

// Rate profile dependent
OSD_UINT8_CALLBACK_ENTRY("RATE PROF", cmsx_profileIndexOnChange, (&(const OSD_UINT8_t){ &tmpProfileIndex, 1, MAX_CONTROL_RATE_PROFILE_COUNT, 1})),
OSD_UINT8_CALLBACK_ENTRY("RATE PROF", cmsx_profileIndexOnChange, (&(const OSD_UINT8_t){ &tmpProfileIndex, 1, MAX_CONTROL_PROFILE_COUNT, 1})),
OSD_SUBMENU_ENTRY("RATE", &cmsx_menuRateProfile),
OSD_SUBMENU_ENTRY("MANU RATE", &cmsx_menuManualRateProfile),

Expand Down
2 changes: 1 addition & 1 deletion src/main/config/parameter_group_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//#define PG_SENSOR_TRIMS 9 -- NOT USED in INAV
#define PG_GYRO_CONFIG 10
#define PG_BATTERY_PROFILES 11
#define PG_CONTROL_RATE_PROFILES 12
#define PG_CONTROL_PROFILES 12
#define PG_SERIAL_CONFIG 13
#define PG_PID_PROFILE 14
//#define PG_GTUNE_CONFIG 15
Expand Down
4 changes: 2 additions & 2 deletions src/main/fc/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool cliMode = false;
#include "fc/fc_core.h"
#include "fc/cli.h"
#include "fc/config.h"
#include "fc/controlrate_profile.h"
#include "fc/control_profile.h"
#include "fc/rc_adjustments.h"
#include "fc/rc_controls.h"
#include "fc/rc_modes.h"
Expand Down Expand Up @@ -3731,7 +3731,7 @@ static void cliDumpControlProfile(uint8_t profileIndex, uint8_t dumpMask)
cliPrintHashLine("control_profile");
cliPrintLinef("control_profile %d\r\n", getConfigProfile() + 1);
dumpAllValues(PROFILE_VALUE, dumpMask);
dumpAllValues(CONTROL_RATE_VALUE, dumpMask);
dumpAllValues(CONTROL_VALUE, dumpMask);
dumpAllValues(EZ_TUNE_VALUE, dumpMask);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/fc/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#include "flight/ez_tune.h"

#include "fc/config.h"
#include "fc/controlrate_profile.h"
#include "fc/control_profile.h"
#include "fc/rc_adjustments.h"
#include "fc/rc_controls.h"
#include "fc/rc_curves.h"
Expand Down Expand Up @@ -321,7 +321,7 @@ void resetConfigs(void)

static void activateConfig(void)
{
activateControlRateConfig();
activateControlConfig();
activateBatteryProfile();
activateMixerConfig();

Expand Down Expand Up @@ -443,7 +443,7 @@ bool setConfigProfile(uint8_t profileIndex)
pgActivateProfile(profileIndex);
systemConfigMutable()->current_profile_index = profileIndex;
// set the control rate profile to match
setControlRateProfile(profileIndex);
setControlProfile(profileIndex);
#ifdef USE_EZ_TUNE
ezTuneUpdate();
#endif
Expand Down
29 changes: 14 additions & 15 deletions src/main/fc/controlrate_profile.c → src/main/fc/control_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@
#include "config/parameter_group_ids.h"

#include "fc/config.h"
#include "fc/controlrate_profile.h"
#include "fc/control_profile.h"
#include "fc/rc_curves.h"
#include "fc/settings.h"

const controlRateConfig_t *currentControlRateProfile;
const controlConfig_t *currentControlProfile;

PG_REGISTER_ARRAY_WITH_RESET_FN(controlConfig_t, MAX_CONTROL_PROFILE_COUNT, controlProfiles, PG_CONTROL_PROFILES, 0);

PG_REGISTER_ARRAY_WITH_RESET_FN(controlRateConfig_t, MAX_CONTROL_RATE_PROFILE_COUNT, controlRateProfiles, PG_CONTROL_RATE_PROFILES, 4);

void pgResetFn_controlRateProfiles(controlRateConfig_t *instance)
void pgResetFn_controlProfiles(controlConfig_t *instance)
{
for (int i = 0; i < MAX_CONTROL_RATE_PROFILE_COUNT; i++) {
RESET_CONFIG(controlRateConfig_t, &instance[i],
for (int i = 0; i < MAX_CONTROL_PROFILE_COUNT; i++) {
RESET_CONFIG(controlConfig_t, &instance[i],
.throttle = {
.rcMid8 = SETTING_THR_MID_DEFAULT,
.rcExpo8 = SETTING_THR_EXPO_DEFAULT,
Expand Down Expand Up @@ -82,21 +81,21 @@ void pgResetFn_controlRateProfiles(controlRateConfig_t *instance)
}
}

void setControlRateProfile(uint8_t profileIndex)
void setControlProfile(uint8_t profileIndex)
{
if (profileIndex >= MAX_CONTROL_RATE_PROFILE_COUNT) {
if (profileIndex >= MAX_CONTROL_PROFILE_COUNT) {
profileIndex = 0;
}
currentControlRateProfile = controlRateProfiles(profileIndex);
currentControlProfile = controlProfiles(profileIndex);
}

void activateControlRateConfig(void)
void activateControlConfig(void)
{
generateThrottleCurve(currentControlRateProfile);
generateThrottleCurve(currentControlProfile);
}

void changeControlRateProfile(uint8_t profileIndex)
void changeControlProfile(uint8_t profileIndex)
{
setControlRateProfile(profileIndex);
activateControlRateConfig();
setControlProfile(profileIndex);
activateControlConfig();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@

#include "config/parameter_group.h"

#include "fc/controlrate_profile_config_struct.h"
#include "fc/control_profile_config_struct.h"
#include "fc/settings.h"

#define MAX_CONTROL_RATE_PROFILE_COUNT SETTING_CONSTANT_MAX_CONTROL_RATE_PROFILE_COUNT
#define MAX_CONTROL_PROFILE_COUNT SETTING_CONSTANT_MAX_CONTROL_PROFILE_COUNT

PG_DECLARE_ARRAY(controlRateConfig_t, MAX_CONTROL_RATE_PROFILE_COUNT, controlRateProfiles);
PG_DECLARE_ARRAY(controlConfig_t, MAX_CONTROL_PROFILE_COUNT, controlProfiles);

extern const controlRateConfig_t *currentControlRateProfile;
extern const controlConfig_t *currentControlProfile;

void setControlRateProfile(uint8_t profileIndex);
void changeControlRateProfile(uint8_t profileIndex);
void activateControlRateConfig(void);
uint8_t getCurrentControlRateProfile(void);
void setControlProfile(uint8_t profileIndex);
void changeControlProfile(uint8_t profileIndex);
void activateControlConfig(void);
uint8_t getCurrentControlProfile(void);
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <stdbool.h>
#include <stdint.h>

typedef struct controlRateConfig_s {
typedef struct controlConfig_s {

struct {
uint8_t rcMid8;
Expand Down Expand Up @@ -61,4 +61,4 @@ typedef struct controlRateConfig_s {
} rateDynamics;
#endif

} controlRateConfig_t;
} controlConfig_t;
16 changes: 8 additions & 8 deletions src/main/fc/fc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#include "fc/fc_core.h"
#include "fc/cli.h"
#include "fc/config.h"
#include "fc/controlrate_profile.h"
#include "fc/control_profile.h"
#include "fc/multifunction.h"
#include "fc/rc_adjustments.h"
#include "fc/rc_smoothing.h"
Expand Down Expand Up @@ -391,15 +391,15 @@ static void processPilotAndFailSafeActions(float dT)
}
else {
// Compute ROLL PITCH and YAW command
rcCommand[ROLL] = getAxisRcCommand(rxGetChannelValue(ROLL), FLIGHT_MODE(MANUAL_MODE) ? currentControlRateProfile->manual.rcExpo8 : currentControlRateProfile->stabilized.rcExpo8, rcControlsConfig()->deadband);
rcCommand[PITCH] = getAxisRcCommand(rxGetChannelValue(PITCH), FLIGHT_MODE(MANUAL_MODE) ? currentControlRateProfile->manual.rcExpo8 : currentControlRateProfile->stabilized.rcExpo8, rcControlsConfig()->deadband);
rcCommand[YAW] = -getAxisRcCommand(rxGetChannelValue(YAW), FLIGHT_MODE(MANUAL_MODE) ? currentControlRateProfile->manual.rcYawExpo8 : currentControlRateProfile->stabilized.rcYawExpo8, rcControlsConfig()->yaw_deadband);
rcCommand[ROLL] = getAxisRcCommand(rxGetChannelValue(ROLL), FLIGHT_MODE(MANUAL_MODE) ? currentControlProfile->manual.rcExpo8 : currentControlProfile->stabilized.rcExpo8, rcControlsConfig()->deadband);
rcCommand[PITCH] = getAxisRcCommand(rxGetChannelValue(PITCH), FLIGHT_MODE(MANUAL_MODE) ? currentControlProfile->manual.rcExpo8 : currentControlProfile->stabilized.rcExpo8, rcControlsConfig()->deadband);
rcCommand[YAW] = -getAxisRcCommand(rxGetChannelValue(YAW), FLIGHT_MODE(MANUAL_MODE) ? currentControlProfile->manual.rcYawExpo8 : currentControlProfile->stabilized.rcYawExpo8, rcControlsConfig()->yaw_deadband);

// Apply manual control rates
if (FLIGHT_MODE(MANUAL_MODE)) {
rcCommand[ROLL] = rcCommand[ROLL] * currentControlRateProfile->manual.rates[FD_ROLL] / 100L;
rcCommand[PITCH] = rcCommand[PITCH] * currentControlRateProfile->manual.rates[FD_PITCH] / 100L;
rcCommand[YAW] = rcCommand[YAW] * currentControlRateProfile->manual.rates[FD_YAW] / 100L;
rcCommand[ROLL] = rcCommand[ROLL] * currentControlProfile->manual.rates[FD_ROLL] / 100L;
rcCommand[PITCH] = rcCommand[PITCH] * currentControlProfile->manual.rates[FD_PITCH] / 100L;
rcCommand[YAW] = rcCommand[YAW] * currentControlProfile->manual.rates[FD_YAW] / 100L;
} else {
DEBUG_SET(DEBUG_RATE_DYNAMICS, 0, rcCommand[ROLL]);
rcCommand[ROLL] = applyRateDynamics(rcCommand[ROLL], ROLL, dT);
Expand Down Expand Up @@ -656,7 +656,7 @@ void processRx(timeUs_t currentTimeUs)
if (!cliMode) {
bool canUseRxData = rxIsReceivingSignal() && !FLIGHT_MODE(FAILSAFE_MODE);
updateAdjustmentStates(canUseRxData);
processRcAdjustments(CONST_CAST(controlRateConfig_t*, currentControlRateProfile), canUseRxData);
processRcAdjustments(CONST_CAST(controlConfig_t*, currentControlProfile), canUseRxData);
}

// Angle mode forced on briefly after emergency inflight rearm to help stabilise attitude (currently limited to MR)
Expand Down
Loading