From db29fac09e417df4eaeef7337c229c214995e36f Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 22 Nov 2018 18:56:51 -0500 Subject: [PATCH] PID auto tune unit test --- .../controllers/algo/auto_generated_enums.cpp | 30 ++++++++++++++++++- .../controllers/algo/auto_generated_enums.h | 4 ++- firmware/controllers/algo/rusefi_enums.h | 19 ++++++++++++ firmware/controllers/math/pid_auto_tune.cpp | 8 ++--- firmware/controllers/math/pid_auto_tune.h | 28 +++-------------- 5 files changed, 59 insertions(+), 30 deletions(-) diff --git a/firmware/controllers/algo/auto_generated_enums.cpp b/firmware/controllers/algo/auto_generated_enums.cpp index 50696410ae..8bd9252f04 100644 --- a/firmware/controllers/algo/auto_generated_enums.cpp +++ b/firmware/controllers/algo/auto_generated_enums.cpp @@ -1,6 +1,6 @@ // auto-generated from.\controllers/algo/rusefi_enums.h // by enum2string.jar tool -// on Wed Nov 21 21:47:19 EST 2018 +// on Thu Nov 22 18:48:26 EST 2018 // see also gen_config_and_enums.bat @@ -946,3 +946,31 @@ case TCHARGE_MODE_RPM_TPS: } return NULL; } +const char *getPidAutoTune_Peak(PidAutoTune_Peak value){ +switch(value) { +case MAXIMUM: + return "MAXIMUM"; +case NOT_A_PEAK: + return "NOT_A_PEAK"; + } + return NULL; +} +const char *getPidAutoTune_AutoTunerState(PidAutoTune_AutoTunerState value){ +switch(value) { +case AUTOTUNER_OFF: + return "AUTOTUNER_OFF"; +case CONVERGED: + return "CONVERGED"; +case FAILED: + return "FAILED"; +case RELAY_STEP_DOWN: + return "RELAY_STEP_DOWN"; +case RELAY_STEP_UP: + return "RELAY_STEP_UP"; +case STEADY_STATE_AFTER_STEP_UP: + return "STEADY_STATE_AFTER_STEP_UP"; +case STEADY_STATE_AT_BASELINE: + return "STEADY_STATE_AT_BASELINE"; + } + return NULL; +} diff --git a/firmware/controllers/algo/auto_generated_enums.h b/firmware/controllers/algo/auto_generated_enums.h index 17c99bec40..69ee8dc33e 100644 --- a/firmware/controllers/algo/auto_generated_enums.h +++ b/firmware/controllers/algo/auto_generated_enums.h @@ -1,6 +1,6 @@ // auto-generated from.\controllers/algo/rusefi_enums.h // by enum2string.jar tool -// on Wed Nov 21 20:48:18 EST 2018 +// on Thu Nov 22 18:48:26 EST 2018 // see also gen_config_and_enums.bat @@ -43,4 +43,6 @@ const char *getChamber_style_e(chamber_style_e value); const char *getCan_nbc_e(can_nbc_e value); const char *getHip_state_e(hip_state_e value); const char *getTChargeMode_e(tChargeMode_e value); +const char *getPidAutoTune_Peak(PidAutoTune_Peak value); +const char *getPidAutoTune_AutoTunerState(PidAutoTune_AutoTunerState value); #endif /*_A_H_HEADER_ */ diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index 4c3d29f530..9f122305cc 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -950,4 +950,23 @@ typedef enum { Force_4bytes_size_tChargeMode_e = ENUM_32_BITS, } tChargeMode_e; +// peak type +typedef enum { + MINIMUM = -1, + NOT_A_PEAK = 0, + MAXIMUM = 1 +} PidAutoTune_Peak; + +// auto tuner state +typedef enum { + AUTOTUNER_OFF = 0, + STEADY_STATE_AT_BASELINE = 1, + STEADY_STATE_AFTER_STEP_UP = 2, + RELAY_STEP_UP = 4, + RELAY_STEP_DOWN = 8, + CONVERGED = 16, + FAILED = 128 +} PidAutoTune_AutoTunerState; + + #endif /* RUSEFI_ENUMS_H_ */ diff --git a/firmware/controllers/math/pid_auto_tune.cpp b/firmware/controllers/math/pid_auto_tune.cpp index f08987e481..b206a25285 100644 --- a/firmware/controllers/math/pid_auto_tune.cpp +++ b/firmware/controllers/math/pid_auto_tune.cpp @@ -94,17 +94,17 @@ double PID_AutoTune::calculatePhaseLag(double inducedAmplitude) } } -void PID_AutoTune::setState(AutoTunerState state) { +void PID_AutoTune::setState(PidAutoTune_AutoTunerState state) { this->state = state; #if EFI_UNIT_TEST - printf("setState %d\r\n", state); + printf("setState %s\r\n", getPidAutoTune_AutoTunerState(state)); #endif /* EFI_UNIT_TEST */ } -void PID_AutoTune::setPeakType(Peak peakType) { +void PID_AutoTune::setPeakType(PidAutoTune_Peak peakType) { this->peakType = peakType; #if EFI_UNIT_TEST - printf("peakType %d\r\n", peakType); + printf("peakType %s\r\n", getPidAutoTune_Peak(peakType)); #endif /* EFI_UNIT_TEST */ } diff --git a/firmware/controllers/math/pid_auto_tune.h b/firmware/controllers/math/pid_auto_tune.h index 953a46d4e7..8a015dbc97 100644 --- a/firmware/controllers/math/pid_auto_tune.h +++ b/firmware/controllers/math/pid_auto_tune.h @@ -95,26 +95,6 @@ public: NO_OVERSHOOT_PID }; - // peak type - enum Peak - { - MINIMUM = -1, - NOT_A_PEAK = 0, - MAXIMUM = 1 - }; - - // auto tuner state - enum AutoTunerState - { - AUTOTUNER_OFF = 0, - STEADY_STATE_AT_BASELINE = 1, - STEADY_STATE_AFTER_STEP_UP = 2, - RELAY_STEP_UP = 4, - RELAY_STEP_DOWN = 8, - CONVERGED = 16, - FAILED = 128 - }; - // tuning rule divisor enum { @@ -162,8 +142,8 @@ public: unsigned long sampleTime; byte nLookBack; - void setState(AutoTunerState state); - void setPeakType(Peak peakType); + void setState(PidAutoTune_AutoTunerState state); + void setPeakType(PidAutoTune_Peak peakType); private: @@ -177,9 +157,9 @@ private: double noiseBand; byte controlType; // * selects autotune algorithm - enum AutoTunerState state; // * state of autotuner finite state machine + PidAutoTune_AutoTunerState state; // * state of autotuner finite state machine unsigned long lastTime; - enum Peak peakType; + PidAutoTune_Peak peakType; unsigned long lastPeakTime[STEPCOUNT]; // * peak time, most recent in array element 0 double lastPeaks[STEPCOUNT]; // * peak value, most recent in array element 0 double lastInputs[101]; // * process values, most recent in array element 0