rusefi-1/unit_tests/test_idle_controller.cpp

69 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
* @author Andrey Belomutskiy, (c) 2012-2014
*/
#include <stdio.h>
2017-05-16 17:18:28 -07:00
2015-07-10 06:01:56 -07:00
#include "efitime.h"
#include "engine_test_helper.h"
#include "pid.h"
void testPidController(void) {
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;
2017-06-02 18:51:38 -07:00
pidS.period = 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
2016-07-13 18:03:05 -07:00
assertEqualsM("getValue#90", 90, pid.getValue(14, 12, 0.1));
2015-07-10 06:01:56 -07:00
2016-07-13 18:03:05 -07:00
assertEqualsM("getValue#10", 10, pid.getValue(14, 16, 0.1));
2015-07-10 06:01:56 -07:00
assertEquals(10, pid.getValue(14, 16, 1));
pid.updateFactors(29, 0, 0);
assertEquals(10, pid.getValue(14, 16, 1));
// assertEquals(68, pid.getIntegration());
assertEquals(10, pid.getValue(14, 16, 1));
// assertEquals(0, pid.getIntegration());
assertEquals(10, pid.getValue(14, 16, 1));
// assertEquals(68, pid.getIntegration());
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;
pidS.period = 1;
pid.reset();
assertEqualsM("target=50, input=0", 50, pid.getValue(/*target*/50, /*input*/0));
assertEqualsM("target=50, input=0 iTerm", 0, pid.iTerm);
assertEqualsM("target=50, input=70", 0, pid.getValue(/*target*/50, /*input*/70));
2017-06-02 19:28:12 -07:00
assertEqualsM("target=50, input=70 iTerm", 0, pid.iTerm);
2017-06-02 18:51:38 -07:00
assertEqualsM("target=50, input=70 #2", 0, pid.getValue(/*target*/50, /*input*/70));
2017-06-02 19:28:12 -07:00
assertEqualsM("target=50, input=70 iTerm #2", 0, pid.iTerm);
2017-06-02 18:51:38 -07:00
2017-06-02 19:28:12 -07:00
assertEqualsM("target=50, input=50", 0, pid.getValue(/*target*/50, /*input*/50));
assertEqualsM("target=50, input=50 iTerm", 0, pid.iTerm);
2017-06-02 18:51:38 -07:00
2015-07-10 06:01:56 -07:00
}