refactoring launch

This commit is contained in:
Andrey 2021-11-15 18:57:12 -05:00
parent 34015eceee
commit 4002c92dcc
6 changed files with 16 additions and 24 deletions

View File

@ -23,6 +23,7 @@
#include "ac_control.h"
#include "knock_logic.h"
#include "idle_state_generated.h"
#include "launch_control.h"
#if EFI_SIGNAL_EXECUTOR_ONE_TIMER
// PROD real firmware uses this implementation
@ -109,6 +110,7 @@ public:
cyclic_buffer<int> triggerErrorDetection;
GearControllerBase *gearController;
LaunchControlBase launchController;
efitick_t mostRecentSparkEvent;
efitick_t mostRecentTimeBetweenSparkEvents;

View File

@ -169,7 +169,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
multispark.count = getMultiSparkCount(rpm PASS_ENGINE_PARAMETER_SUFFIX);
#if EFI_LAUNCH_CONTROL
updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE);
engine->launchController.update();
#endif //EFI_LAUNCH_CONTROL
engine->limpManager.updateState(rpm, nowNt);

View File

@ -17,8 +17,6 @@
static bool isInit = false;
LaunchControlBase launchInstance;
/**
* We can have active condition from switch or from clutch.
* In case we are dependent on VSS we just return true.
@ -98,10 +96,6 @@ 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)) {
@ -180,7 +174,7 @@ void LaunchControlBase::applyLaunchControlLimiting(bool *limitedSpark, bool *lim
}
void initLaunchControl(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
launchInstance.inject(PASS_ENGINE_PARAMETER_SIGNATURE);
engine->launchController.inject(PASS_ENGINE_PARAMETER_SIGNATURE);
isInit = true;
}

View File

@ -13,8 +13,6 @@
void initLaunchControl(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void setDefaultLaunchParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE);
void updateLaunchConditions(DECLARE_ENGINE_PARAMETER_SIGNATURE);
class LaunchControlBase : public EnginePtr {
public:
// Update the state of the launch control system

View File

@ -49,8 +49,6 @@
#include "backup_ram.h"
extern LaunchControlBase launchInstance;
// todo: figure out if this even helps?
//#if defined __GNUC__
//#define RAM_METHOD_PREFIX __attribute__((section(".ram")))
@ -418,7 +416,7 @@ void mainTriggerCallback(uint32_t trgEventIndex, efitick_t edgeTimestamp DECLARE
#if EFI_LAUNCH_CONTROL
if (engine->isLaunchCondition && !limitedSpark && !limitedFuel) {
/* in case we are not already on a limited conditions, check launch as well */
launchInstance.applyLaunchControlLimiting(&limitedSpark, &limitedFuel PASS_ENGINE_PARAMETER_SUFFIX);
engine->launchController.applyLaunchControlLimiting(&limitedSpark, &limitedFuel PASS_ENGINE_PARAMETER_SUFFIX);
}
#endif
if (trgEventIndex == 0) {

View File

@ -130,7 +130,6 @@ TEST(LaunchControl, CompleteRun) {
bool spark, fuel;
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
extern LaunchControlBase launchInstance;
initLaunchControl(PASS_ENGINE_PARAMETER_SIGNATURE);
//load default config
@ -149,46 +148,47 @@ TEST(LaunchControl, CompleteRun) {
Sensor::setMockValue(SensorType::VehicleSpeed, 10.0);
engine->rpmCalculator.mockRpm = 1200;
//update condition check
updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE);
engine->launchController.update();
//check if we have some sort of cut? we should not have at this point
spark = false;
fuel = false;
launchInstance.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX);
engine->launchController.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);
engine->launchController.update();
//we have a 3 seconds delay to actually enable it!
eth.moveTimeForwardAndInvokeEventsSec(1);
updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE);
engine->launchController.update();
spark = false;
fuel = false;
launchInstance.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX);
engine->launchController.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX);
EXPECT_FALSE(spark);
EXPECT_FALSE(fuel);
eth.moveTimeForwardAndInvokeEventsSec(3);
updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE);
engine->launchController.update();
spark = false;
fuel = false;
launchInstance.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX);
engine->launchController.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX);
EXPECT_TRUE(spark);
EXPECT_FALSE(fuel);
Sensor::setMockValue(SensorType::VehicleSpeed, 40.0);
updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE);
engine->launchController.update();
spark = false;
fuel = false;
launchInstance.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX);
engine->launchController.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX);
EXPECT_FALSE(spark);
EXPECT_FALSE(fuel);