diff --git a/unit_tests/tests/actuators/test_etb.cpp b/unit_tests/tests/actuators/test_etb.cpp index 699b12089a..2ffc539184 100644 --- a/unit_tests/tests/actuators/test_etb.cpp +++ b/unit_tests/tests/actuators/test_etb.cpp @@ -709,6 +709,8 @@ TEST(etb, setOutputLimpHome) { } TEST(etb, closedLoopPid) { + EngineTestHelper eth(engine_type_e::TEST_ENGINE); + pid_s pid = {}; pid.pFactor = 5; pid.maxValue = 75; @@ -723,9 +725,7 @@ TEST(etb, closedLoopPid) { etb.init(DC_Throttle1, nullptr, &pid, nullptr, true); // Disable autotune for now - Engine e; - EngineTestHelperBase base(&e, nullptr, nullptr); - e.etbAutoTune = false; + engine->etbAutoTune = false; // Setpoint greater than actual, should be positive output EXPECT_FLOAT_EQ(etb.getClosedLoop(50, 40).value_or(-1), 50); @@ -740,51 +740,37 @@ TEST(etb, closedLoopPid) { TEST(etb, jamDetection) { EngineTestHelper eth(engine_type_e::TEST_ENGINE); - pid_s pid = {}; - - // I-only since we're testing out the integrator - pid.pFactor = 0; - pid.iFactor = 1; - pid.dFactor = 0; - pid.maxValue = 50; - pid.minValue = -50; - // Must have TPS & PPS initialized for ETB setup Sensor::setMockValue(SensorType::Tps1Primary, 0); Sensor::setMockValue(SensorType::Tps1, 0.0f, true); Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true); // Limit of 5%, 1 second - engineConfiguration->etbJamIntegratorLimit = 5; + engineConfiguration->jamDetectThreshold = 5; engineConfiguration->etbJamTimeout = 1; EtbController etb; - etb.init(DC_Throttle1, nullptr, &pid, nullptr, true); + etb.init(DC_Throttle1, nullptr, nullptr, nullptr, true); setTimeNowUs(0); - // Reset timer while under integrator limit - EXPECT_EQ(etb.getPidState().iTerm, 0); - etb.checkOutput(0); + // Reset timer while under error limit + etb.checkJam(10, 14); EXPECT_EQ(etb.jamTimer, 0); EXPECT_FALSE(etb.jamDetected); - for (size_t i = 0; i < ETB_LOOP_FREQUENCY; i++) { - // Error of 10, should accumulate 10 integrator per second - etb.getClosedLoop(50, 40); - } - - EXPECT_NEAR(etb.getPidState().iTerm, 10.0f, 1e-3); + // Start a jam + etb.checkJam(10, 16); // Just under time limit, no jam yet setTimeNowUs(0.9e6); - etb.checkOutput(0); + etb.checkJam(10, 16); EXPECT_NEAR(etb.jamTimer, 0.9f, 1e-3); EXPECT_FALSE(etb.jamDetected); // Above the time limit, jam detected! setTimeNowUs(1.1e6); - etb.checkOutput(0); + etb.checkJam(10, 16); EXPECT_TRUE(etb.jamDetected); } diff --git a/unit_tests/tests/actuators/test_etb_integrated.cpp b/unit_tests/tests/actuators/test_etb_integrated.cpp index 14600ba68c..4adac65451 100644 --- a/unit_tests/tests/actuators/test_etb_integrated.cpp +++ b/unit_tests/tests/actuators/test_etb_integrated.cpp @@ -23,30 +23,6 @@ static EtbController * initEtbIntegratedTest() { return (EtbController*)engine->etbControllers[0]; } -TEST(etb, integrated) { - EngineTestHelper eth(engine_type_e::TEST_ENGINE); // we have a destructor so cannot move EngineTestHelper into utility method - EtbController *etb = initEtbIntegratedTest(); - - Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 40); - Sensor::setMockValue(SensorType::AcceleratorPedalSecondary, 40); - - etb->update(); - - ASSERT_EQ(engine->outputChannels.etbTarget, 40); - ASSERT_NEAR(etb->prevOutput, 120.363, EPS3D); - ASSERT_NEAR(etb->etbDutyAverage, 60.1813, EPS3D); - - Sensor::setMockValue(SensorType::AcceleratorPedal, 10, true); - etb->update(); - ASSERT_NEAR(etb->etbDutyAverage, 70.0741, EPS3D); - ASSERT_NEAR(etb->etbDutyRateOfChange, 130.2554, EPS3D); - - float destination; - int offset = ELECTRONIC_THROTTLE_BASE_ADDRESS + offsetof(electronic_throttle_s, etbDutyRateOfChange); - copyRange((uint8_t*)&destination, getLiveDataFragments(), offset, sizeof(destination)); - ASSERT_NEAR(destination, 130.2554, EPS3D); -} - // TEST(etb, intermittentTps) { // EngineTestHelper eth(engine_type_e::TEST_ENGINE); // we have a destructor so cannot move EngineTestHelper into utility method // EtbController *etb = initEtbIntegratedTest();