From 99489cff679c2db1e45297af1ff16c9b37d416b4 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 20 Apr 2020 14:29:03 -0700 Subject: [PATCH] Improve ETB idle control (#1319) * compress idle pos * fix tests for new behavior --- .../controllers/actuators/electronic_throttle.cpp | 13 +++++++++---- unit_tests/tests/test_etb.cpp | 14 +++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 9c8870be8f..9fa72f244c 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -168,7 +168,8 @@ expected EtbController::getSetpoint() const { float sanitizedPedal = clampF(0, pedalPosition.Value, 100); float rpm = GET_RPM(); - engine->engineState.targetFromTable = m_pedalMap->getValue(rpm / RPM_1_BYTE_PACKING_MULT, sanitizedPedal); + float targetFromTable = m_pedalMap->getValue(rpm / RPM_1_BYTE_PACKING_MULT, sanitizedPedal); + engine->engineState.targetFromTable = targetFromTable; percent_t etbIdlePosition = clampF( 0, @@ -177,15 +178,19 @@ expected EtbController::getSetpoint() const { ); percent_t etbIdleAddition = 0.01f * CONFIG(etbIdleThrottleRange) * etbIdlePosition; - float target = engine->engineState.targetFromTable + etbIdleAddition; + // Interpolate so that the idle adder just "compresses" the throttle's range upward. + // [0, 100] -> [idle, 100] + // 0% target from table -> idle position as target + // 100% target from table -> 100% target position + percent_t targetPosition = interpolateClamped(0, etbIdleAddition, 100, 100, targetFromTable); #if EFI_TUNER_STUDIO if (m_myIndex == 0) { - tsOutputChannels.etbTarget = target; + tsOutputChannels.etbTarget = targetPosition; } #endif - return target; + return targetPosition; } expected EtbController::getOpenLoop(percent_t target) const { diff --git a/unit_tests/tests/test_etb.cpp b/unit_tests/tests/test_etb.cpp index f04c34727b..abe59745cd 100644 --- a/unit_tests/tests/test_etb.cpp +++ b/unit_tests/tests/test_etb.cpp @@ -176,26 +176,30 @@ TEST(etb, setpointIdle) { // Idle should now have 10% range engineConfiguration->etbIdleThrottleRange = 10; - // 50% idle position should increase setpoint by 5% + // 50% idle position should increase setpoint by 5% when closed, and 0% when open etb.setIdlePosition(50); Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f); EXPECT_FLOAT_EQ(5, etb.getSetpoint().value_or(-1)); Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f); - EXPECT_FLOAT_EQ(55, etb.getSetpoint().value_or(-1)); + EXPECT_FLOAT_EQ(52.5, etb.getSetpoint().value_or(-1)); + Sensor::setMockValue(SensorType::AcceleratorPedal, 100.0f); + EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1)); - // 100% setpoint should increase by 10% + // 100% setpoint should increase by 10% closed, scaled 0% at wot etb.setIdlePosition(100); Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f); EXPECT_FLOAT_EQ(10, etb.getSetpoint().value_or(-1)); Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f); - EXPECT_FLOAT_EQ(60, etb.getSetpoint().value_or(-1)); + EXPECT_FLOAT_EQ(55, etb.getSetpoint().value_or(-1)); + Sensor::setMockValue(SensorType::AcceleratorPedal, 100.0f); + EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1)); // 125% setpoint should clamp to 10% increase etb.setIdlePosition(125); Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f); EXPECT_FLOAT_EQ(10, etb.getSetpoint().value_or(-1)); Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f); - EXPECT_FLOAT_EQ(60, etb.getSetpoint().value_or(-1)); + EXPECT_FLOAT_EQ(55, etb.getSetpoint().value_or(-1)); } TEST(etb, etbTpsSensor) {