Launch Control refactoring (#1992)

* refactor

- called from periodicFastCallback
- removed defines

* Update rusefi.input

removed unused configurations.
added clutch inversion option

* Added new tests

fixed limiting only in case we have launch condition and rpm outside of window

* Update launch_control.cpp

Unintialized config update, now it is working fine with VSS and with clutch as well.

* small fixes

updated after review findings

* Fix breaking engine rev limiter

applyLaunchControlLimiting should not overwrite booleans to false!

* Delay timer in seconds

timer uses ms, so convert seconds to ms
This commit is contained in:
shadowm60 2020-12-01 20:03:42 +02:00 committed by GitHub
parent cdd2527f37
commit 6fb745d29c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 109 additions and 42 deletions

View File

@ -18,6 +18,8 @@
#include "perf_trace.h"
#include "closed_loop_fuel.h"
#include "sensor.h"
#include "launch_control.h"
#if EFI_PROD_CODE
#include "svnversion.h"
@ -174,6 +176,11 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
float ignitionLoad = getIgnitionLoad(PASS_ENGINE_PARAMETER_SIGNATURE);
timingAdvance = getAdvance(rpm, ignitionLoad PASS_ENGINE_PARAMETER_SUFFIX);
multispark.count = getMultiSparkCount(rpm PASS_ENGINE_PARAMETER_SUFFIX);
#if EFI_LAUNCH_CONTROL
updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE);
#endif //EFI_LAUNCH_CONTROL
#endif // EFI_ENGINE_CONTROL
}

View File

@ -24,8 +24,11 @@
#include "engine_state.h"
#include "advance_map.h"
static bool isInit = false;
static Logging *logger;
LaunchControlBase launchInstance;
#if EFI_TUNER_STUDIO
#include "tunerstudio_outputs.h"
extern TunerStudioOutputChannels tsOutputChannels;
@ -33,22 +36,8 @@ extern TunerStudioOutputChannels tsOutputChannels;
EXTERN_ENGINE;
#define RETART_THD_CALC CONFIG(launchRpm) +\
(CONFIG(enableLaunchRetard) ? CONFIG(launchAdvanceRpmRange) : 0) +\
CONFIG(hardCutRpmRange)
static int retardThresholdRpm;
class LaunchControlImpl : public LaunchControlBase, public PeriodicTimerController {
int getPeriodMs() override {
return 50;
}
void PeriodicTask() {
update();
}
};
/**
* We can have active condition from switch or from clutch.
* In case we are dependent on VSS we just return true.
@ -90,7 +79,8 @@ bool LaunchControlBase::isInsideSwitchCondition() const {
*/
bool LaunchControlBase::isInsideSpeedCondition() const {
int speed = getVehicleSpeed();
return (CONFIG(launchSpeedTreshold) > speed) || !engineConfiguration->launchDisableBySpeed;
return (CONFIG(launchSpeedTreshold) > speed) || (!(CONFIG(launchActivationMode) == ALWAYS_ACTIVE_LAUNCH));
}
/**
@ -134,21 +124,30 @@ bool LaunchControlBase::isLaunchConditionMet(int rpm) const {
return speedCondition && activateSwitchCondition && rpmCondition && tpsCondition;
}
void updateLaunchConditions(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
launchInstance.update();
}
void LaunchControlBase::update() {
if (!CONFIG(launchControlEnabled)) {
return;
}
#if ! EFI_UNIT_TEST
if(!isInit) {
return;
}
#endif
int rpm = GET_RPM();
bool combinedConditions = isLaunchConditionMet(rpm);
float timeDelay = CONFIG(launchActivateDelay);
int cutRpmRange = CONFIG(hardCutRpmRange);
int launchAdvanceRpmRange = CONFIG(launchTimingRpmRange);
//recalculate in periodic task, this way we save time in applyLaunchControlLimiting
//and still recalculat in case user changed the values
retardThresholdRpm = RETART_THD_CALC;
retardThresholdRpm = CONFIG(launchRpm) + (CONFIG(enableLaunchRetard) ?
CONFIG(launchAdvanceRpmRange) : 0) + CONFIG(hardCutRpmRange);
if (!combinedConditions) {
// conditions not met, reset timer
@ -159,7 +158,7 @@ void LaunchControlBase::update() {
engine->applyLaunchExtraFuel = false;
} else {
// If conditions are met...
if (m_launchTimer.hasElapsedMs(timeDelay) && combinedConditions) {
if (m_launchTimer.hasElapsedMs(timeDelay*1000) && combinedConditions) {
engine->isLaunchCondition = true; // ...enable launch!
engine->applyLaunchExtraFuel = true;
}
@ -181,8 +180,6 @@ void LaunchControlBase::update() {
#endif /* EFI_TUNER_STUDIO */
}
static LaunchControlImpl Launch;
void setDefaultLaunchParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
engineConfiguration->launchRpm = 4000; // Rpm to trigger Launch condition
engineConfiguration->launchTimingRetard = 10; // retard in absolute degrees ATDC
@ -198,20 +195,21 @@ void setDefaultLaunchParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
engineConfiguration->enableLaunchBoost = true;
engineConfiguration->launchSmoothRetard = true; //interpolates the advance linear from launchrpm to fully retarded at launchtimingrpmrange
engineConfiguration->antiLagRpmTreshold = 3000;
}
void applyLaunchControlLimiting(bool *limitedSpark, bool *limitedFuel DECLARE_ENGINE_PARAMETER_SUFFIX) {
if (retardThresholdRpm < GET_RPM()) {
if (( engine->isLaunchCondition ) && ( retardThresholdRpm < GET_RPM() )) {
*limitedSpark = engineConfiguration->launchSparkCutEnable;
*limitedFuel = engineConfiguration->launchFuelCutEnable;
}
}
}
void initLaunchControl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
logger = sharedLogger;
retardThresholdRpm = RETART_THD_CALC;
Launch.Start();
INJECT_ENGINE_REFERENCE(&launchInstance);
isInit = true;
}
#endif /* EFI_LAUNCH_CONTROL */

View File

@ -14,6 +14,7 @@ class Logging;
void initLaunchControl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
void setDefaultLaunchParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE);
void applyLaunchControlLimiting(bool *limitedSpark, bool *limitedFuel DECLARE_ENGINE_PARAMETER_SUFFIX);
void updateLaunchConditions(DECLARE_ENGINE_PARAMETER_SIGNATURE);
class LaunchControlBase {
public:
@ -26,7 +27,6 @@ public:
bool isInsideTpsCondition() const;
bool isInsideSwitchCondition() const;
bool isInsideRPMCondition(int rpm) const;
bool isLaunchConditionMet(int rpm) const;
private:

View File

@ -3277,13 +3277,14 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
field = "Activation Mode", launchActivationMode
field = "Switch Input", launchActivatePin, {launchActivationMode == 0 && launchControlEnabled == 1}
field = "Clutch Input", clutchDownPin, {launchActivationMode == 1 && launchControlEnabled == 1}
field = "Clutch Input inverted", clutchDownPinMode, {launchActivationMode == 1 && launchControlEnabled == 1}
field = ""
field = "Rpm Treshold", launchRpmTreshold, {launchControlEnabled == 1}
field = "Speed Treshold", launchSpeedTreshold, {launchControlEnabled == 1}
field = ""
field = "Launch RPM", launchRpm, {launchControlEnabled == 1}
field = "Extra Fuel", launchFuelAdded, {launchControlEnabled == 1}
field = "Boost Solenoid Duty", launchBoostDuty, {launchControlEnabled == 1}
;field = "Extra Fuel", launchFuelAdded, {launchControlEnabled == 1}
;field = "Boost Solenoid Duty", launchBoostDuty, {launchControlEnabled == 1}
field = "Ignition Retard enable", enableLaunchRetard, {launchControlEnabled == 1}
field = "Ignition Retard", launchTimingRetard, {launchControlEnabled == 1}
field = "Ignition Retard RPM Range", launchTimingRpmRange, {launchControlEnabled == 1}

View File

@ -34,6 +34,7 @@ TEST(LaunchControl, VSSCondition) {
INJECT_ENGINE_REFERENCE(&dut);
// Test Speed trashold
engineConfiguration->launchActivationMode = ALWAYS_ACTIVE_LAUNCH;
engineConfiguration->launchSpeedTreshold = 30;
engineConfiguration->launchDisableBySpeed = 1;
setMockVehicleSpeed(10);
@ -42,15 +43,6 @@ TEST(LaunchControl, VSSCondition) {
setMockVehicleSpeed(40);
EXPECT_FALSE(dut.isInsideSpeedCondition());
//we do not want to disable launch by speed
engineConfiguration->launchSpeedTreshold = 30;
engineConfiguration->launchDisableBySpeed = 0;
setMockVehicleSpeed(10.0);
EXPECT_TRUE(dut.isInsideSpeedCondition());
setMockVehicleSpeed(40.0);
EXPECT_TRUE(dut.isInsideSpeedCondition());
}
TEST(LaunchControl, RPMCondition) {
@ -73,11 +65,11 @@ TEST(LaunchControl, SwitchInputCondition) {
INJECT_ENGINE_REFERENCE(&dut);
//activation based on VSS
engineConfiguration->launchActivationMode=ALWAYS_ACTIVE_LAUNCH;
engineConfiguration->launchActivationMode = ALWAYS_ACTIVE_LAUNCH;
EXPECT_TRUE(dut.isInsideSwitchCondition());
//active by switch
engineConfiguration->launchActivationMode=SWITCH_INPUT_LAUNCH;
engineConfiguration->launchActivationMode = SWITCH_INPUT_LAUNCH;
engineConfiguration->launchActivatePin = GPIOG_1;
setMockState(engineConfiguration->launchActivatePin, true);
EXPECT_TRUE(dut.isInsideSwitchCondition());
@ -86,7 +78,7 @@ TEST(LaunchControl, SwitchInputCondition) {
EXPECT_FALSE(dut.isInsideSwitchCondition());
//by clutch
engineConfiguration->launchActivationMode=CLUTCH_INPUT_LAUNCH;
engineConfiguration->launchActivationMode = CLUTCH_INPUT_LAUNCH;
engineConfiguration->clutchDownPin = GPIOG_2;
engineConfiguration->clutchDownPinMode = PI_PULLUP;
setMockState(engineConfiguration->clutchDownPin, true);
@ -131,3 +123,72 @@ TEST(LaunchControl, CombinedCondition) {
EXPECT_FALSE(dut.isLaunchConditionMet(3200));
}
TEST(LaunchControl, CompleteRun) {
bool spark, fuel;
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
LoggingWithStorage logger("test");
initLaunchControl(&logger,PASS_ENGINE_PARAMETER_SIGNATURE);
//load default config
setDefaultLaunchParameters(PASS_CONFIG_PARAMETER_SIGNATURE);
//check VSS normal usage
engineConfiguration->launchActivationMode = ALWAYS_ACTIVE_LAUNCH;
engineConfiguration->launchSpeedTreshold = 30;
engineConfiguration->launchDisableBySpeed = 1;
engineConfiguration->launchRpm = 3000;
engineConfiguration->launchTpsTreshold = 10;
engineConfiguration->launchControlEnabled = 1;
//valid TPS
Sensor::setMockValue(SensorType::DriverThrottleIntent, 20.0f);
setMockVehicleSpeed(10);
engine->rpmCalculator.mockRpm = 1200;
//update condition check
updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE);
//check if we have some sort of cut? we should not have at this point
spark = false;
fuel = false;
applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX);
EXPECT_FALSE(spark);
EXPECT_FALSE(fuel);
engine->rpmCalculator.mockRpm = 3510;
//update condition check
updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE);
//we have a 3 seconds delay to actually enable it!
eth.smartMoveTimeForwardSeconds(1);
updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE);
spark = false;
fuel = false;
applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX);
EXPECT_FALSE(spark);
EXPECT_FALSE(fuel);
eth.smartMoveTimeForwardSeconds(3);
updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE);
spark = false;
fuel = false;
applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX);
EXPECT_TRUE(spark);
EXPECT_FALSE(fuel);
setMockVehicleSpeed(40);
updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE);
spark = false;
fuel = false;
applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX);
EXPECT_FALSE(spark);
EXPECT_FALSE(fuel);
}