From 5a735c9059e7d1cb12a0dbac0906d9593cb0246b Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 22 Feb 2023 13:41:43 -0500 Subject: [PATCH] Native SENT TPS input #5079 only:alphax-4chan --- firmware/controllers/actuators/electronic_throttle.cpp | 9 ++++++++- unit_tests/tests/actuators/test_etb.cpp | 9 +++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 930e0829e0..fdd51b4265 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -108,6 +108,13 @@ static SensorType functionToPositionSensor(dc_function_e func) { } } +static SensorType functionToTpsSensor(dc_function_e func) { + switch(func) { + case DC_Throttle1: return SensorType::Tps1; + default: return SensorType::Tps2; + } +} + static SensorType functionToTpsSensorPrimary(dc_function_e func) { switch(func) { case DC_Throttle1: return SensorType::Tps1Primary; @@ -177,7 +184,7 @@ bool EtbController::init(dc_function_e function, DcMotor *motor, pid_s *pidParam } // If no sensor is configured for this throttle, skip initialization. - if (!Sensor::hasSensor(functionToTpsSensorPrimary(function))) { + if (!Sensor::hasSensor(functionToTpsSensor(function))) { etbErrorCode = (int8_t)TpsState::TpsError; return false; } diff --git a/unit_tests/tests/actuators/test_etb.cpp b/unit_tests/tests/actuators/test_etb.cpp index 2bddf9740b..1df7a2ddea 100644 --- a/unit_tests/tests/actuators/test_etb.cpp +++ b/unit_tests/tests/actuators/test_etb.cpp @@ -210,7 +210,7 @@ TEST(etb, initializationNotRedundantPedal) { EXPECT_FATAL_ERROR(dut.init(DC_Throttle1, nullptr, nullptr, nullptr, true)); } -TEST(etb, initializationNoPrimarySensor) { +TEST(etb, initializationNoSensor) { Sensor::resetAllMocks(); EtbController dut; @@ -218,13 +218,10 @@ TEST(etb, initializationNoPrimarySensor) { // Needs pedal for init Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true); - // Redundant, but no primary configured - Sensor::setMockValue(SensorType::Tps1, /*value*/0, /*mockRedundant*/true); - EXPECT_FALSE(dut.init(DC_Throttle1, nullptr, nullptr, nullptr, true)); - // Now configure primary TPS - Sensor::setMockValue(SensorType::Tps1Primary, 0); + // Redundant + Sensor::setMockValue(SensorType::Tps1, /*value*/0, /*mockRedundant*/true); // With primary TPS, should return true (ie, throttle was configured) EXPECT_TRUE(dut.init(DC_Throttle1, nullptr, nullptr, nullptr, true));