diff --git a/firmware/controllers/algo/launch_control.cpp b/firmware/controllers/algo/launch_control.cpp index 4a640ace63..630917ba60 100644 --- a/firmware/controllers/algo/launch_control.cpp +++ b/firmware/controllers/algo/launch_control.cpp @@ -3,6 +3,7 @@ * * @date 10. sep. 2019 * Author: Ola Ruud + * Rework: Patryk Chmura */ #include "pch.h" @@ -75,19 +76,19 @@ bool LaunchControlBase::isInsideTpsCondition() const { /** * Condition is true as soon as we are above LaunchRpm */ -bool LaunchControlBase::isInsideRPMCondition(int rpm) const { +LaunchCondition LaunchControlBase::isInsideRPMCondition(int rpm) const { int launchRpm = engineConfiguration->launchRpm; - return (launchRpm < rpm); + return (launchRpm < rpm) ? LaunchCondition::Launch : LaunchCondition::NotMet; } -bool LaunchControlBase::isLaunchConditionMet(int rpm) { - +LaunchCondition LaunchControlBase::isLaunchConditionMet(int rpm) { + LaunchCondition rpmLaunchCondition = isInsideRPMCondition(rpm); activateSwitchCondition = isInsideSwitchCondition(); - rpmCondition = isInsideRPMCondition(rpm); + rpmCondition = (rpmLaunchCondition == LaunchCondition::Launch); speedCondition = isInsideSpeedCondition(); tpsCondition = isInsideTpsCondition(); - return speedCondition && activateSwitchCondition && rpmCondition && tpsCondition; + return ((speedCondition && activateSwitchCondition && tpsCondition) == true) ? rpmLaunchCondition : LaunchCondition::NotMet; } LaunchControlBase::LaunchControlBase() { @@ -106,7 +107,7 @@ void LaunchControlBase::update() { } int rpm = Sensor::getOrZero(SensorType::Rpm); - combinedConditions = isLaunchConditionMet(rpm); + combinedConditions = isLaunchConditionMet(rpm) == LaunchCondition::Launch; //and still recalculate in case user changed the values retardThresholdRpm = engineConfiguration->launchRpm diff --git a/firmware/controllers/algo/launch_control.h b/firmware/controllers/algo/launch_control.h index 74387acae0..648a13b3b3 100644 --- a/firmware/controllers/algo/launch_control.h +++ b/firmware/controllers/algo/launch_control.h @@ -12,6 +12,11 @@ void initLaunchControl(); +enum class LaunchCondition { + Launch, + NotMet +}; + class LaunchControlBase : public launch_control_state_s { public: LaunchControlBase(); @@ -22,8 +27,8 @@ public: bool isInsideSpeedCondition() const; bool isInsideTpsCondition() const; bool isInsideSwitchCondition(); - bool isInsideRPMCondition(int rpm) const; - bool isLaunchConditionMet(int rpm); + LaunchCondition isInsideRPMCondition(int rpm) const; + LaunchCondition isLaunchConditionMet(int rpm); bool isLaunchSparkRpmRetardCondition() const; bool isLaunchFuelRpmRetardCondition() const; diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 55713bd54e..cc7e3e6c8b 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -483,7 +483,7 @@ MAP_sensor_config_s map;@see isMapAveragingEnabled ThermistorConf clt;todo: merge with channel settings, use full-scale Thermistor here! ThermistorConf iat; - int launchTimingRetard;;"deg", 1, 0, -180, 180, 2 + float launchTimingRetard;;"deg", 1, 0, -180, 180, 2 int hip9011PrescalerAndSDO;value '6' for 8MHz hw osc\nread hip9011 datasheet for details\ntodo split into two bit fields;"integer", 1, 0, 0, 32, 0 float knockBandCustom;We calculate knock band based of cylinderBore\n Use this to override - kHz knock band override\nRequires power cycling to effect;"kHz", 1, 0, 0, 20, 2 diff --git a/unit_tests/tests/test_launch.cpp b/unit_tests/tests/test_launch.cpp index e132bab3be..1f894520b2 100644 --- a/unit_tests/tests/test_launch.cpp +++ b/unit_tests/tests/test_launch.cpp @@ -78,9 +78,9 @@ TEST(LaunchControl, RPMCondition) { engineConfiguration->launchRpm = 3000; - EXPECT_FALSE(dut.isInsideRPMCondition(2900)); + EXPECT_EQ(dut.isInsideRPMCondition(2900), LaunchCondition::NotMet); - EXPECT_TRUE(dut.isInsideRPMCondition(3100)); + EXPECT_EQ(dut.isInsideRPMCondition(3100), LaunchCondition::Launch); } TEST(LaunchControl, SwitchInputCondition) { @@ -141,13 +141,13 @@ TEST(LaunchControl, CombinedCondition) { Sensor::setMockValue(SensorType::VehicleSpeed, 10.0); Sensor::setMockValue(SensorType::Rpm, 1200); - EXPECT_FALSE(dut.isLaunchConditionMet(1200)); + EXPECT_EQ(dut.isLaunchConditionMet(1200), LaunchCondition::NotMet); - Sensor::setMockValue(SensorType::Rpm, 3200); - EXPECT_TRUE(dut.isLaunchConditionMet(3200)); + Sensor::setMockValue(SensorType::Rpm, 3200); + EXPECT_EQ(dut.isLaunchConditionMet(3200), LaunchCondition::Launch); Sensor::setMockValue(SensorType::VehicleSpeed, 40.0); - EXPECT_FALSE(dut.isLaunchConditionMet(3200)); + EXPECT_EQ(dut.isLaunchConditionMet(3200), LaunchCondition::NotMet); }