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 244 of file efi_pid.cpp.

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

◆ PidIndustrial() [2/2]

PidIndustrial::PidIndustrial ( pid_s pid)
explicit

Definition at line 247 of file efi_pid.cpp.

247 : Pid(p_parameters) {
248}

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:250
@ 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 250 of file efi_pid.cpp.

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

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 289 of file efi_pid.cpp.

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

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: