dead fields & better field name
This commit is contained in:
parent
b85e91d103
commit
f960587dc0
|
@ -17,23 +17,23 @@ Pid::Pid() {
|
||||||
initPidClass(NULL);
|
initPidClass(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pid::Pid(pid_s *pid) {
|
Pid::Pid(pid_s *parameters) {
|
||||||
initPidClass(pid);
|
initPidClass(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pid::initPidClass(pid_s *pid) {
|
void Pid::initPidClass(pid_s *parameters) {
|
||||||
this->pid = pid;
|
this->parameters = parameters;
|
||||||
resetCounter = 0;
|
resetCounter = 0;
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Pid::isSame(pid_s *pid) const {
|
bool Pid::isSame(pid_s *parameters) const {
|
||||||
return this->pid->pFactor == pid->pFactor
|
return this->parameters->pFactor == parameters->pFactor
|
||||||
&& this->pid->iFactor == pid->iFactor
|
&& this->parameters->iFactor == parameters->iFactor
|
||||||
&& this->pid->dFactor == pid->dFactor
|
&& this->parameters->dFactor == parameters->dFactor
|
||||||
&& this->pid->offset == pid->offset
|
&& this->parameters->offset == parameters->offset
|
||||||
&& this->pid->periodMs == pid->periodMs;
|
&& this->parameters->periodMs == parameters->periodMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,7 +41,7 @@ bool Pid::isSame(pid_s *pid) const {
|
||||||
* @returns Output from the PID controller / the input to the process
|
* @returns Output from the PID controller / the input to the process
|
||||||
*/
|
*/
|
||||||
float Pid::getOutput(float target, float input) {
|
float Pid::getOutput(float target, float input) {
|
||||||
float dTime = MS2SEC(GET_PERIOD_LIMITED(pid));
|
float dTime = MS2SEC(GET_PERIOD_LIMITED(parameters));
|
||||||
return getOutput(target, input, dTime);
|
return getOutput(target, input, dTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,13 +50,13 @@ float Pid::getUnclampedOutput(float target, float input, float dTime) {
|
||||||
this->target = target;
|
this->target = target;
|
||||||
this->input = input;
|
this->input = input;
|
||||||
|
|
||||||
float pTerm = pid->pFactor * error;
|
float pTerm = parameters->pFactor * error;
|
||||||
updateITerm(pid->iFactor * dTime * error);
|
updateITerm(parameters->iFactor * dTime * error);
|
||||||
dTerm = pid->dFactor / dTime * (error - previousError);
|
dTerm = parameters->dFactor / dTime * (error - previousError);
|
||||||
|
|
||||||
previousError = error;
|
previousError = error;
|
||||||
|
|
||||||
return pTerm + iTerm + dTerm + pid->offset;
|
return pTerm + iTerm + dTerm + parameters->offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,19 +65,19 @@ float Pid::getUnclampedOutput(float target, float input, float dTime) {
|
||||||
float Pid::getOutput(float target, float input, float dTime) {
|
float Pid::getOutput(float target, float input, float dTime) {
|
||||||
float output = getUnclampedOutput(target, input, dTime);
|
float output = getUnclampedOutput(target, input, dTime);
|
||||||
|
|
||||||
if (output > pid->maxValue) {
|
if (output > parameters->maxValue) {
|
||||||
output = pid->maxValue;
|
output = parameters->maxValue;
|
||||||
} else if (output < pid->minValue) {
|
} else if (output < parameters->minValue) {
|
||||||
output = pid->minValue;
|
output = parameters->minValue;
|
||||||
}
|
}
|
||||||
this->output = output;
|
this->output = output;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pid::updateFactors(float pFactor, float iFactor, float dFactor) {
|
void Pid::updateFactors(float pFactor, float iFactor, float dFactor) {
|
||||||
pid->pFactor = pFactor;
|
parameters->pFactor = pFactor;
|
||||||
pid->iFactor = iFactor;
|
parameters->iFactor = iFactor;
|
||||||
pid->dFactor = dFactor;
|
parameters->dFactor = dFactor;
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,11 +89,11 @@ void Pid::reset(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
float Pid::getP(void) const {
|
float Pid::getP(void) const {
|
||||||
return pid->pFactor;
|
return parameters->pFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Pid::getI(void) const {
|
float Pid::getI(void) const {
|
||||||
return pid->iFactor;
|
return parameters->iFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Pid::getPrevError(void) const {
|
float Pid::getPrevError(void) const {
|
||||||
|
@ -105,11 +105,11 @@ float Pid::getIntegration(void) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
float Pid::getD(void) const {
|
float Pid::getD(void) const {
|
||||||
return pid->dFactor;
|
return parameters->dFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Pid::getOffset(void) const {
|
float Pid::getOffset(void) const {
|
||||||
return pid->offset;
|
return parameters->offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pid::setErrorAmplification(float coef) {
|
void Pid::setErrorAmplification(float coef) {
|
||||||
|
@ -131,18 +131,18 @@ void Pid::postState(TunerStudioOutputChannels *tsOutputChannels, int pMult) {
|
||||||
tsOutputChannels->debugFloatField4 = getI();
|
tsOutputChannels->debugFloatField4 = getI();
|
||||||
tsOutputChannels->debugFloatField5 = getD();
|
tsOutputChannels->debugFloatField5 = getD();
|
||||||
tsOutputChannels->debugFloatField6 = dTerm;
|
tsOutputChannels->debugFloatField6 = dTerm;
|
||||||
// tsOutputChannels->debugFloatField6 = pid->minValue;
|
// tsOutputChannels->debugFloatField6 = parameters->minValue;
|
||||||
tsOutputChannels->debugFloatField7 = pid->maxValue;
|
tsOutputChannels->debugFloatField7 = parameters->maxValue;
|
||||||
tsOutputChannels->debugIntField1 = getP() * pMult;
|
tsOutputChannels->debugIntField1 = getP() * pMult;
|
||||||
tsOutputChannels->debugIntField2 = getOffset();
|
tsOutputChannels->debugIntField2 = getOffset();
|
||||||
tsOutputChannels->debugIntField3 = resetCounter;
|
tsOutputChannels->debugIntField3 = resetCounter;
|
||||||
tsOutputChannels->debugIntField4 = pid->periodMs;
|
tsOutputChannels->debugIntField4 = parameters->periodMs;
|
||||||
}
|
}
|
||||||
#endif /* EFI_TUNER_STUDIO */
|
#endif /* EFI_TUNER_STUDIO */
|
||||||
|
|
||||||
void Pid::sleep() {
|
void Pid::sleep() {
|
||||||
#if !EFI_UNIT_TEST
|
#if !EFI_UNIT_TEST
|
||||||
int periodMs = maxI(10, pid->periodMs);
|
int periodMs = maxI(10, parameters->periodMs);
|
||||||
chThdSleepMilliseconds(periodMs);
|
chThdSleepMilliseconds(periodMs);
|
||||||
#endif /* EFI_UNIT_TEST */
|
#endif /* EFI_UNIT_TEST */
|
||||||
}
|
}
|
||||||
|
@ -150,11 +150,11 @@ void Pid::sleep() {
|
||||||
void Pid::showPidStatus(Logging *logging, const char*msg) {
|
void Pid::showPidStatus(Logging *logging, const char*msg) {
|
||||||
scheduleMsg(logging, "%s settings: offset=%d P=%.5f I=%.5f D=%.5f period=%dms",
|
scheduleMsg(logging, "%s settings: offset=%d P=%.5f I=%.5f D=%.5f period=%dms",
|
||||||
msg,
|
msg,
|
||||||
pid->offset,
|
parameters->offset,
|
||||||
pid->pFactor,
|
parameters->pFactor,
|
||||||
pid->iFactor,
|
parameters->iFactor,
|
||||||
pid->dFactor,
|
parameters->dFactor,
|
||||||
pid->periodMs);
|
parameters->periodMs);
|
||||||
|
|
||||||
scheduleMsg(logging, "%s status: value=%.2f input=%.2f/target=%.2f iTerm=%.5f dTerm=%.5f",
|
scheduleMsg(logging, "%s status: value=%.2f input=%.2f/target=%.2f iTerm=%.5f dTerm=%.5f",
|
||||||
msg,
|
msg,
|
||||||
|
@ -171,16 +171,16 @@ void Pid::updateITerm(float value) {
|
||||||
* If we have exceeded the ability of the controlled device to hit target, the I factor will keep accumulating and approach infinity.
|
* If we have exceeded the ability of the controlled device to hit target, the I factor will keep accumulating and approach infinity.
|
||||||
* Here we limit the I-term #353
|
* Here we limit the I-term #353
|
||||||
*/
|
*/
|
||||||
if (iTerm > pid->maxValue * 100) {
|
if (iTerm > parameters->maxValue * 100) {
|
||||||
iTerm = pid->maxValue * 100;
|
iTerm = parameters->maxValue * 100;
|
||||||
}
|
}
|
||||||
if (iTerm > iTermMax) {
|
if (iTerm > iTermMax) {
|
||||||
iTerm = iTermMax;
|
iTerm = iTermMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is kind of a hack. a proper fix would be having separate additional settings 'maxIValue' and 'minIValye'
|
// this is kind of a hack. a proper fix would be having separate additional settings 'maxIValue' and 'minIValye'
|
||||||
if (iTerm < -pid->maxValue * 100)
|
if (iTerm < -parameters->maxValue * 100)
|
||||||
iTerm = -pid->maxValue * 100;
|
iTerm = -parameters->maxValue * 100;
|
||||||
if (iTerm < iTermMin) {
|
if (iTerm < iTermMin) {
|
||||||
iTerm = iTermMin;
|
iTerm = iTermMin;
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ PidCic::PidCic() {
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
PidCic::PidCic(pid_s *pid) : Pid(pid) {
|
PidCic::PidCic(pid_s *parameters) : Pid(parameters) {
|
||||||
// call our derived reset()
|
// call our derived reset()
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,9 @@ class Pid : public pid_state_s {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Pid();
|
Pid();
|
||||||
explicit Pid(pid_s *pid);
|
explicit Pid(pid_s *parameters);
|
||||||
void initPidClass(pid_s *pid);
|
void initPidClass(pid_s *parameters);
|
||||||
bool isSame(pid_s *pid) const;
|
bool isSame(pid_s *parameters) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This version of the method takes dTime from pid_s
|
* This version of the method takes dTime from pid_s
|
||||||
|
@ -61,8 +61,6 @@ public:
|
||||||
void postState(TunerStudioOutputChannels *tsOutputChannels);
|
void postState(TunerStudioOutputChannels *tsOutputChannels);
|
||||||
void postState(TunerStudioOutputChannels *tsOutputChannels, int pMult);
|
void postState(TunerStudioOutputChannels *tsOutputChannels, int pMult);
|
||||||
#endif /* EFI_TUNER_STUDIO */
|
#endif /* EFI_TUNER_STUDIO */
|
||||||
float minResult;
|
|
||||||
float maxResult;
|
|
||||||
void showPidStatus(Logging *logging, const char*msg);
|
void showPidStatus(Logging *logging, const char*msg);
|
||||||
void sleep();
|
void sleep();
|
||||||
int resetCounter;
|
int resetCounter;
|
||||||
|
@ -70,7 +68,7 @@ public:
|
||||||
float iTermMin = -1000000.0;
|
float iTermMin = -1000000.0;
|
||||||
float iTermMax = 1000000.0;
|
float iTermMax = 1000000.0;
|
||||||
private:
|
private:
|
||||||
pid_s *pid;
|
pid_s *parameters;
|
||||||
|
|
||||||
float previousError;
|
float previousError;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue