PID auto tune
This commit is contained in:
parent
20605d8204
commit
27136cafe7
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue