PID refactoring

This commit is contained in:
rusEfi 2017-05-29 23:15:07 -04:00
parent faafbead72
commit b9a8bfed2b
8 changed files with 17 additions and 17 deletions

View File

@ -35,7 +35,7 @@ static SimplePwm auxPidPwm[AUX_PID_COUNT];
static OutputPin auxPidPin[AUX_PID_COUNT]; static OutputPin auxPidPin[AUX_PID_COUNT];
static pid_s *auxPidS = &persistentState.persistentConfiguration.engineConfiguration.auxPid[0]; static pid_s *auxPidS = &persistentState.persistentConfiguration.engineConfiguration.auxPid[0];
static Pid auxPid(auxPidS, 0, 90); static Pid auxPid(auxPidS);
static Logging *logger; static Logging *logger;
static bool isEnabled(int index) { static bool isEnabled(int index) {

View File

@ -264,7 +264,7 @@ void Engine::setConfig(persistent_config_s *config) {
this->config = config; this->config = config;
engineConfiguration = &config->engineConfiguration; engineConfiguration = &config->engineConfiguration;
memset(config, 0, sizeof(persistent_config_s)); memset(config, 0, sizeof(persistent_config_s));
engineState.warmupAfrPid.init(&config->engineConfiguration.warmupAfrPid, 0.5, 1.5); engineState.warmupAfrPid.init(&config->engineConfiguration.warmupAfrPid);
} }
void Engine::printKnockState(void) { void Engine::printKnockState(void) {

View File

@ -29,7 +29,7 @@ int alternatorPidResetCounter = 0;
static SimplePwm alternatorControl; static SimplePwm alternatorControl;
static pid_s *altPidS = &persistentState.persistentConfiguration.engineConfiguration.alternatorControl; static pid_s *altPidS = &persistentState.persistentConfiguration.engineConfiguration.alternatorControl;
static Pid altPid(altPidS, 1, 90); static Pid altPid(altPidS);
static THD_WORKING_AREA(alternatorControlThreadStack, UTILITY_THREAD_STACK_SIZE); static THD_WORKING_AREA(alternatorControlThreadStack, UTILITY_THREAD_STACK_SIZE);

View File

@ -73,7 +73,7 @@ static OutputPin outputDirectionClose CCM_OPTIONAL;
EXTERN_ENGINE; EXTERN_ENGINE;
static Pid pid(&engineConfiguration->etb, 0, 100); static Pid pid(&engineConfiguration->etb);
static float prevTps; static float prevTps;
@ -109,7 +109,7 @@ static msg_t etbThread(void *arg) {
pid.postState(&tsOutputChannels); pid.postState(&tsOutputChannels);
} }
if (engineConfiguration->isVerboseETB) { if (engineConfiguration->isVerboseETB) {
pid.showPidStatus(&logger, "ETB", engineConfiguration->etb.period); pid.showPidStatus(&logger, "ETB");
} }

View File

@ -45,7 +45,7 @@ EXTERN_ENGINE
static bool shouldResetPid = false; static bool shouldResetPid = false;
static Pid idlePid(&engineConfiguration->idleRpmPid, 1, 99); static Pid idlePid(&engineConfiguration->idleRpmPid);
// todo: extract interface for idle valve hardware, with solenoid and stepper implementations? // todo: extract interface for idle valve hardware, with solenoid and stepper implementations?
static SimplePwm idleSolenoid; static SimplePwm idleSolenoid;
@ -83,7 +83,7 @@ static void showIdleInfo(void) {
if (engineConfiguration->idleMode == IM_AUTO) { if (engineConfiguration->idleMode == IM_AUTO) {
idlePid.showPidStatus(logger, "idle", engineConfiguration->idleRpmPid.period); idlePid.showPidStatus(logger, "idle");
} }
} }
@ -239,7 +239,7 @@ static msg_t ivThread(int param) {
} }
if (engineConfiguration->isVerboseIAC && engineConfiguration->idleMode == IM_AUTO) { if (engineConfiguration->isVerboseIAC && engineConfiguration->idleMode == IM_AUTO) {
idlePid.showPidStatus(logger, "idle", engineConfiguration->idleRpmPid.period); idlePid.showPidStatus(logger, "idle");
} }

View File

@ -12,14 +12,14 @@
#include "math.h" #include "math.h"
Pid::Pid() { Pid::Pid() {
init(NULL, NAN, NAN); init(NULL);
} }
Pid::Pid(pid_s *pid, float minResult, float maxResult) { Pid::Pid(pid_s *pid) {
init(pid, minResult, maxResult); init(pid);
} }
void Pid::init(pid_s *pid, float minResult, float maxResult) { void Pid::init(pid_s *pid) {
this->pid = pid; this->pid = pid;
dTerm = iTerm = 0; dTerm = iTerm = 0;
@ -123,7 +123,7 @@ void Pid::sleep() {
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */
} }
void Pid::showPidStatus(Logging *logging, const char*msg, int dTime) { void Pid::showPidStatus(Logging *logging, const char*msg) {
scheduleMsg(logging, "%s settings: offset=%d P=%.5f I=%.5f D=%.5f dT=%d", scheduleMsg(logging, "%s settings: offset=%d P=%.5f I=%.5f D=%.5f dT=%d",
msg, msg,
pid->offset, pid->offset,

View File

@ -20,8 +20,8 @@ class Pid {
public: public:
Pid(); Pid();
Pid(pid_s *pid, float minResult, float maxResult); Pid(pid_s *pid);
void init(pid_s *pid, float minResult, float maxResult); void init(pid_s *pid);
bool isSame(pid_s *pid); bool isSame(pid_s *pid);
float getValue(float target, float input); float getValue(float target, float input);
@ -42,7 +42,7 @@ public:
float maxResult; float maxResult;
float iTerm; float iTerm;
float dTerm; // we are remembering this only for debugging purposes float dTerm; // we are remembering this only for debugging purposes
void showPidStatus(Logging *logging, const char*msg, int dTime); void showPidStatus(Logging *logging, const char*msg);
void sleep(); void sleep();
private: private:
pid_s *pid; pid_s *pid;

View File

@ -69,7 +69,7 @@ static const char *prevOutputName = NULL;
static Logging *logger; static Logging *logger;
#if ! EFI_UNIT_TEST #if ! EFI_UNIT_TEST
static pid_s *fuelPidS = &persistentState.persistentConfiguration.engineConfiguration.fuelClosedLoopPid; static pid_s *fuelPidS = &persistentState.persistentConfiguration.engineConfiguration.fuelClosedLoopPid;
static Pid fuelPid(fuelPidS, -100, 100); static Pid fuelPid(fuelPidS);
extern TunerStudioOutputChannels tsOutputChannels; extern TunerStudioOutputChannels tsOutputChannels;
#endif #endif