diff --git a/firmware/controllers/algo/advance_map.cpp b/firmware/controllers/algo/advance_map.cpp index b70085e2c8..384db68fb8 100644 --- a/firmware/controllers/algo/advance_map.cpp +++ b/firmware/controllers/algo/advance_map.cpp @@ -32,6 +32,7 @@ int minCrankingRpm = 0; static Map3D tcTimingDropTable; +static Map3D tcSparkSkipTable; #if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT @@ -60,6 +61,8 @@ static angle_t getRunningAdvance(int rpm, float engineLoad) { float vehicleSpeed = Sensor::getOrZero(SensorType::VehicleSpeed); float wheelSlip = Sensor::getOrZero(SensorType::WheelSlipRatio); engine->ignitionState.tractionAdvanceDrop = tcTimingDropTable.getValue(wheelSlip, vehicleSpeed); + engine->engineState.tractionControlSparkSkip = tcSparkSkipTable.getValue(wheelSlip, vehicleSpeed); + engine->engineState.updateSparkSkip(); advanceAngle += engine->ignitionState.tractionAdvanceDrop; @@ -253,6 +256,7 @@ size_t getMultiSparkCount(int rpm) { void initIgnitionAdvanceControl() { tcTimingDropTable.initTable(engineConfiguration->tractionControlTimingDrop, engineConfiguration->tractionControlSlipBins, engineConfiguration->tractionControlSpeedBins); + tcSparkSkipTable.initTable(engineConfiguration->tractionControlIgnitionSkip, engineConfiguration->tractionControlSlipBins, engineConfiguration->tractionControlSpeedBins); } #endif // EFI_ENGINE_CONTROL diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index 6182d32cd6..48cbeab667 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -88,6 +88,11 @@ EngineState::EngineState() { void EngineState::updateSlowSensors() { } +void EngineState::updateSparkSkip() { + engine->softSparkLimiter.setTargetSkipRatio(luaSoftSparkSkip + engineConfiguration->useHardSkipInTraction ? 0 : tractionControlSparkSkip); + engine->hardSparkLimiter.setTargetSkipRatio(luaHardSparkSkip + engineConfiguration->useHardSkipInTraction ? tractionControlSparkSkip : 0); +} + void EngineState::periodicFastCallback() { ScopePerf perf(PE::EngineStatePeriodicFastCallback); diff --git a/firmware/controllers/algo/engine_state.h b/firmware/controllers/algo/engine_state.h index 8733340aad..f708e51371 100644 --- a/firmware/controllers/algo/engine_state.h +++ b/firmware/controllers/algo/engine_state.h @@ -19,6 +19,8 @@ public: void updateSlowSensors(); void updateTChargeK(int rpm, float tps); + void updateSparkSkip(); + /** * always 360 or 720, never zero */ diff --git a/firmware/controllers/lua/lua_hooks.cpp b/firmware/controllers/lua/lua_hooks.cpp index e9297db6b7..08a2c0d2c5 100644 --- a/firmware/controllers/lua/lua_hooks.cpp +++ b/firmware/controllers/lua/lua_hooks.cpp @@ -823,12 +823,14 @@ void configureRusefiLuaHooks(lua_State* lState) { #if EFI_LAUNCH_CONTROL lua_register(lState, "setSparkSkipRatio", [](lua_State* l) { auto targetSkipRatio = luaL_checknumber(l, 1); - engine->softSparkLimiter.setTargetSkipRatio(targetSkipRatio); + engine->engineState.luaSoftSparkSkip = targetSkipRatio; + engine->engineState.updateSparkSkip(); return 1; }); lua_register(lState, "setSparkHardSkipRatio", [](lua_State* l) { auto targetSkipRatio = luaL_checknumber(l, 1); - engine->hardSparkLimiter.setTargetSkipRatio(targetSkipRatio); + engine->engineState.luaHardSparkSkip = targetSkipRatio; + engine->engineState.updateSparkSkip(); return 1; }); #endif // EFI_LAUNCH_CONTROL