From 84ebfe301a201e9486d7564444854ed471251e86 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 11 Jul 2020 15:19:27 -0400 Subject: [PATCH] PidIndustrial does not limit iTerm #1599 confirming issue with a unit test --- unit_tests/tests/test_pid.cpp | 50 +++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/unit_tests/tests/test_pid.cpp b/unit_tests/tests/test_pid.cpp index f3b845206a..b399e7324b 100644 --- a/unit_tests/tests/test_pid.cpp +++ b/unit_tests/tests/test_pid.cpp @@ -62,31 +62,47 @@ TEST(util, pid) { ASSERT_EQ( 0, pid.getOutput(/*target*/50, /*input*/50)) << "target=50, input=50"; ASSERT_EQ( 0, pid.iTerm) << "target=50, input=50 iTerm"; - } -TEST(util, pidLimits) { +static void commonPidTestParameters(pid_s * pidS) { + pidS->pFactor = 0; + pidS->iFactor = 50; + pidS->dFactor = 0; + pidS->offset = 0; + pidS->minValue = 10; + pidS->maxValue = 40; + pidS->periodMs = 1; +} +static void commonPidTest(Pid *pid) { + pid->iTermMax = 45; + + ASSERT_EQ( 12.5, pid->getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #0"; + ASSERT_EQ( 12.5, pid->getIntegration()); + ASSERT_EQ( 25 , pid->getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #1"; + + ASSERT_EQ( 37.5, pid->getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #2"; + ASSERT_EQ( 37.5, pid->getIntegration()); + + ASSERT_EQ( 40.0, pid->getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #3"; + ASSERT_EQ( 45, pid->getIntegration()); +} + +TEST(util, parallelPidLimits) { pid_s pidS; - pidS.pFactor = 0; - pidS.iFactor = 50; - pidS.dFactor = 0; - pidS.offset = 0; - pidS.minValue = 10; - pidS.maxValue = 40; - pidS.periodMs = 1; + commonPidTestParameters(&pidS); Pid pid(&pidS); + commonPidTest(&pid); +} - pid.iTermMax = 45; - - ASSERT_EQ( 12.5, pid.getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #0"; - ASSERT_EQ( 25 , pid.getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #1"; - - ASSERT_EQ( 37.5, pid.getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #2"; - - ASSERT_EQ( 40.0, pid.getOutput(/*target*/50, /*input*/0)) << "target=50, input=0 #3"; +TEST(util, industrialPidLimits) { + pid_s pidS; + commonPidTestParameters(&pidS); + PidIndustrial pid(&pidS); +// todo: #1599 +// commonPidTest(&pid); } TEST(util, pidIndustrial) {