From a444e09ff891fb3d1dfbc5c90719d1bc2250c93c Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Fri, 24 Apr 2020 14:54:03 -0700 Subject: [PATCH] etb CL test (#1361) --- unit_tests/tests/test_etb.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/unit_tests/tests/test_etb.cpp b/unit_tests/tests/test_etb.cpp index abe59745cd..8e3b59c3e9 100644 --- a/unit_tests/tests/test_etb.cpp +++ b/unit_tests/tests/test_etb.cpp @@ -290,3 +290,27 @@ TEST(etb, setOutputOutOfRangeLow) { // Off scale - should get clamped to -90% etb.setOutput(-110); } + +TEST(etb, closedLoopPid) { + pid_s pid = {}; + pid.pFactor = 5; + pid.maxValue = 75; + pid.minValue = -60; + + EtbController etb; + etb.init(nullptr, 0, &pid, nullptr); + + // Disable autotune for now + Engine e; + e.etbAutoTune = false; + etb.engine = &e; + + // Setpoint greater than actual, should be positive output + EXPECT_FLOAT_EQ(etb.getClosedLoop(50, 40).value_or(-1), 50); + // Likewise but negative + EXPECT_FLOAT_EQ(etb.getClosedLoop(50, 52).value_or(-1), -10); + + // Test PID limiting + EXPECT_FLOAT_EQ(etb.getClosedLoop(50, 70).value_or(-1), -60); + EXPECT_FLOAT_EQ(etb.getClosedLoop(50, 30).value_or(-1), 75); +}