From 299a345c1c7193350f1d13dfd72b4a5677fc6a09 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 14 Oct 2020 19:02:09 -0700 Subject: [PATCH] etb function config 1 (#1881) * this should all be safe... * test fix --- .../actuators/electronic_throttle.cpp | 17 ++++++++++++++--- unit_tests/tests/test_etb.cpp | 3 --- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 4ad660a94a..71b15ce7ff 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -172,6 +172,8 @@ bool EtbController::init(etb_function_e function, DcMotor *motor, pid_s *pidPara m_pid.initPidClass(pidParameters); m_pedalMap = pedalMap; + reset(); + return true; } @@ -756,6 +758,10 @@ void setDefaultEtbParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE) { } } + // Default is to run each throttle off its respective hbridge + engineConfiguration->etbFunctions[0] = ETB_Throttle1; + engineConfiguration->etbFunctions[1] = ETB_Throttle2; + engineConfiguration->etbFreq = DEFAULT_ETB_PWM_FREQUENCY; // voltage, not ADC like with TPS @@ -831,16 +837,23 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) { engine->etbActualCount = Sensor::hasSensor(SensorType::Tps2) ? 2 : 1; + bool anyEtbConfigured = false; + for (int i = 0 ; i < engine->etbActualCount; i++) { auto motor = initDcMotor(i, CONFIG(etb_use_two_wires) PASS_ENGINE_PARAMETER_SUFFIX); // If this motor is actually set up, init the etb if (motor) { + auto controller = engine->etbControllers[i]; + if (!controller) { + continue; + } + // TODO: configure per-motor in config so wastegate/VW idle works auto func = i == 0 ? ETB_Throttle1 : ETB_Throttle2; - engine->etbControllers[i]->init(func, motor, &engineConfiguration->etb, &pedal2tpsMap); + anyEtbConfigured |= controller->init(func, motor, &engineConfiguration->etb, &pedal2tpsMap); INJECT_ENGINE_REFERENCE(engine->etbControllers[i]); } } @@ -858,8 +871,6 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } #endif /* EFI_UNIT_TEST */ - etbPidReset(PASS_ENGINE_PARAMETER_SIGNATURE); - #if !EFI_UNIT_TEST etbThread.Start(); #endif diff --git a/unit_tests/tests/test_etb.cpp b/unit_tests/tests/test_etb.cpp index 5522ca1b7d..86b75b3cc2 100644 --- a/unit_tests/tests/test_etb.cpp +++ b/unit_tests/tests/test_etb.cpp @@ -47,7 +47,6 @@ TEST(etb, initializationSingleThrottle) { // Expect mock0 to be init as throttle 1, and PID params EXPECT_CALL(mocks[0], init(ETB_Throttle1, _, &engineConfiguration->etb, Ne(nullptr))).WillOnce(Return(true)); - EXPECT_CALL(mocks[0], reset); // We do not expect throttle #2 to be initialized @@ -72,11 +71,9 @@ TEST(etb, initializationDualThrottle) { // Expect mock0 to be init as throttle 1, and PID params EXPECT_CALL(mocks[0], init(ETB_Throttle1, _, &engineConfiguration->etb, Ne(nullptr))).WillOnce(Return(true)); - EXPECT_CALL(mocks[0], reset); // Expect mock1 to be init as throttle 2, and PID params EXPECT_CALL(mocks[1], init(ETB_Throttle2, _, &engineConfiguration->etb, Ne(nullptr))).WillOnce(Return(true)); - EXPECT_CALL(mocks[1], reset); doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE); }