rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Data Fields | Private Member Functions
PidIndustrial Class Reference

#include <efi_pid.h>

Inheritance diagram for PidIndustrial:
Inheritance graph
[legend]
Collaboration diagram for PidIndustrial:
Collaboration graph
[legend]

Public Member Functions

 PidIndustrial ()
 
 PidIndustrial (pid_s *pid)
 
float getOutput (float target, float input, float dTime) override
 
float getOutput (float target, float input)
 
virtual float getOutput (float target, float input, float dTime)
 
- Public Member Functions inherited from Pid
 Pid ()
 
 Pid (pid_s *parameters)
 
void initPidClass (pid_s *parameters)
 
bool isSame (const pid_s *parameters) const
 
float getOutput (float target, float input)
 
float getUnclampedOutput (float target, float input, float dTime)
 
void updateFactors (float pFactor, float iFactor, float dFactor)
 
virtual void reset ()
 
float getP () const
 
float getI () const
 
float getD () const
 
float getOffset () const
 
float getMinValue () const
 
float getIntegration (void) const
 
float getPrevError (void) const
 
void setErrorAmplification (float coef)
 
void postState (pid_status_s &pidStatus) const
 
void showPidStatus (const char *msg) const
 
void sleep ()
 

Data Fields

float antiwindupFreq = 0.0f
 
float derivativeFilterLoss = 0.0f
 
- Data Fields inherited from Pid
int resetCounter
 
float iTermMin = -1000000.0
 
float iTermMax = 1000000.0
 
- Data Fields inherited from pid_state_s
float iTerm = (float)0
 
float dTerm = (float)0
 
float target = (float)0
 
float input = (float)0
 
float output = (float)0
 
float errorAmplificationCoef = (float)0
 
float previousError = (float)0
 

Private Member Functions

float limitOutput (float v) const
 

Additional Inherited Members

- Protected Member Functions inherited from Pid
virtual void updateITerm (float value)
 
- Protected Attributes inherited from Pid
pid_sparameters = nullptr
 

Detailed Description

A PID with derivative filtering (backward differences) and integrator anti-windup. See: Wittenmark B., Astrom K., Arzen K. IFAC Professional Brief. Computer Control: An Overview. Two additional parameters used: derivativeFilterLoss and antiwindupFreq (If both are 0, then this controller is identical to PidParallelController)

TODO: should PidIndustrial replace all usages of Pid/PidParallelController?

Definition at line 113 of file efi_pid.h.

Constructor & Destructor Documentation

◆ PidIndustrial() [1/2]

PidIndustrial::PidIndustrial ( )

Definition at line 243 of file efi_pid.cpp.

243 : Pid() {
244}
Pid()
Definition efi_pid.cpp:16

◆ PidIndustrial() [2/2]

PidIndustrial::PidIndustrial ( pid_s pid)
explicit

Definition at line 246 of file efi_pid.cpp.

246 : Pid(p_parameters) {
247}

Member Function Documentation

◆ getOutput() [1/3]

float Pid::getOutput ( float  p_target,
float  p_input 
)

This version of the method takes dTime from pid_s

Parameters
Controllerinput / process output
Returns
Output from the PID controller / the input to the process
Parameters
Controllerinput / process output
Returns
Output from the PID controller / the input to the process

Definition at line 47 of file efi_pid.cpp.

56 {
57 efiAssert(ObdCode::OBD_PCM_Processor_Fault, parameters != nullptr, "PID::getOutput nullptr", 0);
58 float dTime = MS2SEC(GET_PERIOD_LIMITED(parameters));
59 return getOutput(p_target, p_input, dTime);
60}
pid_s * parameters
Definition efi_pid.h:71
float getOutput(float target, float input, float dTime) override
Definition efi_pid.cpp:249
@ OBD_PCM_Processor_Fault

◆ getOutput() [2/3]

float Pid::getOutput ( float  p_target,
float  p_input,
float  dTime 
)
virtual
Parameters
dTimeseconds probably? :)

Reimplemented from Pid.

Definition at line 48 of file efi_pid.cpp.

84 {
85 float l_output = getUnclampedOutput(p_target, p_input, dTime);
86
87 if (l_output > parameters->maxValue) {
88 l_output = parameters->maxValue;
89 } else if (l_output < getMinValue()) {
90 l_output = getMinValue();
91 }
92 output = l_output;
93 return output;
94}
float getUnclampedOutput(float target, float input, float dTime)
Definition efi_pid.cpp:62
float getMinValue() const
Definition efi_pid.cpp:134

◆ getOutput() [3/3]

float PidIndustrial::getOutput ( float  p_target,
float  p_input,
float  dTime 
)
overridevirtual
Parameters
dTimeseconds probably? :)

Reimplemented from Pid.

Definition at line 249 of file efi_pid.cpp.

249 {
250 float ad, bd;
251 float error = (p_target - p_input) * errorAmplificationCoef;
252 float pTerm = parameters->pFactor * error;
253
254 // calculate dTerm coefficients
255 if (fabsf(derivativeFilterLoss) > DBL_EPSILON) {
256 // restore Td in the Standard form from the Parallel form: Td = Kd / Kc
257 float Td = parameters->dFactor / parameters->pFactor;
258 // calculate the backward differences approximation of the derivative term
259 ad = Td / (Td + dTime / derivativeFilterLoss);
261 } else {
262 // According to the Theory of limits, if p.derivativeFilterLoss -> 0, then
263 // lim(ad) = 0; lim(bd) = p.pFactor * Td / dTime = p.dFactor / dTime
264 // i.e. dTerm becomes equal to Pid's
265 ad = 0.0f;
266 bd = parameters->dFactor / dTime;
267 }
268
269 // (error - previousError) = (target-input) - (target-prevousInput) = -(input - prevousInput)
270 dTerm = dTerm * ad + (error - previousError) * bd;
271
272 updateITerm(parameters->iFactor * dTime * error);
273
274 // calculate output and apply the limits
275 float l_output = pTerm + iTerm + dTerm + getOffset();
276 float limitedOutput = limitOutput(l_output);
277
278 // apply the integrator anti-windup on top of the "normal" iTerm change above
279 // If p.antiwindupFreq = 0, then iTerm is equal to PidParallelController's
280 iTerm += dTime * antiwindupFreq * (limitedOutput - l_output);
281
282 // update the state
283 previousError = error;
284
285 return limitedOutput;
286}
virtual void updateITerm(float value)
Definition efi_pid.cpp:178
float getOffset() const
Definition efi_pid.cpp:130
float antiwindupFreq
Definition efi_pid.h:123
float derivativeFilterLoss
Definition efi_pid.h:124
float limitOutput(float v) const
Definition efi_pid.cpp:288

Referenced by LuaIndustrialPid::get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ limitOutput()

float PidIndustrial::limitOutput ( float  v) const
private

Definition at line 288 of file efi_pid.cpp.

288 {
289 if (v < getMinValue())
290 v = getMinValue();
291 if (v > parameters->maxValue)
292 v = parameters->maxValue;
293 return v;
294}

Referenced by getOutput().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ antiwindupFreq

float PidIndustrial::antiwindupFreq = 0.0f

◆ derivativeFilterLoss

float PidIndustrial::derivativeFilterLoss = 0.0f

The documentation for this class was generated from the following files: