Share the code for getTargetRpmForIdleCorrection() and move it from idle_thread.cpp

This commit is contained in:
Andrei 2019-03-22 17:41:20 +02:00
parent e9bbda6648
commit 0f671b7865
3 changed files with 16 additions and 12 deletions

View File

@ -619,6 +619,18 @@ void setTargetRpmCurve(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
setLinearCurve(engineConfiguration->cltIdleRpm, CLT_CURVE_SIZE, rpm, rpm, 10);
}
int getTargetRpmForIdleCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
float clt = engine->sensors.clt;
int targetRpm;
if (cisnan(clt)) {
// error is already reported, let's take first value from the table should be good enough error handing solution
targetRpm = CONFIG(cltIdleRpm)[0];
} else {
targetRpm = interpolate2d("cltRpm", clt, CONFIG(cltIdleRpmBins), CONFIG(cltIdleRpm), CLT_CURVE_SIZE);
}
return targetRpm + engine->fsioState.fsioIdleTargetRPMAdjustment;
}
/**
* @brief Global default engine configuration
* This method sets the global engine configuration defaults. These default values are then

View File

@ -51,6 +51,7 @@ typedef struct {
void prepareVoidConfiguration(engine_configuration_s *activeConfiguration);
void setDefaultConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void setTargetRpmCurve(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX);
int getTargetRpmForIdleCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void setAfrMap(afr_table_t table, float value);
/**
* See also setLinearCurve()

View File

@ -205,16 +205,7 @@ static percent_t automaticIdleController() {
}
// get Target RPM for Auto-PID from a separate table
float clt = engine->sensors.clt;
int targetRpm;
if (cisnan(clt)) {
// error is already reported, let's take first value from the table should be good enough error handing solution
targetRpm = CONFIG(cltIdleRpm)[0];
} else {
targetRpm = interpolate2d("cltRpm", clt, CONFIG(cltIdleRpmBins), CONFIG(cltIdleRpm), CLT_CURVE_SIZE);
}
targetRpm += engine->fsioState.fsioIdleTargetRPMAdjustment;
int targetRpm = getTargetRpmForIdleCorrection(PASS_ENGINE_PARAMETER_SIGNATURE);
// check if within the dead zone
int rpm = GET_RPM();
@ -256,8 +247,8 @@ static percent_t automaticIdleController() {
int idlePidLowerRpm = targetRpm + CONFIG(idlePidRpmDeadZone);
if (CONFIG(idlePidRpmUpperLimit) > 0) {
idleState = PID_UPPER;
if (CONFIGB(useIacTableForCoasting)) {
percent_t iacPosForCoasting = interpolate2d("iacCoasting", clt, CONFIG(iacCoastingBins), CONFIG(iacCoasting), CLT_CURVE_SIZE);
if (CONFIGB(useIacTableForCoasting) && !cisnan(engine->sensors.clt)) {
percent_t iacPosForCoasting = interpolate2d("iacCoasting", engine->sensors.clt, CONFIG(iacCoastingBins), CONFIG(iacCoasting), CLT_CURVE_SIZE);
newValue = interpolateClamped(idlePidLowerRpm, newValue, idlePidLowerRpm + CONFIG(idlePidRpmUpperLimit), iacPosForCoasting, rpm);
} else {
// Well, just leave it as is, without PID regulation...