PID refactoring
This commit is contained in:
parent
faafbead72
commit
b9a8bfed2b
|
@ -35,7 +35,7 @@ static SimplePwm auxPidPwm[AUX_PID_COUNT];
|
|||
static OutputPin auxPidPin[AUX_PID_COUNT];
|
||||
|
||||
static pid_s *auxPidS = &persistentState.persistentConfiguration.engineConfiguration.auxPid[0];
|
||||
static Pid auxPid(auxPidS, 0, 90);
|
||||
static Pid auxPid(auxPidS);
|
||||
static Logging *logger;
|
||||
|
||||
static bool isEnabled(int index) {
|
||||
|
|
|
@ -264,7 +264,7 @@ void Engine::setConfig(persistent_config_s *config) {
|
|||
this->config = config;
|
||||
engineConfiguration = &config->engineConfiguration;
|
||||
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) {
|
||||
|
|
|
@ -29,7 +29,7 @@ int alternatorPidResetCounter = 0;
|
|||
|
||||
static SimplePwm 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);
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ static OutputPin outputDirectionClose CCM_OPTIONAL;
|
|||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
static Pid pid(&engineConfiguration->etb, 0, 100);
|
||||
static Pid pid(&engineConfiguration->etb);
|
||||
|
||||
static float prevTps;
|
||||
|
||||
|
@ -109,7 +109,7 @@ static msg_t etbThread(void *arg) {
|
|||
pid.postState(&tsOutputChannels);
|
||||
}
|
||||
if (engineConfiguration->isVerboseETB) {
|
||||
pid.showPidStatus(&logger, "ETB", engineConfiguration->etb.period);
|
||||
pid.showPidStatus(&logger, "ETB");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ EXTERN_ENGINE
|
|||
|
||||
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?
|
||||
static SimplePwm idleSolenoid;
|
||||
|
@ -83,7 +83,7 @@ static void showIdleInfo(void) {
|
|||
|
||||
|
||||
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) {
|
||||
idlePid.showPidStatus(logger, "idle", engineConfiguration->idleRpmPid.period);
|
||||
idlePid.showPidStatus(logger, "idle");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -12,14 +12,14 @@
|
|||
#include "math.h"
|
||||
|
||||
Pid::Pid() {
|
||||
init(NULL, NAN, NAN);
|
||||
init(NULL);
|
||||
}
|
||||
|
||||
Pid::Pid(pid_s *pid, float minResult, float maxResult) {
|
||||
init(pid, minResult, maxResult);
|
||||
Pid::Pid(pid_s *pid) {
|
||||
init(pid);
|
||||
}
|
||||
|
||||
void Pid::init(pid_s *pid, float minResult, float maxResult) {
|
||||
void Pid::init(pid_s *pid) {
|
||||
this->pid = pid;
|
||||
|
||||
dTerm = iTerm = 0;
|
||||
|
@ -123,7 +123,7 @@ void Pid::sleep() {
|
|||
#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",
|
||||
msg,
|
||||
pid->offset,
|
||||
|
|
|
@ -20,8 +20,8 @@ class Pid {
|
|||
|
||||
public:
|
||||
Pid();
|
||||
Pid(pid_s *pid, float minResult, float maxResult);
|
||||
void init(pid_s *pid, float minResult, float maxResult);
|
||||
Pid(pid_s *pid);
|
||||
void init(pid_s *pid);
|
||||
bool isSame(pid_s *pid);
|
||||
|
||||
float getValue(float target, float input);
|
||||
|
@ -42,7 +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);
|
||||
void showPidStatus(Logging *logging, const char*msg);
|
||||
void sleep();
|
||||
private:
|
||||
pid_s *pid;
|
||||
|
|
|
@ -69,7 +69,7 @@ static const char *prevOutputName = NULL;
|
|||
static Logging *logger;
|
||||
#if ! EFI_UNIT_TEST
|
||||
static pid_s *fuelPidS = &persistentState.persistentConfiguration.engineConfiguration.fuelClosedLoopPid;
|
||||
static Pid fuelPid(fuelPidS, -100, 100);
|
||||
static Pid fuelPid(fuelPidS);
|
||||
extern TunerStudioOutputChannels tsOutputChannels;
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue