better logging

This commit is contained in:
rusEfi 2018-11-26 21:14:21 -05:00
parent e6d44fb85f
commit b4a09b2e71
2 changed files with 13 additions and 10 deletions

View File

@ -52,7 +52,6 @@ void PID_AutoTune::Cancel()
} }
void PID_AutoTune::reset() { void PID_AutoTune::reset() {
running = false;
controlType = ZIEGLER_NICHOLS_PID; controlType = ZIEGLER_NICHOLS_PID;
noiseBand = 0.5; noiseBand = 0.5;
@ -161,6 +160,7 @@ bool PID_AutoTune::Runtime(Logging *logger)
} }
else else
{ {
scheduleMsg(logger, "starting...");
setState(RELAY_STEP_UP); setState(RELAY_STEP_UP);
} }
} }
@ -171,6 +171,8 @@ bool PID_AutoTune::Runtime(Logging *logger)
#if EFI_UNIT_TEST #if EFI_UNIT_TEST
printf("too soon for new input %d %d %d\r\n", now, lastTime, sampleTime); printf("too soon for new input %d %d %d\r\n", now, lastTime, sampleTime);
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */
scheduleMsg(logger, "AT skipping now=%d %d %d", now, lastTime, sampleTime);
return false; return false;
} }
@ -189,11 +191,13 @@ bool PID_AutoTune::Runtime(Logging *logger)
// check input and change relay state if necessary // check input and change relay state if necessary
if ((state == RELAY_STEP_UP) && (refVal > setpoint + workingNoiseBand)) if ((state == RELAY_STEP_UP) && (refVal > setpoint + workingNoiseBand))
{ {
scheduleMsg(logger, "noise crossed up %f s=%f n=%f", refVal, setpoint, workingNoiseBand);
setState(RELAY_STEP_DOWN); setState(RELAY_STEP_DOWN);
justChanged = true; justChanged = true;
} }
else if ((state == RELAY_STEP_DOWN) && (refVal < setpoint - workingNoiseBand)) else if ((state == RELAY_STEP_DOWN) && (refVal < setpoint - workingNoiseBand))
{ {
scheduleMsg(logger, "noise crossed down %f s=%f n=%f", refVal, setpoint, workingNoiseBand);
setState(RELAY_STEP_UP); setState(RELAY_STEP_UP);
justChanged = true; justChanged = true;
} }
@ -216,7 +220,7 @@ bool PID_AutoTune::Runtime(Logging *logger)
#if defined (AUTOTUNE_DEBUG) #if defined (AUTOTUNE_DEBUG)
Serial.print(F("asymmetry ")); Serial.print(F("asymmetry "));
Serial.println(asymmetry); Serial.println(asymmetry);
#endif #endif /* AUTOTUNE_DEBUG */
#if EFI_UNIT_TEST #if EFI_UNIT_TEST
printf("asymmetry=%f\r\n", asymmetry); printf("asymmetry=%f\r\n", asymmetry);
@ -264,7 +268,7 @@ bool PID_AutoTune::Runtime(Logging *logger)
Serial.println(deltaRelayBias); Serial.println(deltaRelayBias);
Serial.print(F("relayBias ")); Serial.print(F("relayBias "));
Serial.println(relayBias); Serial.println(relayBias);
#endif #endif /* AUTOTUNE_DEBUG */
#if EFI_UNIT_TEST #if EFI_UNIT_TEST
printf("deltaRelayBias=%f relayBias=%f\r\n", deltaRelayBias, relayBias); printf("deltaRelayBias=%f relayBias=%f\r\n", deltaRelayBias, relayBias);
@ -289,7 +293,7 @@ bool PID_AutoTune::Runtime(Logging *logger)
lastStepTime[0] = now; lastStepTime[0] = now;
sumInputSinceLastStep[0] = 0.0; sumInputSinceLastStep[0] = 0.0;
#if defined (AUTOTUNE_DEBUG #if defined (AUTOTUNE_DEBUG)
for (byte i = 1; i < (stepCount > 4 ? 5 : stepCount); i++) for (byte i = 1; i < (stepCount > 4 ? 5 : stepCount); i++)
{ {
Serial.print(F("step time ")); Serial.print(F("step time "));
@ -297,7 +301,7 @@ bool PID_AutoTune::Runtime(Logging *logger)
Serial.print(F("step sum ")); Serial.print(F("step sum "));
Serial.println(sumInputSinceLastStep[i]); Serial.println(sumInputSinceLastStep[i]);
} }
#endif #endif /* AUTOTUNE_DEBUG */
#endif // if defined AUTOTUNE_RELAY_BIAS #endif // if defined AUTOTUNE_RELAY_BIAS
@ -313,6 +317,7 @@ bool PID_AutoTune::Runtime(Logging *logger)
#if defined (AUTOTUNE_RELAY_BIAS) #if defined (AUTOTUNE_RELAY_BIAS)
setOutput(outputStart + workingOstep + relayBias); setOutput(outputStart + workingOstep + relayBias);
#else #else
scheduleMsg(logger, "AT adding %f", workingOutputstep);
setOutput(outputStart + workingOutputstep); setOutput(outputStart + workingOutputstep);
#endif #endif
@ -323,6 +328,7 @@ bool PID_AutoTune::Runtime(Logging *logger)
#if defined (AUTOTUNE_RELAY_BIAS) #if defined (AUTOTUNE_RELAY_BIAS)
setOutput(outputStart - workingOstep + relayBias); setOutput(outputStart - workingOstep + relayBias);
#else #else
scheduleMsg(logger, "AT subtracting %f", workingOutputstep);
setOutput(outputStart - workingOutputstep); setOutput(outputStart - workingOutputstep);
#endif #endif
@ -689,6 +695,7 @@ bool PID_AutoTune::Runtime(Logging *logger)
// autotune algorithm has terminated // autotune algorithm has terminated
// reset autotuner variables // reset autotuner variables
scheduleMsg(logger, "AT done");
setOutput( outputStart); setOutput( outputStart);
if (state == FAILED) if (state == FAILED)
@ -789,9 +796,7 @@ float PID_AutoTune::GetKd()
void PID_AutoTune::setOutput(float output) { void PID_AutoTune::setOutput(float output) {
this->output = output; this->output = output;
if (logger != NULL) { scheduleMsg(logger, "setOutput %f %s", output, getPidAutoTune_AutoTunerState(state));
scheduleMsg(logger, "setOutput %f %s", output, getPidAutoTune_AutoTunerState(state));
}
#if EFI_UNIT_TEST #if EFI_UNIT_TEST
printf("output=%f\r\n", output); printf("output=%f\r\n", output);

View File

@ -159,8 +159,6 @@ private:
double setpoint; double setpoint;
bool running; // todo: remove this
double noiseBand; double noiseBand;
byte controlType; // * selects autotune algorithm byte controlType; // * selects autotune algorithm