misc anti shadow

This commit is contained in:
Matthew Kennedy 2023-11-01 14:59:36 -07:00
parent ada987985d
commit 44bd9af964
3 changed files with 40 additions and 40 deletions

View File

@ -37,7 +37,7 @@ static void fireSparkBySettingPinLow(IgnitionEvent *event, IgnitionOutputPin *ou
output->signalFallSparkId = event->sparkId;
if (!output->currentLogicValue && !event->wasSparkLimited) {
if (!output->m_currentLogicValue && !event->wasSparkLimited) {
warning(ObdCode::CUSTOM_OUT_OF_ORDER_COIL, "out-of-order coil off %s", output->getName());
output->outOfOrder = true;
}

View File

@ -22,23 +22,23 @@ Pid::Pid(pid_s *parameters) {
}
void Pid::initPidClass(pid_s *parameters) {
this->parameters = parameters;
m_parameters = parameters;
resetCounter = 0;
reset();
}
bool Pid::isSame(const pid_s *parameters) const {
if (!this->parameters) {
if (!m_parameters) {
// this 'null' could happen on first execution during initialization
return false;
}
efiAssert(ObdCode::OBD_PCM_Processor_Fault, parameters != NULL, "PID::isSame NULL", false);
return this->parameters->pFactor == parameters->pFactor
&& this->parameters->iFactor == parameters->iFactor
&& this->parameters->dFactor == parameters->dFactor
&& this->parameters->offset == parameters->offset
&& this->parameters->periodMs == parameters->periodMs;
return m_parameters->pFactor == parameters->pFactor
&& m_parameters->iFactor == parameters->iFactor
&& m_parameters->dFactor == parameters->dFactor
&& m_parameters->offset == parameters->offset
&& m_parameters->periodMs == parameters->periodMs;
}
/**
@ -46,7 +46,7 @@ bool Pid::isSame(const pid_s *parameters) const {
* @returns Output from the PID controller / the input to the process
*/
float Pid::getOutput(float target, float input) {
float dTime = MS2SEC(GET_PERIOD_LIMITED(parameters));
float dTime = MS2SEC(GET_PERIOD_LIMITED(m_parameters));
return getOutput(target, input, dTime);
}
@ -55,9 +55,9 @@ float Pid::getUnclampedOutput(float target, float input, float dTime) {
this->target = target;
this->input = input;
float pTerm = parameters->pFactor * error;
updateITerm(parameters->iFactor * dTime * error);
dTerm = parameters->dFactor / dTime * (error - previousError);
float pTerm = m_parameters->pFactor * error;
updateITerm(m_parameters->iFactor * dTime * error);
dTerm = m_parameters->dFactor / dTime * (error - previousError);
previousError = error;
@ -75,8 +75,8 @@ float Pid::getUnclampedOutput(float target, float input, float dTime) {
float Pid::getOutput(float target, float input, float dTime) {
float output = getUnclampedOutput(target, input, dTime);
if (output > parameters->maxValue) {
output = parameters->maxValue;
if (output > m_parameters->maxValue) {
output = m_parameters->maxValue;
} else if (output < getMinValue()) {
output = getMinValue();
}
@ -85,9 +85,9 @@ float Pid::getOutput(float target, float input, float dTime) {
}
void Pid::updateFactors(float pFactor, float iFactor, float dFactor) {
parameters->pFactor = pFactor;
parameters->iFactor = iFactor;
parameters->dFactor = dFactor;
m_parameters->pFactor = pFactor;
m_parameters->iFactor = iFactor;
m_parameters->dFactor = dFactor;
reset();
}
@ -99,11 +99,11 @@ void Pid::reset() {
}
float Pid::getP() const {
return parameters->pFactor;
return m_parameters->pFactor;
}
float Pid::getI() const {
return parameters->iFactor;
return m_parameters->iFactor;
}
float Pid::getPrevError() const {
@ -115,15 +115,15 @@ float Pid::getIntegration() const {
}
float Pid::getD() const {
return parameters->dFactor;
return m_parameters->dFactor;
}
float Pid::getOffset(void) const {
return parameters->offset;
return m_parameters->offset;
}
float Pid::getMinValue(void) const {
return parameters->minValue;
return m_parameters->minValue;
}
void Pid::setErrorAmplification(float coef) {
@ -135,7 +135,7 @@ void Pid::setErrorAmplification(float coef) {
void Pid::postState(pid_status_s& pidStatus) const {
pidStatus.output = output;
pidStatus.error = previousError;
pidStatus.pTerm = parameters == nullptr ? 0 : parameters->pFactor * previousError;
pidStatus.pTerm = m_parameters == nullptr ? 0 : m_parameters->pFactor * previousError;
pidStatus.iTerm = iTerm;
pidStatus.dTerm = dTerm;
}
@ -143,7 +143,7 @@ void Pid::postState(pid_status_s& pidStatus) const {
void Pid::sleep() {
#if !EFI_UNIT_TEST
int periodMs = maxI(10, parameters->periodMs);
int periodMs = maxI(10, m_parameters->periodMs);
chThdSleepMilliseconds(periodMs);
#endif /* EFI_UNIT_TEST */
}
@ -152,10 +152,10 @@ void Pid::showPidStatus(const char*msg) const {
efiPrintf("%s settings: offset=%f P=%.5f I=%.5f D=%.5f period=%dms",
msg,
getOffset(),
parameters->pFactor,
parameters->iFactor,
parameters->dFactor,
parameters->periodMs);
m_parameters->pFactor,
m_parameters->iFactor,
m_parameters->dFactor,
m_parameters->periodMs);
efiPrintf("%s status: value=%.2f input=%.2f/target=%.2f iTerm=%.5f dTerm=%.5f",
msg,
@ -172,16 +172,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.
* Here we limit the I-term #353
*/
if (iTerm > parameters->maxValue * 100) {
iTerm = parameters->maxValue * 100;
if (iTerm > m_parameters->maxValue * 100) {
iTerm = m_parameters->maxValue * 100;
}
if (iTerm > iTermMax) {
iTerm = iTermMax;
}
// this is kind of a hack. a proper fix would be having separate additional settings 'maxIValue' and 'minIValye'
if (iTerm < -parameters->maxValue * 100)
iTerm = -parameters->maxValue * 100;
if (iTerm < -m_parameters->maxValue * 100)
iTerm = -m_parameters->maxValue * 100;
if (iTerm < iTermMin) {
iTerm = iTermMin;
}
@ -196,27 +196,27 @@ PidIndustrial::PidIndustrial(pid_s *parameters) : Pid(parameters) {
float PidIndustrial::getOutput(float target, float input, float dTime) {
float ad, bd;
float error = (target - input) * errorAmplificationCoef;
float pTerm = parameters->pFactor * error;
float pTerm = m_parameters->pFactor * error;
// calculate dTerm coefficients
if (fabsf(derivativeFilterLoss) > DBL_EPSILON) {
// restore Td in the Standard form from the Parallel form: Td = Kd / Kc
float Td = parameters->dFactor / parameters->pFactor;
float Td = m_parameters->dFactor / m_parameters->pFactor;
// calculate the backward differences approximation of the derivative term
ad = Td / (Td + dTime / derivativeFilterLoss);
bd = parameters->pFactor * ad / derivativeFilterLoss;
bd = m_parameters->pFactor * ad / derivativeFilterLoss;
} else {
// According to the Theory of limits, if p.derivativeFilterLoss -> 0, then
// lim(ad) = 0; lim(bd) = p.pFactor * Td / dTime = p.dFactor / dTime
// i.e. dTerm becomes equal to Pid's
ad = 0.0f;
bd = parameters->dFactor / dTime;
bd = m_parameters->dFactor / dTime;
}
// (error - previousError) = (target-input) - (target-prevousInput) = -(input - prevousInput)
dTerm = dTerm * ad + (error - previousError) * bd;
updateITerm(parameters->iFactor * dTime * error);
updateITerm(m_parameters->iFactor * dTime * error);
// calculate output and apply the limits
float output = pTerm + iTerm + dTerm + getOffset();
@ -235,7 +235,7 @@ float PidIndustrial::getOutput(float target, float input, float dTime) {
float PidIndustrial::limitOutput(float v) const {
if (v < getMinValue())
v = getMinValue();
if (v > parameters->maxValue)
v = parameters->maxValue;
if (v > m_parameters->maxValue)
v = m_parameters->maxValue;
return v;
}

View File

@ -68,7 +68,7 @@ public:
float iTermMin = -1000000.0;
float iTermMax = 1000000.0;
protected:
pid_s *parameters = nullptr;
pid_s *m_parameters = nullptr;
virtual void updateITerm(float value);
};