extracting pid test to separate file
This commit is contained in:
parent
df7fe0ec3b
commit
3201df7fbe
|
@ -48,61 +48,7 @@ TEST(idle, fsioPidParameters) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(idle, pid) {
|
// see also util.pid test
|
||||||
print("******************************************* testPidController\r\n");
|
|
||||||
pid_s pidS;
|
|
||||||
pidS.pFactor = 50;
|
|
||||||
pidS.iFactor = 0.5;
|
|
||||||
pidS.dFactor = 0;
|
|
||||||
pidS.offset = 0;
|
|
||||||
pidS.minValue = 10;
|
|
||||||
pidS.maxValue = 90;
|
|
||||||
pidS.periodMs = 1;
|
|
||||||
|
|
||||||
Pid pid(&pidS);
|
|
||||||
|
|
||||||
ASSERT_EQ( 90, pid.getOutput(14, 12, 0.1)) << "getValue#90";
|
|
||||||
|
|
||||||
|
|
||||||
ASSERT_EQ( 10, pid.getOutput(14, 16, 0.1)) << "getValue#10";
|
|
||||||
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
|
|
||||||
|
|
||||||
pid.updateFactors(29, 0, 0);
|
|
||||||
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
|
|
||||||
// ASSERT_EQ(68, pid.getIntegration());
|
|
||||||
|
|
||||||
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
|
|
||||||
// ASSERT_EQ(0, pid.getIntegration());
|
|
||||||
|
|
||||||
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
|
|
||||||
// ASSERT_EQ(68, pid.getIntegration());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pidS.pFactor = 1;
|
|
||||||
pidS.iFactor = 0;
|
|
||||||
pidS.dFactor = 0;
|
|
||||||
pidS.offset = 0;
|
|
||||||
pidS.minValue = 0;
|
|
||||||
pidS.maxValue = 100;
|
|
||||||
pidS.periodMs = 1;
|
|
||||||
|
|
||||||
pid.reset();
|
|
||||||
|
|
||||||
ASSERT_EQ( 50, pid.getOutput(/*target*/50, /*input*/0)) << "target=50, input=0";
|
|
||||||
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=0 iTerm";
|
|
||||||
|
|
||||||
ASSERT_EQ( 0, pid.getOutput(/*target*/50, /*input*/70)) << "target=50, input=70";
|
|
||||||
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=70 iTerm";
|
|
||||||
|
|
||||||
ASSERT_EQ( 0, pid.getOutput(/*target*/50, /*input*/70)) << "target=50, input=70 #2";
|
|
||||||
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=70 iTerm #2";
|
|
||||||
|
|
||||||
ASSERT_EQ( 0, pid.getOutput(/*target*/50, /*input*/50)) << "target=50, input=50";
|
|
||||||
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=50 iTerm";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(idle, timingPid) {
|
TEST(idle, timingPid) {
|
||||||
print("******************************************* testTimingPidController\r\n");
|
print("******************************************* testTimingPidController\r\n");
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* @file test_pid_auto.cpp
|
||||||
|
*
|
||||||
|
* @date Sep 29, 2019
|
||||||
|
* @author Andrey Belomutskiy, (c) 2012-2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
// see also idle.timingPid test
|
||||||
|
|
||||||
|
#include "unit_test_framework.h"
|
||||||
|
#include "pid.h"
|
||||||
|
|
||||||
|
TEST(util, pid) {
|
||||||
|
print("******************************************* testPidController\r\n");
|
||||||
|
pid_s pidS;
|
||||||
|
pidS.pFactor = 50;
|
||||||
|
pidS.iFactor = 0.5;
|
||||||
|
pidS.dFactor = 0;
|
||||||
|
pidS.offset = 0;
|
||||||
|
pidS.minValue = 10;
|
||||||
|
pidS.maxValue = 90;
|
||||||
|
pidS.periodMs = 1;
|
||||||
|
|
||||||
|
Pid pid(&pidS);
|
||||||
|
|
||||||
|
ASSERT_EQ( 90, pid.getOutput(14, 12, 0.1)) << "getValue#90";
|
||||||
|
|
||||||
|
|
||||||
|
ASSERT_EQ( 10, pid.getOutput(14, 16, 0.1)) << "getValue#10";
|
||||||
|
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
|
||||||
|
|
||||||
|
pid.updateFactors(29, 0, 0);
|
||||||
|
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
|
||||||
|
// ASSERT_EQ(68, pid.getIntegration());
|
||||||
|
|
||||||
|
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
|
||||||
|
// ASSERT_EQ(0, pid.getIntegration());
|
||||||
|
|
||||||
|
ASSERT_EQ(10, pid.getOutput(14, 16, 1));
|
||||||
|
// ASSERT_EQ(68, pid.getIntegration());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pidS.pFactor = 1;
|
||||||
|
pidS.iFactor = 0;
|
||||||
|
pidS.dFactor = 0;
|
||||||
|
pidS.offset = 0;
|
||||||
|
pidS.minValue = 0;
|
||||||
|
pidS.maxValue = 100;
|
||||||
|
pidS.periodMs = 1;
|
||||||
|
|
||||||
|
pid.reset();
|
||||||
|
|
||||||
|
ASSERT_EQ( 50, pid.getOutput(/*target*/50, /*input*/0)) << "target=50, input=0";
|
||||||
|
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=0 iTerm";
|
||||||
|
|
||||||
|
ASSERT_EQ( 0, pid.getOutput(/*target*/50, /*input*/70)) << "target=50, input=70";
|
||||||
|
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=70 iTerm";
|
||||||
|
|
||||||
|
ASSERT_EQ( 0, pid.getOutput(/*target*/50, /*input*/70)) << "target=50, input=70 #2";
|
||||||
|
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=70 iTerm #2";
|
||||||
|
|
||||||
|
ASSERT_EQ( 0, pid.getOutput(/*target*/50, /*input*/50)) << "target=50, input=50";
|
||||||
|
ASSERT_EQ( 0, pid.iTerm) << "target=50, input=50 iTerm";
|
||||||
|
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
/*
|
/*
|
||||||
* test_pid_auto.cpp
|
* @file test_pid_auto.cpp
|
||||||
*
|
*
|
||||||
* Created on: Sep 14, 2017
|
* @date Sep 14, 2017
|
||||||
* @author Andrey Belomutskiy, (c) 2012-2018
|
* @author Andrey Belomutskiy, (c) 2012-2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
|
@ -25,6 +25,7 @@ TESTS_SRC_CPP = \
|
||||||
tests/test_cpp_memory_layout.cpp \
|
tests/test_cpp_memory_layout.cpp \
|
||||||
tests/test_sensors.cpp \
|
tests/test_sensors.cpp \
|
||||||
tests/test_pid_auto.cpp \
|
tests/test_pid_auto.cpp \
|
||||||
|
tests/test_pid.cpp \
|
||||||
tests/test_accel_enrichment.cpp \
|
tests/test_accel_enrichment.cpp \
|
||||||
tests/test_gpiochip.cpp \
|
tests/test_gpiochip.cpp \
|
||||||
\
|
\
|
||||||
|
|
Loading…
Reference in New Issue