proportional spark cut #3427

This commit is contained in:
Andrey 2021-11-16 13:15:12 -05:00
parent c951d1d0c0
commit a61043e570
4 changed files with 36 additions and 0 deletions

View File

@ -115,6 +115,7 @@ public:
GearControllerBase *gearController; GearControllerBase *gearController;
LaunchControlBase launchController; LaunchControlBase launchController;
SoftSparkLimiter softSparkLimiter;
efitick_t mostRecentSparkEvent; efitick_t mostRecentSparkEvent;
efitick_t mostRecentTimeBetweenSparkEvents; efitick_t mostRecentTimeBetweenSparkEvents;

View File

@ -137,6 +137,21 @@ bool LaunchControlBase::isLaunchFuelRpmRetardCondition() const {
return isLaunchRpmRetardCondition() && engineConfiguration->launchFuelCutEnable; return isLaunchRpmRetardCondition() && engineConfiguration->launchFuelCutEnable;
} }
void SoftSparkLimiter::setTargetSkipRatio(float targetSkipRatio) {
this->targetSkipRatio = targetSkipRatio;
}
bool SoftSparkLimiter::shouldSkip() {
if (targetSkipRatio == 0 || wasJustSkipped) {
wasJustSkipped = false;
return false;
}
float r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
wasJustSkipped = r < 2 * targetSkipRatio;
return wasJustSkipped;
}
void initLaunchControl() { void initLaunchControl() {
engine->launchController.inject(); engine->launchController.inject();
} }

View File

@ -35,3 +35,17 @@ private:
Timer m_launchTimer; Timer m_launchTimer;
}; };
class SoftSparkLimiter {
public:
/**
* targetSkipRatio of '0' means 'do not skip', would always return false
*/
void setTargetSkipRatio(float targetSkipRatio);
bool shouldSkip();
private:
bool wasJustSkipped = false;
float targetSkipRatio = 0;
};

View File

@ -486,6 +486,12 @@ void configureRusefiLuaHooks(lua_State* l) {
return 1; return 1;
}); });
lua_register(l, "setSparkSkipRatio", [](lua_State* l) {
auto targetSkipRatio = luaL_checknumber(l, 1);
engine->softSparkLimiter.setTargetSkipRatio(targetSkipRatio);
return 1;
});
#if !EFI_UNIT_TEST #if !EFI_UNIT_TEST
lua_register(l, "startPwm", lua_startPwm); lua_register(l, "startPwm", lua_startPwm);
lua_register(l, "setPwmDuty", lua_setPwmDuty); lua_register(l, "setPwmDuty", lua_setPwmDuty);