mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-22 07:45:29 +03:00
Add rate profiles and inflight switching between them. See Profiles and
Inflight Adjustment documentation for details.
This commit is contained in:
parent
cac814923c
commit
28f9fa629c
12 changed files with 346 additions and 66 deletions
|
@ -98,10 +98,11 @@ void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions, es
|
|||
// use the last flash pages for storage
|
||||
#define CONFIG_START_FLASH_ADDRESS (0x08000000 + (uint32_t)((FLASH_PAGE_SIZE * FLASH_PAGE_COUNT) - FLASH_TO_RESERVE_FOR_CONFIG))
|
||||
|
||||
master_t masterConfig; // master config struct with data independent from profiles
|
||||
profile_t *currentProfile; // profile config struct
|
||||
master_t masterConfig; // master config struct with data independent from profiles
|
||||
profile_t *currentProfile;
|
||||
controlRateConfig_t *currentControlRateProfile;
|
||||
|
||||
static const uint8_t EEPROM_CONF_VERSION = 83;
|
||||
static const uint8_t EEPROM_CONF_VERSION = 84;
|
||||
|
||||
static void resetAccelerometerTrims(flightDynamicsTrims_t *accelerometerTrims)
|
||||
{
|
||||
|
@ -231,12 +232,36 @@ void resetSerialConfig(serialConfig_t *serialConfig)
|
|||
serialConfig->reboot_character = 'R';
|
||||
}
|
||||
|
||||
static void resetControlRateConfig(controlRateConfig_t *controlRateConfig) {
|
||||
controlRateConfig->rcRate8 = 90;
|
||||
controlRateConfig->rcExpo8 = 65;
|
||||
controlRateConfig->rollPitchRate = 0;
|
||||
controlRateConfig->yawRate = 0;
|
||||
controlRateConfig->thrMid8 = 50;
|
||||
controlRateConfig->thrExpo8 = 0;
|
||||
controlRateConfig->dynThrPID = 0;
|
||||
controlRateConfig->tpa_breakpoint = 1500;
|
||||
|
||||
}
|
||||
|
||||
static void setProfile(uint8_t profileIndex)
|
||||
{
|
||||
currentProfile = &masterConfig.profile[profileIndex];
|
||||
}
|
||||
|
||||
static uint8_t currentControlRateProfileIndex = 0;
|
||||
|
||||
uint8_t getCurrentControlRateProfile(void)
|
||||
{
|
||||
return currentControlRateProfileIndex;
|
||||
}
|
||||
|
||||
static void setControlRateProfile(uint8_t profileIndex)
|
||||
{
|
||||
currentControlRateProfileIndex = profileIndex;
|
||||
currentControlRateProfile = &masterConfig.controlRateProfiles[profileIndex];
|
||||
}
|
||||
|
||||
// Default settings
|
||||
static void resetConf(void)
|
||||
{
|
||||
|
@ -322,14 +347,7 @@ static void resetConf(void)
|
|||
currentProfile->pidController = 0;
|
||||
resetPidProfile(¤tProfile->pidProfile);
|
||||
|
||||
currentProfile->controlRateConfig.rcRate8 = 90;
|
||||
currentProfile->controlRateConfig.rcExpo8 = 65;
|
||||
currentProfile->controlRateConfig.rollPitchRate = 0;
|
||||
currentProfile->controlRateConfig.yawRate = 0;
|
||||
currentProfile->dynThrPID = 0;
|
||||
currentProfile->tpa_breakpoint = 1500;
|
||||
currentProfile->controlRateConfig.thrMid8 = 50;
|
||||
currentProfile->controlRateConfig.thrExpo8 = 0;
|
||||
resetControlRateConfig(&masterConfig.controlRateProfiles[0]);
|
||||
|
||||
// for (i = 0; i < CHECKBOXITEMS; i++)
|
||||
// cfg.activate[i] = 0;
|
||||
|
@ -391,8 +409,18 @@ static void resetConf(void)
|
|||
#endif
|
||||
|
||||
// copy first profile into remaining profile
|
||||
for (i = 1; i < 3; i++)
|
||||
for (i = 1; i < MAX_PROFILE_COUNT; i++) {
|
||||
memcpy(&masterConfig.profile[i], currentProfile, sizeof(profile_t));
|
||||
}
|
||||
|
||||
// copy first control rate config into remaining profile
|
||||
for (i = 1; i < MAX_CONTROL_RATE_PROFILE_COUNT; i++) {
|
||||
memcpy(&masterConfig.controlRateProfiles[i], currentControlRateProfile, sizeof(controlRateConfig_t));
|
||||
}
|
||||
|
||||
for (i = 1; i < MAX_PROFILE_COUNT; i++) {
|
||||
masterConfig.profile[i].default_rateProfile_index = i % MAX_CONTROL_RATE_PROFILE_COUNT;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t calculateChecksum(const uint8_t *data, uint32_t length)
|
||||
|
@ -427,12 +455,18 @@ static bool isEEPROMContentValid(void)
|
|||
return true;
|
||||
}
|
||||
|
||||
void activateControlRateConfig(void)
|
||||
{
|
||||
generatePitchRollCurve(currentControlRateProfile);
|
||||
generateThrottleCurve(currentControlRateProfile, &masterConfig.escAndServoConfig);
|
||||
}
|
||||
|
||||
void activateConfig(void)
|
||||
{
|
||||
static imuRuntimeConfig_t imuRuntimeConfig;
|
||||
|
||||
generatePitchRollCurve(¤tProfile->controlRateConfig);
|
||||
generateThrottleCurve(¤tProfile->controlRateConfig, &masterConfig.escAndServoConfig);
|
||||
activateControlRateConfig();
|
||||
|
||||
useRcControlsConfig(currentProfile->modeActivationConditions, &masterConfig.escAndServoConfig, ¤tProfile->pidProfile);
|
||||
|
||||
useGyroConfig(&masterConfig.gyroConfig);
|
||||
|
@ -565,12 +599,17 @@ void readEEPROM(void)
|
|||
|
||||
// Read flash
|
||||
memcpy(&masterConfig, (char *) CONFIG_START_FLASH_ADDRESS, sizeof(master_t));
|
||||
// Copy current profile
|
||||
if (masterConfig.current_profile_index > 2) // sanity check
|
||||
|
||||
if (masterConfig.current_profile_index > MAX_PROFILE_COUNT - 1) // sanity check
|
||||
masterConfig.current_profile_index = 0;
|
||||
|
||||
setProfile(masterConfig.current_profile_index);
|
||||
|
||||
if (currentProfile->default_rateProfile_index > MAX_CONTROL_RATE_PROFILE_COUNT - 1) // sanity check
|
||||
currentProfile->default_rateProfile_index = 0;
|
||||
|
||||
setControlRateProfile(currentProfile->default_rateProfile_index);
|
||||
|
||||
validateAndFixConfig();
|
||||
activateConfig();
|
||||
}
|
||||
|
@ -663,6 +702,15 @@ void changeProfile(uint8_t profileIndex)
|
|||
blinkLedAndSoundBeeper(2, 40, profileIndex + 1);
|
||||
}
|
||||
|
||||
void changeControlRateProfile(uint8_t profileIndex)
|
||||
{
|
||||
if (profileIndex > MAX_CONTROL_RATE_PROFILE_COUNT) {
|
||||
profileIndex = MAX_CONTROL_RATE_PROFILE_COUNT - 1;
|
||||
}
|
||||
setControlRateProfile(profileIndex);
|
||||
activateControlRateConfig();
|
||||
}
|
||||
|
||||
bool feature(uint32_t mask)
|
||||
{
|
||||
return masterConfig.enabledFeatures & mask;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue