mirror of https://github.com/rusefi/rusefi-1.git
PID auto tune unit test
This commit is contained in:
parent
1fffc8b740
commit
8156e8f752
|
@ -66,6 +66,8 @@ extern TunerStudioOutputChannels tsOutputChannels;
|
||||||
#endif /* EFI_TUNER_STUDIO */
|
#endif /* EFI_TUNER_STUDIO */
|
||||||
static bool shouldResetPid = false;
|
static bool shouldResetPid = false;
|
||||||
|
|
||||||
|
static pid_s tuneWorkingPidSettings;
|
||||||
|
static Pid tuneWorkingPid(&tuneWorkingPidSettings);
|
||||||
static PID_AutoTune autoTune;
|
static PID_AutoTune autoTune;
|
||||||
|
|
||||||
static LoggingWithStorage logger("ETB");
|
static LoggingWithStorage logger("ETB");
|
||||||
|
@ -122,9 +124,13 @@ static msg_t etbThread(void *arg) {
|
||||||
autoTune.input = actualThrottlePosition;
|
autoTune.input = actualThrottlePosition;
|
||||||
autoTune.Runtime(&logger);
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,6 +296,15 @@ void initElectronicThrottle(void) {
|
||||||
//
|
//
|
||||||
addConsoleActionF("set_etb", setThrottleDutyCycle);
|
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"
|
// this is useful one you do "enable etb_auto"
|
||||||
addConsoleActionF("set_etb_output", setTempOutput);
|
addConsoleActionF("set_etb_output", setTempOutput);
|
||||||
addConsoleActionF("set_etb_step", setTempStep);
|
addConsoleActionF("set_etb_step", setTempStep);
|
||||||
|
|
|
@ -49,6 +49,7 @@ PID_AutoTune::PID_AutoTune() {
|
||||||
noiseBand = 0.5;
|
noiseBand = 0.5;
|
||||||
setState(AUTOTUNER_OFF);
|
setState(AUTOTUNER_OFF);
|
||||||
oStep = 10.0;
|
oStep = 10.0;
|
||||||
|
input = output = 0;
|
||||||
SetLookbackSec(10);
|
SetLookbackSec(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ void PID_AutoTune::setPeakType(PidAutoTune_Peak peakType) {
|
||||||
/**
|
/**
|
||||||
* returns true when done, otherwise returns false
|
* returns true when done, otherwise returns false
|
||||||
*/
|
*/
|
||||||
bool PID_AutoTune::Runtime(Logging *logging)
|
bool PID_AutoTune::Runtime(Logging *logger)
|
||||||
{
|
{
|
||||||
// check ready for new input
|
// check ready for new input
|
||||||
unsigned long now = currentTimeMillis();
|
unsigned long now = currentTimeMillis();
|
||||||
|
@ -738,6 +739,7 @@ bool PID_AutoTune::Runtime(Logging *logging)
|
||||||
#if EFI_UNIT_TEST
|
#if EFI_UNIT_TEST
|
||||||
printf("Happy end AMIGOF_PI!\r\n");
|
printf("Happy end AMIGOF_PI!\r\n");
|
||||||
#endif /* EFI_UNIT_TEST */
|
#endif /* EFI_UNIT_TEST */
|
||||||
|
scheduleMsg(logger, "output %f", output);
|
||||||
// converged
|
// converged
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,11 +175,11 @@ static void testPidAutoZigZagZero() {
|
||||||
printf("loop=%d %d\r\n", i, startMockMs);
|
printf("loop=%d %d\r\n", i, startMockMs);
|
||||||
for (; mockTimeMs < CYCLE + startMockMs; mockTimeMs++) {
|
for (; mockTimeMs < CYCLE + startMockMs; mockTimeMs++) {
|
||||||
at.input = zigZagValue(mockTimeMs);
|
at.input = zigZagValue(mockTimeMs);
|
||||||
// bool result = at.Runtime(&logging);
|
bool result = at.Runtime(&logging);
|
||||||
// assertFalseM("should be false#4", result);
|
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() {
|
void testPidAutoZigZag() {
|
||||||
|
|
Loading…
Reference in New Issue