Iac cranking running taper (#465)

* IAC taper

* chibios sync

* fix for afterCrankingIACtaperDuration==0
This commit is contained in:
andreika-git 2017-08-01 23:27:16 +03:00 committed by rusefi
parent a2ad10c973
commit c10077aa2e
3 changed files with 29 additions and 4 deletions

View File

@ -129,6 +129,17 @@ float interpolate(float x1, float y1, float x2, float y2, float x) {
return interpolateMsg("", x1, y1, x2, y2, x); return interpolateMsg("", x1, y1, x2, y2, x);
} }
float interpolateClamped(float x1, float y1, float x2, float y2, float x) {
if (x <= x1)
return y1;
if (x >= x2)
return y2;
float a = INTERPOLATION_A(x1, y1, x2, y2);
float b = y1 - a * x1;
return a * x + b;
}
/** /**
* Another implementation, which one is faster? * Another implementation, which one is faster?
*/ */

View File

@ -25,6 +25,7 @@ int findIndexMsg(const char *msg, const float array[], int size, float value);
void ensureArrayIsAscending(const char *msg, const float array[], int size); void ensureArrayIsAscending(const char *msg, const float array[], int size);
int findIndex2(const float array[], unsigned size, float value); int findIndex2(const float array[], unsigned size, float value);
float interpolate(float x1, float y1, float x2, float y2, float x); float interpolate(float x1, float y1, float x2, float y2, float x);
float interpolateClamped(float x1, float y1, float x2, float y2, float x);
float interpolateMsg(const char *msg, float x1, float y1, float x2, float y2, float x); float interpolateMsg(const char *msg, float x1, float y1, float x2, float y2, float x);
float interpolate2d(const char *msg, float value, float bin[], float values[], int size); float interpolate2d(const char *msg, float value, float bin[], float values[], int size);

View File

@ -54,6 +54,9 @@ static StepperMotor iacMotor;
static int adjustedTargetRpm; static int adjustedTargetRpm;
static uint32_t lastCrankingCyclesCounter = 0;
static float lastCrankingIacPosition;
/** /**
* that's current position with CLT and IAT corrections * that's current position with CLT and IAT corrections
*/ */
@ -213,11 +216,21 @@ static msg_t ivThread(int param) {
} else if (!engine->rpmCalculator.isRunning(PASS_ENGINE_PARAMETER_SIGNATURE)) { } else if (!engine->rpmCalculator.isRunning(PASS_ENGINE_PARAMETER_SIGNATURE)) {
// during cranking it's always manual mode, PID would make no sence during cranking // during cranking it's always manual mode, PID would make no sence during cranking
iacPosition = cltCorrection * engineConfiguration->crankingIACposition; iacPosition = cltCorrection * engineConfiguration->crankingIACposition;
} else if (engineConfiguration->idleMode == IM_MANUAL) { // save cranking position & cycles counter for taper transition
// let's re-apply CLT correction lastCrankingIacPosition = iacPosition;
iacPosition = manualIdleController(cltCorrection); lastCrankingCyclesCounter = engine->rpmCalculator.getRevolutionCounterSinceStart();
} else { } else {
iacPosition = autoIdle(cltCorrection); if (engineConfiguration->idleMode == IM_MANUAL) {
// let's re-apply CLT correction
iacPosition = manualIdleController(cltCorrection);
} else {
iacPosition = autoIdle(cltCorrection);
}
// taper transition from cranking to running (uint32_t to float conversion is safe here)
if (engineConfiguration->afterCrankingIACtaperDuration > 0)
iacPosition = interpolateClamped(lastCrankingCyclesCounter, lastCrankingIacPosition,
lastCrankingCyclesCounter + engineConfiguration->afterCrankingIACtaperDuration, iacPosition,
engine->rpmCalculator.getRevolutionCounterSinceStart());
} }
if (absF(iacPosition - currentIdlePosition) < 1) { if (absF(iacPosition - currentIdlePosition) < 1) {