From 2d21796e59ab20a57f83f1cdb2a10de6b33c3504 Mon Sep 17 00:00:00 2001 From: Patryk Chmura Date: Sun, 25 Feb 2024 22:11:34 +0100 Subject: [PATCH] Launch control code rework --- firmware/controllers/algo/advance_map.cpp | 15 +++---- firmware/controllers/algo/launch_control.cpp | 41 +++++++++++++++----- firmware/controllers/algo/launch_control.h | 5 ++- firmware/tunerstudio/rusefi.input | 16 ++++---- 4 files changed, 52 insertions(+), 25 deletions(-) diff --git a/firmware/controllers/algo/advance_map.cpp b/firmware/controllers/algo/advance_map.cpp index 5909c94605..4ea90e1dbb 100644 --- a/firmware/controllers/algo/advance_map.cpp +++ b/firmware/controllers/algo/advance_map.cpp @@ -104,15 +104,16 @@ static angle_t getRunningAdvance(int rpm, float engineLoad) { #endif #if EFI_LAUNCH_CONTROL - if (engine->launchController.isLaunchCondition && engineConfiguration->enableLaunchRetard) { - if (engineConfiguration->launchSmoothRetard) { + if (engineConfiguration->enableLaunchRetard) { + if (engine->launchController.isLaunchPreCondition && engineConfiguration->launchSmoothRetard) { float launchAngle = engineConfiguration->launchTimingRetard; int launchRpm = engineConfiguration->launchRpm; - int launchRpmWithTimingRange = launchRpm + engineConfiguration->launchRpmWindow; - // interpolate timing from rpm at launch triggered to full retard at launch launchRpm + launchTimingRpmRange - return interpolateClamped(launchRpm, advanceAngle, launchRpmWithTimingRange, launchAngle, rpm); - } else { - return engineConfiguration->launchTimingRetard; + int launchRpmWithTimingWindow = launchRpm - engineConfiguration->launchRpmWindow; + // interpolate timing from rpm at launch triggered to full retard at launch launchRpm + float launchTimingInterpolated = interpolateClamped(launchRpmWithTimingWindow, advanceAngle, launchRpm, advanceAngle - launchAngle, rpm); + return launchTimingInterpolated; + } else if (engine->launchController.isLaunchCondition) { + return advanceAngle - engineConfiguration->launchTimingRetard; } } #endif /* EFI_LAUNCH_CONTROL */ diff --git a/firmware/controllers/algo/launch_control.cpp b/firmware/controllers/algo/launch_control.cpp index 838966ff6f..1724b51499 100644 --- a/firmware/controllers/algo/launch_control.cpp +++ b/firmware/controllers/algo/launch_control.cpp @@ -77,8 +77,16 @@ bool LaunchControlBase::isInsideTpsCondition() const { * Condition is true as soon as we are above LaunchRpm */ LaunchCondition LaunchControlBase::isInsideRPMCondition(int rpm) const { - int launchRpm = engineConfiguration->launchRpm; - return (launchRpm < rpm) ? LaunchCondition::Launch : LaunchCondition::NotMet; + auto launchRpm = engineConfiguration->launchRpm; + auto preLaunchRpm = launchRpm - engineConfiguration->launchRpmWindow; + + if (rpm >= launchRpm) { + return LaunchCondition::Launch; + } else if ((rpm >= preLaunchRpm) && (rpm < launchRpm)) { + return LaunchCondition::PreLaunch; + } else { + return LaunchCondition::NotMet; + } } LaunchCondition LaunchControlBase::isLaunchConditionMet(int rpm) { @@ -110,13 +118,7 @@ void LaunchControlBase::update() { combinedConditions = isLaunchConditionMet(rpm) == LaunchCondition::Launch; //and still recalculate in case user changed the values - retardThresholdRpm = engineConfiguration->launchRpm - /* - we never had UI for 'launchAdvanceRpmRange' so it was always zero. are we supposed to forget about this dead line - or it is supposed to be referencing 'launchTimingRpmRange'? - + (engineConfiguration->enableLaunchRetard ? engineConfiguration->launchAdvanceRpmRange : 0) -*/ - + engineConfiguration->launchRpmWindow; + retardThresholdRpm = engineConfiguration->launchRpm - (engineConfiguration->enableLaunchRetard ? engineConfiguration->launchRpmWindow : 0); if (!combinedConditions) { // conditions not met, reset timer @@ -126,10 +128,29 @@ void LaunchControlBase::update() { // If conditions are met... isLaunchCondition = m_launchTimer.hasElapsedSec(engineConfiguration->launchActivateDelay); } + + isLaunchPreCondition = combinedConditions = (isLaunchConditionMet(rpm) == LaunchCondition::PreLaunch);; + int targetLaunchSparkSkipPercent = engineConfiguration->launchSparkSkipPercent; + if (isLaunchPreCondition) { + m_preLaunchSparkSkipArmed = false; + + if (targetLaunchSparkSkipPercent > 0) { + int launchRpm = engineConfiguration->launchRpm; + int launchRpmWithWindow = launchRpm - engineConfiguration->launchRpmWindow; + int launchSparkSkipInterpolated = interpolateClamped(launchRpmWithWindow, 0, launchRpm, targetLaunchSparkSkipPercent, rpm); + float launchSparkSkip = ((float)launchSparkSkipInterpolated) / 100.0f; + engine->hardSparkLimiter.setTargetSkipRatio(launchSparkSkip); + } + } else { + if (m_preLaunchSparkSkipArmed == false) { + engine->hardSparkLimiter.setTargetSkipRatio(0); + m_preLaunchSparkSkipArmed = true; + } + } } bool LaunchControlBase::isLaunchRpmRetardCondition() const { - return isLaunchCondition && (retardThresholdRpm < Sensor::getOrZero(SensorType::Rpm)); + return (isLaunchCondition || isLaunchPreCondition) && (retardThresholdRpm < Sensor::getOrZero(SensorType::Rpm)); } bool LaunchControlBase::isLaunchSparkRpmRetardCondition() const { diff --git a/firmware/controllers/algo/launch_control.h b/firmware/controllers/algo/launch_control.h index 648a13b3b3..d0c5ed9e0f 100644 --- a/firmware/controllers/algo/launch_control.h +++ b/firmware/controllers/algo/launch_control.h @@ -13,6 +13,7 @@ void initLaunchControl(); enum class LaunchCondition { + PreLaunch, Launch, NotMet }; @@ -23,7 +24,7 @@ public: // Update the state of the launch control system void update(); - float getFuelCoefficient() const; + float getFuelCoefficient() const; bool isInsideSpeedCondition() const; bool isInsideTpsCondition() const; bool isInsideSwitchCondition(); @@ -37,6 +38,7 @@ private: bool isLaunchRpmRetardCondition() const; Timer m_launchTimer; + bool m_preLaunchSparkSkipArmed = false; }; /** @@ -49,6 +51,7 @@ public: * targetSkipRatio of '0' means 'do not skip', would always return false */ void setTargetSkipRatio(float targetSkipRatio); + float getTargetSkipRatio() { return targetSkipRatio; }; bool shouldSkip(); private: diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 6901960227..6b828213e5 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -4668,18 +4668,20 @@ dialog = tcuControls, "Transmission Settings" field = "" ; dead code field = "Rpm Threshold", launchRpmThreshold, {launchControlEnabled == 1} - field = "Speed Threshold", launchSpeedThreshold, {launchControlEnabled == 1} + field = "Speed Threshold", launchSpeedThreshold, {launchControlEnabled == 1} field = "" - field = "Launch RPM", launchRpm, {launchControlEnabled == 1} + field = "Launch RPM", launchRpm, {launchControlEnabled == 1} field = "Launch Control Window", launchRpmWindow, {launchControlEnabled == 1} - field = "TPS Threshold", launchTpsThreshold, {launchControlEnabled == 1} - field = "Ignition Retard enable", enableLaunchRetard, {launchControlEnabled == 1} + ;field = "Boost Solenoid Duty", launchBoostDuty, {launchControlEnabled == 1} + field = "TPS Threshold", launchTpsThreshold, {launchControlEnabled == 1} + field = "Ignition Retard enable", enableLaunchRetard, {launchControlEnabled == 1} field = "Ignition Retard", launchTimingRetard, {launchControlEnabled == 1 && enableLaunchRetard == 1} - field = "Fuel Added %", launchFuelAdderPercent, {launchControlEnabled == 1} - field = "Smooth Retard Mode", launchSmoothRetard, {launchControlEnabled == 1 && enableLaunchRetard == 1} + field = "Fuel Added %", launchFuelAdderPercent, {launchControlEnabled == 1} + field = "Smooth Retard Mode", launchSmoothRetard, {launchControlEnabled == 1 && enableLaunchRetard == 1} field = "Hard Cut Mode" - field = "Ignition Cut", launchSparkCutEnable, {launchControlEnabled == 1} field = "Fuel Cut", launchFuelCutEnable, {launchControlEnabled == 1} + field = "Ignition Cut", launchSparkCutEnable, {launchControlEnabled == 1} + field = "Spark Skip Transition Target %", launchSparkSkipPercent, {launchControlEnabled == 1} dialog = smLaunchControl, "", border