PID auto tune unit test

This commit is contained in:
rusefi 2018-11-22 23:42:30 -05:00
parent 1fffc8b740
commit 8156e8f752
3 changed files with 23 additions and 6 deletions

View File

@ -66,6 +66,8 @@ extern TunerStudioOutputChannels tsOutputChannels;
#endif /* EFI_TUNER_STUDIO */
static bool shouldResetPid = false;
static pid_s tuneWorkingPidSettings;
static Pid tuneWorkingPid(&tuneWorkingPidSettings);
static PID_AutoTune autoTune;
static LoggingWithStorage logger("ETB");
@ -122,9 +124,13 @@ static msg_t etbThread(void *arg) {
autoTune.input = actualThrottlePosition;
autoTune.Runtime(&logger);
etbPwmUp.setSimplePwmDutyCycle(autoTune.output);
tuneWorkingPid.updateFactors(autoTune.output, 0, 0);
pid.sleep();
float value = tuneWorkingPid.getValue(50, actualThrottlePosition);
scheduleMsg(&logger, "output %f value=%f", autoTune.output, value);
etbPwmUp.setSimplePwmDutyCycle(value);
tuneWorkingPid.sleep();
continue;
}
@ -290,6 +296,15 @@ void initElectronicThrottle(void) {
//
addConsoleActionF("set_etb", setThrottleDutyCycle);
tuneWorkingPidSettings.pFactor = 1;
tuneWorkingPidSettings.iFactor = 0;
tuneWorkingPidSettings.dFactor = 0;
tuneWorkingPidSettings.offset = 10; // todo: not hard-coded value
//todo tuneWorkingPidSettings.period = 10;
tuneWorkingPidSettings.minValue = 0;
tuneWorkingPidSettings.maxValue = 100;
// this is useful one you do "enable etb_auto"
addConsoleActionF("set_etb_output", setTempOutput);
addConsoleActionF("set_etb_step", setTempStep);

View File

@ -49,6 +49,7 @@ PID_AutoTune::PID_AutoTune() {
noiseBand = 0.5;
setState(AUTOTUNER_OFF);
oStep = 10.0;
input = output = 0;
SetLookbackSec(10);
}
@ -112,7 +113,7 @@ void PID_AutoTune::setPeakType(PidAutoTune_Peak peakType) {
/**
* returns true when done, otherwise returns false
*/
bool PID_AutoTune::Runtime(Logging *logging)
bool PID_AutoTune::Runtime(Logging *logger)
{
// check ready for new input
unsigned long now = currentTimeMillis();
@ -738,6 +739,7 @@ bool PID_AutoTune::Runtime(Logging *logging)
#if EFI_UNIT_TEST
printf("Happy end AMIGOF_PI!\r\n");
#endif /* EFI_UNIT_TEST */
scheduleMsg(logger, "output %f", output);
// converged
return true;
}

View File

@ -175,11 +175,11 @@ static void testPidAutoZigZagZero() {
printf("loop=%d %d\r\n", i, startMockMs);
for (; mockTimeMs < CYCLE + startMockMs; mockTimeMs++) {
at.input = zigZagValue(mockTimeMs);
// bool result = at.Runtime(&logging);
// assertFalseM("should be false#4", result);
bool result = at.Runtime(&logging);
assertFalseM("should be false#4", result);
}
oscRange *= 1.5;
}
// nothing happens in this test since we do not allow time play a role
}
void testPidAutoZigZag() {