mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 14:55:21 +03:00
make it easier to switch between locked and unlocked
This commit is contained in:
parent
fc39593415
commit
6f070bbc88
1 changed files with 21 additions and 16 deletions
|
@ -346,10 +346,20 @@ static void applyFlipOverAfterCrashModeToMotors(void)
|
||||||
|
|
||||||
static void applyRPMLimiter(void)
|
static void applyRPMLimiter(void)
|
||||||
{
|
{
|
||||||
//Street League customization
|
//Street League spec settings
|
||||||
float forcedRPMLimit = 130.0f;
|
float forcedRPMLimit = 130.0f;
|
||||||
//if (mixerConfig()->govenor && motorConfig()->dev.useDshotTelemetry) {
|
bool forcedLinearization = true;
|
||||||
if (motorConfig()->dev.useDshotTelemetry) {
|
int forcedMotorPoleCount = 14;
|
||||||
|
bool forceGovenor = true;
|
||||||
|
|
||||||
|
//Unlocked spec settings
|
||||||
|
//float forcedRPMLimit = mixerConfig()->govenor_rpm_limit;
|
||||||
|
//bool forcedLinearization = mixerConfig()->rpm_linearization;
|
||||||
|
//int forcedMotorPoleCount = motorConfig()->motorPoleCount;
|
||||||
|
//bool forceGovenor = mixerConfig()->govenor && motorConfig()->dev.useDshotTelemetry;
|
||||||
|
|
||||||
|
|
||||||
|
if (forceGovenor) {
|
||||||
float RPM_GOVENOR_LIMIT = 0;
|
float RPM_GOVENOR_LIMIT = 0;
|
||||||
float averageRPM = 0;
|
float averageRPM = 0;
|
||||||
float averageRPM_smoothed = 0;
|
float averageRPM_smoothed = 0;
|
||||||
|
@ -357,11 +367,8 @@ static void applyRPMLimiter(void)
|
||||||
float rcCommandThrottle = (rcCommand[THROTTLE]-1000)/1000.0f;
|
float rcCommandThrottle = (rcCommand[THROTTLE]-1000)/1000.0f;
|
||||||
|
|
||||||
//Street League customization
|
//Street League customization
|
||||||
//if (mixerConfig()->rpm_linearization) {
|
if (forcedLinearization) {
|
||||||
if (true) {
|
|
||||||
//scales rpm setpoint between idle rpm and rpm limit based on throttle percent
|
//scales rpm setpoint between idle rpm and rpm limit based on throttle percent
|
||||||
//Street League customization
|
|
||||||
//RPM_GOVENOR_LIMIT = ((mixerConfig()->govenor_rpm_limit - mixerConfig()->govenor_idle_rpm))*100.0f*(rcCommandThrottle) + mixerConfig()->govenor_idle_rpm * 100.0f;
|
|
||||||
RPM_GOVENOR_LIMIT = ((forcedRPMLimit - mixerConfig()->govenor_idle_rpm))*100.0f*(rcCommandThrottle) + mixerConfig()->govenor_idle_rpm * 100.0f;
|
RPM_GOVENOR_LIMIT = ((forcedRPMLimit - mixerConfig()->govenor_idle_rpm))*100.0f*(rcCommandThrottle) + mixerConfig()->govenor_idle_rpm * 100.0f;
|
||||||
|
|
||||||
//limit the speed with which the rpm setpoint can increase based on the rpm_limiter_acceleration_limit cli command
|
//limit the speed with which the rpm setpoint can increase based on the rpm_limiter_acceleration_limit cli command
|
||||||
|
@ -377,8 +384,6 @@ static void applyRPMLimiter(void)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throttle = throttle * mixerRuntime.govenorExpectedThrottleLimit;
|
throttle = throttle * mixerRuntime.govenorExpectedThrottleLimit;
|
||||||
//Street League customization
|
|
||||||
//RPM_GOVENOR_LIMIT = ((mixerConfig()->govenor_rpm_limit))*100.0f;
|
|
||||||
RPM_GOVENOR_LIMIT = ((forcedRPMLimit))*100.0f;
|
RPM_GOVENOR_LIMIT = ((forcedRPMLimit))*100.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,7 +395,7 @@ static void applyRPMLimiter(void)
|
||||||
motorsSaturated = true;
|
motorsSaturated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
averageRPM = 100 * averageRPM / (getMotorCount()*motorConfig()->motorPoleCount/2.0f);
|
averageRPM = 100 * averageRPM / (getMotorCount()*forcedMotorPoleCount/2.0f);
|
||||||
|
|
||||||
//get the smoothed rpm to avoid d term noise
|
//get the smoothed rpm to avoid d term noise
|
||||||
averageRPM_smoothed = mixerRuntime.govenorPreviousSmoothedRPM + mixerRuntime.govenorDelayK * (averageRPM - mixerRuntime.govenorPreviousSmoothedRPM); //kinda braindead to convert to rps then back
|
averageRPM_smoothed = mixerRuntime.govenorPreviousSmoothedRPM + mixerRuntime.govenorDelayK * (averageRPM - mixerRuntime.govenorPreviousSmoothedRPM); //kinda braindead to convert to rps then back
|
||||||
|
@ -399,7 +404,7 @@ static void applyRPMLimiter(void)
|
||||||
float govenorP = smoothedRPMError * mixerRuntime.govenorPGain; //+ when overspped
|
float govenorP = smoothedRPMError * mixerRuntime.govenorPGain; //+ when overspped
|
||||||
float govenorD = (smoothedRPMError-mixerRuntime.govenorPreviousSmoothedRPMError) * mixerRuntime.govenorDGain; // + when quickly going overspeed
|
float govenorD = (smoothedRPMError-mixerRuntime.govenorPreviousSmoothedRPMError) * mixerRuntime.govenorDGain; // + when quickly going overspeed
|
||||||
|
|
||||||
if (mixerConfig()->rpm_linearization) {
|
if (forcedLinearization) {
|
||||||
//don't let I term wind up if throttle is below the motor idle
|
//don't let I term wind up if throttle is below the motor idle
|
||||||
if (rcCommandThrottle < motorConfig()->digitalIdleOffsetValue / 10000.0f) {
|
if (rcCommandThrottle < motorConfig()->digitalIdleOffsetValue / 10000.0f) {
|
||||||
mixerRuntime.govenorI *= 1.0f/(1.0f+(pidGetDT()*10.0f)); //slowly ramp down i term instead of resetting to avoid throttle pulsing cheats
|
mixerRuntime.govenorI *= 1.0f/(1.0f+(pidGetDT()*10.0f)); //slowly ramp down i term instead of resetting to avoid throttle pulsing cheats
|
||||||
|
@ -430,7 +435,7 @@ static void applyRPMLimiter(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
if (mixerRuntime.govenor_init) {
|
if (mixerRuntime.govenor_init) {
|
||||||
if (mixerConfig()->rpm_linearization) {
|
if (forcedLinearization) {
|
||||||
throttle = constrainf(-PIDOutput, 0.0f, 1.0f);
|
throttle = constrainf(-PIDOutput, 0.0f, 1.0f);
|
||||||
} else {
|
} else {
|
||||||
throttle = constrainf(throttle-PIDOutput, 0.0f, 1.0f);
|
throttle = constrainf(throttle-PIDOutput, 0.0f, 1.0f);
|
||||||
|
@ -444,10 +449,10 @@ static void applyRPMLimiter(void)
|
||||||
mixerRuntime.govenorPreviousSmoothedRPMError = smoothedRPMError;
|
mixerRuntime.govenorPreviousSmoothedRPMError = smoothedRPMError;
|
||||||
mixerRuntime.govenorPreviousRPMLimit = RPM_GOVENOR_LIMIT;
|
mixerRuntime.govenorPreviousRPMLimit = RPM_GOVENOR_LIMIT;
|
||||||
|
|
||||||
// DEBUG_SET(DEBUG_RPM_LIMITER, 0, averageRPM);
|
//DEBUG_SET(DEBUG_RPM_LIMITER, 0, averageRPM);
|
||||||
// DEBUG_SET(DEBUG_RPM_LIMITER, 1, smoothedRPMError);
|
//DEBUG_SET(DEBUG_RPM_LIMITER, 1, smoothedRPMError);
|
||||||
// DEBUG_SET(DEBUG_RPM_LIMITER, 2, mixerRuntime.govenorI*100.0f);
|
//DEBUG_SET(DEBUG_RPM_LIMITER, 2, mixerRuntime.govenorI*100.0f);
|
||||||
// DEBUG_SET(DEBUG_RPM_LIMITER, 3, govenorD*10000.0f);
|
//DEBUG_SET(DEBUG_RPM_LIMITER, 3, govenorD*10000.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue