PID auto tune

This commit is contained in:
rusefi 2017-09-14 21:49:26 -04:00
parent 20605d8204
commit 27136cafe7
2 changed files with 49 additions and 2 deletions

View File

@ -75,9 +75,9 @@ int PID_AutoTune::Runtime(Logging *logging) {
for (int i = nLookBack - 1; i >= 0; i--) {
float val = lastInputs[i];
if (isMax)
isMax = input > val;
isMax = input >= val;
if (isMin)
isMin = input < val;
isMin = input <= val;
lastInputs[i + 1] = lastInputs[i];
}
lastInputs[0] = input;

View File

@ -8,6 +8,7 @@
#include "main.h"
#include "test_pid_auto.h"
#include "pid_auto_tune.h"
efitimems_t mockTimeMs = 0;
@ -15,7 +16,53 @@ efitimems_t currentTimeMillis(void) {
return mockTimeMs;
}
Logging logging;
static zigZagValue(int index) {
int i = index % 20;
if ( i <= 10)
return i * 10;
return (20 - i) * 10;
}
void testPidAutoZigZag() {
mockTimeMs = 0;
PID_AutoTune at;
at.outputStart = 50;
at.input = zigZagValue(mockTimeMs);
at.Runtime(&logging);
mockTimeMs++;
at.input = zigZagValue(mockTimeMs);
at.Runtime(&logging);
assertEqualsLM("min@1", 0, at.absMin);
assertEqualsLM("max@1", 10, at.absMax);
assertEqualsM("peakCount", 0, at.peakCount);
for (;mockTimeMs<=11;mockTimeMs++) {
at.input = zigZagValue(mockTimeMs);
at.Runtime(&logging);
}
assertEqualsLM("min@11", 0, at.absMin);
assertEqualsLM("max@11", 100, at.absMax);
assertEqualsM("peakCount", 0, at.peakCount);
for (;mockTimeMs<=21;mockTimeMs++) {
at.input = zigZagValue(mockTimeMs);
at.Runtime(&logging);
}
assertEqualsM("peakCount", 1, at.peakCount);
for (;mockTimeMs<=41;mockTimeMs++) {
at.input = zigZagValue(mockTimeMs);
at.Runtime(&logging);
}
assertEqualsM("peakCount", 2, at.peakCount);
}