fome-fw/unit_tests/tests/test_idle_controller.cpp

65 lines
1.6 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/*
* @file test_idle_controller.cpp
*
* @date Oct 17, 2013
2018-07-28 09:42:37 -07:00
* @author Andrey Belomutskiy, (c) 2012-2018
2015-07-10 06:01:56 -07:00
*/
#include "engine_test_helper.h"
#include "pid.h"
2019-01-08 19:10:54 -08:00
TEST(idle, pid) {
2015-07-10 06:01:56 -07:00
print("******************************************* testPidController\r\n");
2016-01-20 20:03:03 -08:00
pid_s pidS;
pidS.pFactor = 50;
pidS.iFactor = 0.5;
pidS.dFactor = 0;
2016-07-13 18:03:05 -07:00
pidS.offset = 0;
2017-05-29 20:09:52 -07:00
pidS.minValue = 10;
pidS.maxValue = 90;
2019-02-10 19:47:49 -08:00
pidS.periodMs = 1;
2016-01-20 20:03:03 -08:00
2017-05-29 20:09:52 -07:00
Pid pid(&pidS);
2015-07-10 06:01:56 -07:00
ASSERT_EQ( 90, pid.getOutput(14, 12, 0.1)) << "getValue#90";
2015-07-10 06:01:56 -07:00
ASSERT_EQ( 10, pid.getOutput(14, 16, 0.1)) << "getValue#10";
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
2015-07-10 06:01:56 -07:00
pid.updateFactors(29, 0, 0);
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
2019-01-14 12:45:35 -08:00
// ASSERT_EQ(68, pid.getIntegration());
2015-07-10 06:01:56 -07:00
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
2019-01-14 12:45:35 -08:00
// ASSERT_EQ(0, pid.getIntegration());
2015-07-10 06:01:56 -07:00
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
2019-01-14 12:45:35 -08:00
// ASSERT_EQ(68, pid.getIntegration());
2015-07-10 06:01:56 -07:00
2017-06-02 18:51:38 -07:00
pidS.pFactor = 1;
pidS.iFactor = 0;
pidS.dFactor = 0;
pidS.offset = 0;
pidS.minValue = 0;
pidS.maxValue = 100;
2019-02-10 19:47:49 -08:00
pidS.periodMs = 1;
2017-06-02 18:51:38 -07:00
pid.reset();
ASSERT_EQ( 50, pid.getOutput(/*target*/50, /*input*/0)) << "target=50, input=0";
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=0 iTerm";
2017-06-02 18:51:38 -07:00
ASSERT_EQ( 0, pid.getOutput(/*target*/50, /*input*/70)) << "target=50, input=70";
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=70 iTerm";
2017-06-02 18:51:38 -07:00
ASSERT_EQ( 0, pid.getOutput(/*target*/50, /*input*/70)) << "target=50, input=70 #2";
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=70 iTerm #2";
2017-06-02 18:51:38 -07:00
ASSERT_EQ( 0, pid.getOutput(/*target*/50, /*input*/50)) << "target=50, input=50";
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=50 iTerm";
2017-06-02 18:51:38 -07:00
2015-07-10 06:01:56 -07:00
}