2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2020-11-19 05:15:56 -08:00
|
|
|
#include "launch_control.h"
|
|
|
|
|
|
|
|
TEST(LaunchControl, TpsCondition) {
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
|
|
|
|
LaunchControlBase dut;
|
2021-11-15 03:44:40 -08:00
|
|
|
dut.inject(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-11-19 05:15:56 -08:00
|
|
|
|
|
|
|
engineConfiguration->launchTpsTreshold = 10;
|
|
|
|
|
|
|
|
// Should return false with failed sensor
|
|
|
|
Sensor::resetMockValue(SensorType::DriverThrottleIntent);
|
|
|
|
EXPECT_FALSE(dut.isInsideTpsCondition());
|
|
|
|
|
|
|
|
// Should return false when throttle is closed
|
|
|
|
Sensor::setMockValue(SensorType::DriverThrottleIntent, 5.0f);
|
|
|
|
EXPECT_FALSE(dut.isInsideTpsCondition());
|
|
|
|
|
|
|
|
// Should return true when throttle is opened past the threshold
|
|
|
|
Sensor::setMockValue(SensorType::DriverThrottleIntent, 20.0f);
|
|
|
|
EXPECT_TRUE(dut.isInsideTpsCondition());
|
|
|
|
}
|
2020-11-19 18:14:38 -08:00
|
|
|
|
|
|
|
|
|
|
|
TEST(LaunchControl, VSSCondition) {
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
|
|
|
|
LaunchControlBase dut;
|
2021-11-15 03:44:40 -08:00
|
|
|
dut.inject(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-11-19 18:14:38 -08:00
|
|
|
|
|
|
|
// Test Speed trashold
|
2020-12-01 10:03:42 -08:00
|
|
|
engineConfiguration->launchActivationMode = ALWAYS_ACTIVE_LAUNCH;
|
2021-11-15 18:13:01 -08:00
|
|
|
engineConfiguration->launchSpeedThreshold = 30;
|
|
|
|
|
2021-08-12 12:16:51 -07:00
|
|
|
Sensor::setMockValue(SensorType::VehicleSpeed, 10.0);
|
2020-11-19 18:14:38 -08:00
|
|
|
EXPECT_TRUE(dut.isInsideSpeedCondition());
|
|
|
|
|
2021-08-12 12:16:51 -07:00
|
|
|
Sensor::setMockValue(SensorType::VehicleSpeed, 40.0);
|
2020-11-19 18:14:38 -08:00
|
|
|
EXPECT_FALSE(dut.isInsideSpeedCondition());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LaunchControl, RPMCondition) {
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
|
|
|
|
LaunchControlBase dut;
|
2021-11-15 03:44:40 -08:00
|
|
|
dut.inject(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-11-19 18:14:38 -08:00
|
|
|
|
|
|
|
engineConfiguration->launchRpm = 3000;
|
|
|
|
|
|
|
|
EXPECT_FALSE(dut.isInsideRPMCondition(2900));
|
|
|
|
|
|
|
|
EXPECT_TRUE(dut.isInsideRPMCondition(3100));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LaunchControl, SwitchInputCondition) {
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
|
|
|
|
LaunchControlBase dut;
|
2021-11-15 03:44:40 -08:00
|
|
|
dut.inject(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-11-19 18:14:38 -08:00
|
|
|
|
|
|
|
//activation based on VSS
|
2020-12-01 10:03:42 -08:00
|
|
|
engineConfiguration->launchActivationMode = ALWAYS_ACTIVE_LAUNCH;
|
2020-11-19 18:14:38 -08:00
|
|
|
EXPECT_TRUE(dut.isInsideSwitchCondition());
|
|
|
|
|
|
|
|
//active by switch
|
2020-12-01 10:03:42 -08:00
|
|
|
engineConfiguration->launchActivationMode = SWITCH_INPUT_LAUNCH;
|
2020-11-19 18:14:38 -08:00
|
|
|
engineConfiguration->launchActivatePin = GPIOG_1;
|
|
|
|
setMockState(engineConfiguration->launchActivatePin, true);
|
|
|
|
EXPECT_TRUE(dut.isInsideSwitchCondition());
|
|
|
|
|
|
|
|
setMockState(engineConfiguration->launchActivatePin, false);
|
|
|
|
EXPECT_FALSE(dut.isInsideSwitchCondition());
|
|
|
|
|
|
|
|
//by clutch
|
2020-12-01 10:03:42 -08:00
|
|
|
engineConfiguration->launchActivationMode = CLUTCH_INPUT_LAUNCH;
|
2020-11-19 18:14:38 -08:00
|
|
|
engineConfiguration->clutchDownPin = GPIOG_2;
|
|
|
|
engineConfiguration->clutchDownPinMode = PI_PULLUP;
|
|
|
|
setMockState(engineConfiguration->clutchDownPin, true);
|
2021-07-24 16:49:23 -07:00
|
|
|
engine->updateSwitchInputs(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-11-19 18:14:38 -08:00
|
|
|
EXPECT_TRUE(dut.isInsideSwitchCondition());
|
|
|
|
|
|
|
|
setMockState(engineConfiguration->clutchDownPin, false);
|
2021-07-24 16:49:23 -07:00
|
|
|
engine->updateSwitchInputs(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-11-19 18:14:38 -08:00
|
|
|
EXPECT_FALSE(dut.isInsideSwitchCondition());
|
|
|
|
|
|
|
|
engineConfiguration->clutchDownPinMode = PI_PULLDOWN;
|
2021-07-24 16:49:23 -07:00
|
|
|
engineConfiguration->clutchDownPinInverted = true;
|
2020-11-19 18:14:38 -08:00
|
|
|
setMockState(engineConfiguration->clutchDownPin, false);
|
2021-07-24 16:49:23 -07:00
|
|
|
engine->updateSwitchInputs(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-11-19 18:14:38 -08:00
|
|
|
EXPECT_TRUE(dut.isInsideSwitchCondition());
|
|
|
|
|
|
|
|
setMockState(engineConfiguration->clutchDownPin, true);
|
2021-07-24 16:49:23 -07:00
|
|
|
engine->updateSwitchInputs(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-11-19 18:14:38 -08:00
|
|
|
EXPECT_FALSE(dut.isInsideSwitchCondition());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LaunchControl, CombinedCondition) {
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
|
|
|
|
LaunchControlBase dut;
|
2021-11-15 03:44:40 -08:00
|
|
|
dut.inject(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-11-19 18:14:38 -08:00
|
|
|
|
|
|
|
//check VSS normal usage
|
2021-11-15 18:13:01 -08:00
|
|
|
engineConfiguration->launchActivationMode = ALWAYS_ACTIVE_LAUNCH;
|
|
|
|
|
2020-11-19 18:14:38 -08:00
|
|
|
engineConfiguration->launchRpm = 3000;
|
|
|
|
engineConfiguration->launchTpsTreshold = 10;
|
|
|
|
//valid TPS
|
|
|
|
Sensor::setMockValue(SensorType::DriverThrottleIntent, 20.0f);
|
|
|
|
|
2021-08-12 12:16:51 -07:00
|
|
|
Sensor::setMockValue(SensorType::VehicleSpeed, 10.0);
|
2020-11-19 18:14:38 -08:00
|
|
|
engine->rpmCalculator.mockRpm = 1200;
|
|
|
|
|
|
|
|
EXPECT_FALSE(dut.isLaunchConditionMet(1200));
|
|
|
|
|
|
|
|
engine->rpmCalculator.mockRpm = 3200;
|
|
|
|
EXPECT_TRUE(dut.isLaunchConditionMet(3200));
|
|
|
|
|
2021-08-12 12:16:51 -07:00
|
|
|
Sensor::setMockValue(SensorType::VehicleSpeed, 40.0);
|
2020-11-19 18:14:38 -08:00
|
|
|
EXPECT_FALSE(dut.isLaunchConditionMet(3200));
|
|
|
|
|
|
|
|
}
|
2020-12-01 10:03:42 -08:00
|
|
|
|
2021-11-15 18:13:01 -08:00
|
|
|
static void setDefaultLaunchParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
|
|
|
engineConfiguration->launchRpm = 4000; // Rpm to trigger Launch condition
|
|
|
|
// engineConfiguration->launchTimingRetard = 10; // retard in absolute degrees ATDC
|
|
|
|
engineConfiguration->launchTimingRpmRange = 500; // Rpm above Launch triggered for full retard
|
|
|
|
engineConfiguration->launchSparkCutEnable = true;
|
|
|
|
engineConfiguration->launchFuelCutEnable = false;
|
|
|
|
engineConfiguration->hardCutRpmRange = 500; //Rpm above Launch triggered +(if retard enabled) launchTimingRpmRange to hard cut
|
|
|
|
engineConfiguration->launchSpeedThreshold = 10; //maximum speed allowed before disable launch
|
|
|
|
engineConfiguration->launchFuelAdded = 10; // Extra fuel in % when launch are triggered
|
|
|
|
engineConfiguration->launchBoostDuty = 70; // boost valve duty cycle at launch
|
|
|
|
engineConfiguration->launchActivateDelay = 3; // Delay in seconds for launch to kick in
|
|
|
|
// engineConfiguration->enableLaunchRetard = true;
|
|
|
|
// dead code todo engineConfiguration->enableLaunchBoost = true;
|
|
|
|
engineConfiguration->launchSmoothRetard = true; //interpolates the advance linear from launchrpm to fully retarded at launchtimingrpmrange
|
|
|
|
// dead code todo engineConfiguration->antiLagRpmTreshold = 3000;
|
|
|
|
}
|
|
|
|
|
2020-12-01 10:03:42 -08:00
|
|
|
TEST(LaunchControl, CompleteRun) {
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
|
2021-04-20 11:09:41 -07:00
|
|
|
initLaunchControl(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-12-01 10:03:42 -08:00
|
|
|
|
|
|
|
//load default config
|
|
|
|
setDefaultLaunchParameters(PASS_CONFIG_PARAMETER_SIGNATURE);
|
|
|
|
|
|
|
|
//check VSS normal usage
|
|
|
|
engineConfiguration->launchActivationMode = ALWAYS_ACTIVE_LAUNCH;
|
2021-11-15 18:13:01 -08:00
|
|
|
engineConfiguration->launchSpeedThreshold = 30;
|
|
|
|
|
2020-12-01 10:03:42 -08:00
|
|
|
engineConfiguration->launchRpm = 3000;
|
|
|
|
engineConfiguration->launchTpsTreshold = 10;
|
2021-11-15 18:13:01 -08:00
|
|
|
engineConfiguration->launchControlEnabled = true;
|
2020-12-01 10:03:42 -08:00
|
|
|
//valid TPS
|
|
|
|
Sensor::setMockValue(SensorType::DriverThrottleIntent, 20.0f);
|
|
|
|
|
2021-08-12 12:16:51 -07:00
|
|
|
Sensor::setMockValue(SensorType::VehicleSpeed, 10.0);
|
2020-12-01 10:03:42 -08:00
|
|
|
engine->rpmCalculator.mockRpm = 1200;
|
|
|
|
|
2021-11-15 15:57:12 -08:00
|
|
|
engine->launchController.update();
|
|
|
|
|
2020-12-01 10:03:42 -08:00
|
|
|
|
|
|
|
//check if we have some sort of cut? we should not have at this point
|
2021-11-15 16:54:34 -08:00
|
|
|
EXPECT_FALSE(engine->launchController.isLaunchSparkRpmRetardCondition());
|
|
|
|
EXPECT_FALSE(engine->launchController.isLaunchFuelRpmRetardCondition());
|
2020-12-01 10:03:42 -08:00
|
|
|
|
|
|
|
|
|
|
|
engine->rpmCalculator.mockRpm = 3510;
|
|
|
|
//update condition check
|
2021-11-15 15:57:12 -08:00
|
|
|
engine->launchController.update();
|
2020-12-01 10:03:42 -08:00
|
|
|
|
|
|
|
|
|
|
|
//we have a 3 seconds delay to actually enable it!
|
2021-03-11 21:43:48 -08:00
|
|
|
eth.moveTimeForwardAndInvokeEventsSec(1);
|
2021-11-15 15:57:12 -08:00
|
|
|
engine->launchController.update();
|
2020-12-01 10:03:42 -08:00
|
|
|
|
2021-11-15 16:54:34 -08:00
|
|
|
EXPECT_FALSE(engine->launchController.isLaunchSparkRpmRetardCondition());
|
|
|
|
EXPECT_FALSE(engine->launchController.isLaunchFuelRpmRetardCondition());
|
2020-12-01 10:03:42 -08:00
|
|
|
|
2021-03-11 21:43:48 -08:00
|
|
|
eth.moveTimeForwardAndInvokeEventsSec(3);
|
2021-11-15 15:57:12 -08:00
|
|
|
engine->launchController.update();
|
2020-12-01 10:03:42 -08:00
|
|
|
|
2021-11-15 16:54:34 -08:00
|
|
|
|
|
|
|
EXPECT_TRUE(engine->launchController.isLaunchSparkRpmRetardCondition());
|
|
|
|
EXPECT_FALSE(engine->launchController.isLaunchFuelRpmRetardCondition());
|
2020-12-01 10:03:42 -08:00
|
|
|
|
2021-08-12 12:16:51 -07:00
|
|
|
Sensor::setMockValue(SensorType::VehicleSpeed, 40.0);
|
2021-11-15 15:57:12 -08:00
|
|
|
engine->launchController.update();
|
2021-11-15 16:54:34 -08:00
|
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(engine->launchController.isLaunchSparkRpmRetardCondition());
|
|
|
|
EXPECT_FALSE(engine->launchController.isLaunchFuelRpmRetardCondition());
|
2020-12-01 10:03:42 -08:00
|
|
|
|
|
|
|
}
|