From 55010eda5bae83e42f913d45c8824f0b3dd2a1d2 Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 25 May 2017 08:49:04 -0400 Subject: [PATCH] refactoring --- firmware/controllers/idle_thread.cpp | 17 ++++------------- firmware/controllers/math/pid.cpp | 11 +++++++++++ firmware/controllers/math/pid.h | 4 ++++ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/firmware/controllers/idle_thread.cpp b/firmware/controllers/idle_thread.cpp index 5569d8d57a..9fa6ee142d 100644 --- a/firmware/controllers/idle_thread.cpp +++ b/firmware/controllers/idle_thread.cpp @@ -61,16 +61,6 @@ void idleDebug(const char *msg, percent_t value) { scheduleMsg(logger, "idle debug: %s%f", msg, value); } -static void showPidSettings(const char*msg, pid_s *pid) { - scheduleMsg(logger, "%s o=%f P=%.5f I=%.5f D=%.5f dT=%d", - msg, - pid->offset, - pid->pFactor, - pid->iFactor, - pid->dFactor, - engineConfiguration->idleDT); - -} static void showIdleInfo(void) { const char * idleModeStr = getIdle_mode_e(engineConfiguration->idleMode); @@ -91,7 +81,7 @@ static void showIdleInfo(void) { if (engineConfiguration->idleMode == IM_AUTO) { - showPidSettings("idle", &engineConfiguration->idleRpmPid); + idlePid.showPidStatus(logger, "idle", engineConfiguration->idleDT); } } @@ -172,7 +162,7 @@ static float autoIdle(float cltCorrection) { adjustedTargetRpm = engineConfiguration->targetIdleRpm * cltCorrection; - percent_t newValue = idlePid.getValue(adjustedTargetRpm, getRpmE(engine)); + percent_t newValue = idlePid.getValue(adjustedTargetRpm, getRpmE(engine), engineConfiguration->idleDT); return newValue; } @@ -188,6 +178,7 @@ static msg_t ivThread(int param) { */ while (true) { + // todo: in auto mode, speel should be taken from idleDTe chThdSleepMilliseconds(boardConfiguration->idleThreadPeriod); // this value is not used yet @@ -236,7 +227,7 @@ static msg_t ivThread(int param) { } if (engineConfiguration->isVerboseIAC && engineConfiguration->idleMode == IM_AUTO) { - showPidSettings("idle", &engineConfiguration->idleRpmPid); + idlePid.showPidStatus(logger, "idle",engineConfiguration->idleDT); scheduleMsg(logger, "rpm=%d/%d position=%f iTerm=%.5f dTerm=%.5f", getRpmE(engine), adjustedTargetRpm, diff --git a/firmware/controllers/math/pid.cpp b/firmware/controllers/math/pid.cpp index 30a6c8e553..6b91e38adc 100644 --- a/firmware/controllers/math/pid.cpp +++ b/firmware/controllers/math/pid.cpp @@ -113,3 +113,14 @@ void Pid::postState(TunerStudioOutputChannels *tsOutputChannels) { tsOutputChannels->debugFloatField6 = dTerm; } #endif + +void Pid::showPidStatus(Logging *logging, const char*msg, int dTime) { + // todo: dTime should be taken from pid_s + scheduleMsg(logging, "%s o=%f P=%.5f I=%.5f D=%.5f dT=%d", + msg, + pid->offset, + pid->pFactor, + pid->iFactor, + pid->dFactor, + dTime); +} diff --git a/firmware/controllers/math/pid.h b/firmware/controllers/math/pid.h index 9193e4aac3..2837ca5ee1 100644 --- a/firmware/controllers/math/pid.h +++ b/firmware/controllers/math/pid.h @@ -10,6 +10,8 @@ #include "global.h" #include "engine_configuration_generated_structures.h" +#include "datalogging.h" + #if EFI_PROD_CODE || EFI_SIMULATOR #include "tunerstudio_configuration.h" #endif @@ -23,6 +25,7 @@ public: bool isSame(pid_s *pid); float getValue(float target, float input); + // todo: dTime should be taken from pid_s float getValue(float target, float input, float dTime); void updateFactors(float pFactor, float iFactor, float dFactor); void reset(void); @@ -39,6 +42,7 @@ public: float maxResult; float iTerm; float dTerm; // we are remembering this only for debugging purposes + void showPidStatus(Logging *logging, const char*msg, int dTime); private: pid_s *pid;