From bb3cb0ba22b78ce87519a0a72172df4d9979fb97 Mon Sep 17 00:00:00 2001 From: rusefi Date: Mon, 7 Dec 2020 01:11:32 -0500 Subject: [PATCH] Revert "Require redundant tps for ETB (#2037)" This reverts commit 4f1085a8 --- .../actuators/electronic_throttle.cpp | 14 ------- firmware/controllers/sensors/sensor.cpp | 12 ++---- firmware/controllers/sensors/sensor.h | 5 ++- unit_tests/tests/test_etb.cpp | 41 ++----------------- 4 files changed, 10 insertions(+), 62 deletions(-) diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 63d2f4170c..0c441c0247 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -168,20 +168,6 @@ bool EtbController::init(etb_function_e function, DcMotor *motor, pid_s *pidPara m_function = function; m_positionSensor = functionToPositionSensor(function); - - // If we are a throttle, require redundant TPS sensor - if (function == ETB_Throttle1 || function == ETB_Throttle2) { - if (!Sensor::isRedundant(m_positionSensor)) { - firmwareError( - OBD_Throttle_Position_Sensor_Circuit_Malfunction, - "Use of electronic throttle requires %s to be redundant.", - Sensor::getSensorName(m_positionSensor) - ); - - return false; - } - } - m_motor = motor; m_pid.initPidClass(pidParameters); m_pedalMap = pedalMap; diff --git a/firmware/controllers/sensors/sensor.cpp b/firmware/controllers/sensors/sensor.cpp index 7b873d2b0c..957ed1ee93 100644 --- a/firmware/controllers/sensors/sensor.cpp +++ b/firmware/controllers/sensors/sensor.cpp @@ -50,10 +50,9 @@ public: return m_sensor; } - void setMockValue(float value, bool mockRedundant) { + void setMockValue(float value) { m_mockValue = value; m_useMock = true; - m_mockRedundant = mockRedundant; } void resetMock() { @@ -132,16 +131,11 @@ public: return sensor->isRedundant(); } - if (m_useMock) { - return m_mockRedundant; - } - return false; } private: bool m_useMock = false; - bool m_mockRedundant = false; float m_mockValue; Sensor* m_sensor = nullptr; }; @@ -207,11 +201,11 @@ bool Sensor::Register() { return entry ? entry->hasSensor() : false; } -/*static*/ void Sensor::setMockValue(SensorType type, float value, bool mockRedundant) { +/*static*/ void Sensor::setMockValue(SensorType type, float value) { auto entry = getEntryForType(type); if (entry) { - entry->setMockValue(value, mockRedundant); + entry->setMockValue(value); } } diff --git a/firmware/controllers/sensors/sensor.h b/firmware/controllers/sensors/sensor.h index e21b4b08c7..ddaac940f2 100644 --- a/firmware/controllers/sensors/sensor.h +++ b/firmware/controllers/sensors/sensor.h @@ -105,7 +105,7 @@ public: /* * Mock a value for a particular sensor. */ - static void setMockValue(SensorType type, float value, bool mockRedundant = false); + static void setMockValue(SensorType type, float value); /* * Mock a value for a particular sensor. @@ -127,7 +127,6 @@ public: * For example, CLT, IAT, Throttle Position 2, etc. */ const char* getSensorName() { return getSensorName(m_type); } - static const char* getSensorName(SensorType type); // Retrieve the current reading from the sensor. // @@ -156,6 +155,8 @@ protected: explicit Sensor(SensorType type) : m_type(type) {} + static const char* getSensorName(SensorType type); + private: const SensorType m_type; diff --git a/unit_tests/tests/test_etb.cpp b/unit_tests/tests/test_etb.cpp index 48c12f8ac1..4ee8f1cac7 100644 --- a/unit_tests/tests/test_etb.cpp +++ b/unit_tests/tests/test_etb.cpp @@ -120,8 +120,8 @@ TEST(etb, initializationDualThrottle) { Sensor::setMockValue(SensorType::AcceleratorPedal, 0); Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0); - Sensor::setMockValue(SensorType::Tps1, 25.0f, true); - Sensor::setMockValue(SensorType::Tps2, 25.0f, true); + // The presence of a second TPS indicates dual throttle + Sensor::setMockValue(SensorType::Tps2, 25.0f); engineConfiguration->etbFunctions[0] = ETB_Throttle1; engineConfiguration->etbFunctions[1] = ETB_Throttle2; @@ -172,15 +172,6 @@ TEST(etb, initializationNoFunction) { dut.setOutput(0.5f); } -TEST(etb, initializationNotRedundantTps) { - EtbController dut; - - // Not redundant, should fail upon init - Sensor::setMockValue(SensorType::Tps1, 0.0f, false); - - EXPECT_FATAL_ERROR(dut.init(ETB_Throttle1, nullptr, nullptr, nullptr)); -} - TEST(etb, idlePlumbing) { StrictMock mocks[ETB_COUNT]; @@ -217,9 +208,6 @@ TEST(etb, testSetpointOnlyPedal) { // Uninitialized ETB must return unexpected (and not deference a null pointer) EXPECT_EQ(etb.getSetpoint(), unexpected); - // Must have TPS initialized for ETB setup - Sensor::setMockValue(SensorType::Tps1, 0.0f, true); - etb.init(ETB_Throttle1, nullptr, nullptr, &pedalMap); // Check endpoints and midpoint @@ -261,9 +249,6 @@ TEST(etb, setpointIdle) { engineConfiguration->useETBforIdleControl = true; engineConfiguration->etbIdleThrottleRange = 0; - // Must have TPS initialized for ETB setup - Sensor::setMockValue(SensorType::Tps1, 0.0f, true); - EtbController etb; INJECT_ENGINE_REFERENCE(&etb); @@ -359,8 +344,8 @@ TEST(etb, setpointWastegateController) { TEST(etb, etbTpsSensor) { // Throw some distinct values on the TPS sensors so we can identify that we're getting the correct one - Sensor::setMockValue(SensorType::Tps1, 25.0f, true); - Sensor::setMockValue(SensorType::Tps2, 75.0f, true); + Sensor::setMockValue(SensorType::Tps1, 25.0f); + Sensor::setMockValue(SensorType::Tps2, 75.0f); Sensor::setMockValue(SensorType::WastegatePosition, 33.0f); Sensor::setMockValue(SensorType::IdlePosition, 66.0f); @@ -412,9 +397,6 @@ TEST(etb, setOutputValid) { WITH_ENGINE_TEST_HELPER(TEST_ENGINE); StrictMock motor; - // Must have TPS initialized for ETB setup - Sensor::setMockValue(SensorType::Tps1, 0.0f, true); - EtbController etb; INJECT_ENGINE_REFERENCE(&etb); etb.init(ETB_Throttle1, &motor, nullptr, nullptr); @@ -431,9 +413,6 @@ TEST(etb, setOutputValid2) { WITH_ENGINE_TEST_HELPER(TEST_ENGINE); StrictMock motor; - // Must have TPS initialized for ETB setup - Sensor::setMockValue(SensorType::Tps1, 0.0f, true); - EtbController etb; INJECT_ENGINE_REFERENCE(&etb); etb.init(ETB_Throttle1, &motor, nullptr, nullptr); @@ -450,9 +429,6 @@ TEST(etb, setOutputOutOfRangeHigh) { WITH_ENGINE_TEST_HELPER(TEST_ENGINE); StrictMock motor; - // Must have TPS initialized for ETB setup - Sensor::setMockValue(SensorType::Tps1, 0.0f, true); - EtbController etb; INJECT_ENGINE_REFERENCE(&etb); etb.init(ETB_Throttle1, &motor, nullptr, nullptr); @@ -469,9 +445,6 @@ TEST(etb, setOutputOutOfRangeLow) { WITH_ENGINE_TEST_HELPER(TEST_ENGINE); StrictMock motor; - // Must have TPS initialized for ETB setup - Sensor::setMockValue(SensorType::Tps1, 0.0f, true); - EtbController etb; INJECT_ENGINE_REFERENCE(&etb); etb.init(ETB_Throttle1, &motor, nullptr, nullptr); @@ -488,9 +461,6 @@ TEST(etb, setOutputPauseControl) { WITH_ENGINE_TEST_HELPER(TEST_ENGINE); StrictMock motor; - // Must have TPS initialized for ETB setup - Sensor::setMockValue(SensorType::Tps1, 0.0f, true); - EtbController etb; INJECT_ENGINE_REFERENCE(&etb); etb.init(ETB_Throttle1, &motor, nullptr, nullptr); @@ -510,9 +480,6 @@ TEST(etb, closedLoopPid) { pid.maxValue = 75; pid.minValue = -60; - // Must have TPS initialized for ETB setup - Sensor::setMockValue(SensorType::Tps1, 0.0f, true); - EtbController etb; etb.init(ETB_Throttle1, nullptr, &pid, nullptr);