mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 09:45:37 +03:00
Merge pull request #7516 from mikeller/add_automatic_pid_profile_switching
Added battery cell count based automatic PID profile switching.
This commit is contained in:
commit
59ea4becb3
23 changed files with 124 additions and 73 deletions
|
@ -194,7 +194,7 @@ static void validateAndFixConfig(void)
|
|||
}
|
||||
loadControlRateProfile();
|
||||
|
||||
if (systemConfig()->pidProfileIndex >= MAX_PROFILE_COUNT) {
|
||||
if (systemConfig()->pidProfileIndex >= PID_PROFILE_COUNT) {
|
||||
systemConfigMutable()->pidProfileIndex = 0;
|
||||
}
|
||||
loadPidProfile();
|
||||
|
@ -215,6 +215,10 @@ static void validateAndFixConfig(void)
|
|||
currentPidProfile->motor_output_limit = 100;
|
||||
}
|
||||
|
||||
if (currentPidProfile->auto_profile_cell_count > MAX_AUTO_DETECT_CELL_COUNT || currentPidProfile->auto_profile_cell_count < AUTO_PROFILE_CELL_COUNT_CHANGE) {
|
||||
currentPidProfile->auto_profile_cell_count = AUTO_PROFILE_CELL_COUNT_STAY;
|
||||
}
|
||||
|
||||
if (motorConfig()->dev.motorPwmProtocol == PWM_TYPE_BRUSHED) {
|
||||
featureDisable(FEATURE_3D);
|
||||
|
||||
|
@ -286,7 +290,7 @@ static void validateAndFixConfig(void)
|
|||
}
|
||||
|
||||
if (!rcSmoothingIsEnabled() || rxConfig()->rcInterpolationChannels == INTERPOLATION_CHANNELS_T) {
|
||||
for (unsigned i = 0; i < MAX_PROFILE_COUNT; i++) {
|
||||
for (unsigned i = 0; i < PID_PROFILE_COUNT; i++) {
|
||||
pidProfilesMutable(i)->pid[PID_ROLL].F = 0;
|
||||
pidProfilesMutable(i)->pid[PID_PITCH].F = 0;
|
||||
}
|
||||
|
@ -296,7 +300,7 @@ static void validateAndFixConfig(void)
|
|||
(rxConfig()->rcInterpolationChannels != INTERPOLATION_CHANNELS_RPY &&
|
||||
rxConfig()->rcInterpolationChannels != INTERPOLATION_CHANNELS_RPYT)) {
|
||||
|
||||
for (unsigned i = 0; i < MAX_PROFILE_COUNT; i++) {
|
||||
for (unsigned i = 0; i < PID_PROFILE_COUNT; i++) {
|
||||
pidProfilesMutable(i)->pid[PID_YAW].F = 0;
|
||||
}
|
||||
}
|
||||
|
@ -306,7 +310,7 @@ static void validateAndFixConfig(void)
|
|||
!(rxConfig()->rcInterpolationChannels == INTERPOLATION_CHANNELS_RPYT
|
||||
|| rxConfig()->rcInterpolationChannels == INTERPOLATION_CHANNELS_T
|
||||
|| rxConfig()->rcInterpolationChannels == INTERPOLATION_CHANNELS_RPT)) {
|
||||
for (unsigned i = 0; i < MAX_PROFILE_COUNT; i++) {
|
||||
for (unsigned i = 0; i < PID_PROFILE_COUNT; i++) {
|
||||
pidProfilesMutable(i)->throttle_boost = 0;
|
||||
}
|
||||
}
|
||||
|
@ -630,9 +634,34 @@ void saveConfigAndNotify(void)
|
|||
beeperConfirmationBeeps(1);
|
||||
}
|
||||
|
||||
void changePidProfileFromCellCount(uint8_t cellCount)
|
||||
{
|
||||
if (currentPidProfile->auto_profile_cell_count == cellCount || currentPidProfile->auto_profile_cell_count == AUTO_PROFILE_CELL_COUNT_STAY) {
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned profileIndex = (systemConfig()->pidProfileIndex + 1) % PID_PROFILE_COUNT;
|
||||
int matchingProfileIndex = -1;
|
||||
while (profileIndex != systemConfig()->pidProfileIndex) {
|
||||
if (pidProfiles(profileIndex)->auto_profile_cell_count == cellCount) {
|
||||
matchingProfileIndex = profileIndex;
|
||||
|
||||
break;
|
||||
} else if (matchingProfileIndex < 0 && pidProfiles(profileIndex)->auto_profile_cell_count == AUTO_PROFILE_CELL_COUNT_STAY) {
|
||||
matchingProfileIndex = profileIndex;
|
||||
}
|
||||
|
||||
profileIndex = (profileIndex + 1) % PID_PROFILE_COUNT;
|
||||
}
|
||||
|
||||
if (matchingProfileIndex >= 0) {
|
||||
changePidProfile(matchingProfileIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void changePidProfile(uint8_t pidProfileIndex)
|
||||
{
|
||||
if (pidProfileIndex < MAX_PROFILE_COUNT) {
|
||||
if (pidProfileIndex < PID_PROFILE_COUNT) {
|
||||
systemConfigMutable()->pidProfileIndex = pidProfileIndex;
|
||||
loadPidProfile();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue