rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes
PidCic Class Reference

#include <efi_pid.h>

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

Public Member Functions

 PidCic ()
 
 PidCic (pid_s *pid)
 
void reset (void) override
 
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)
 
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 ()
 

Private Member Functions

void updateITerm (float value) override
 

Private Attributes

float iTermBuf [PID_AVG_BUF_SIZE]
 
float iTermInvNum
 
int totalItermCnt
 

Additional Inherited Members

- 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
 
- Protected Attributes inherited from Pid
pid_sparameters = nullptr
 

Detailed Description

A PID implementation with a modified cascaded integrator-comb (CIC) filtering. Used for incremental auto-IAC control. See autoIdle() in idle_thread.cpp See pid_cic.md.

https://rusefi.com/forum/viewtopic.php?f=9&t=1315

Definition at line 83 of file efi_pid.h.

Constructor & Destructor Documentation

◆ PidCic() [1/2]

PidCic::PidCic ( )

Definition at line 200 of file efi_pid.cpp.

200 {
201 // call our derived reset()
203}
void reset(void) override
Definition efi_pid.cpp:210
Here is the call graph for this function:

◆ PidCic() [2/2]

PidCic::PidCic ( pid_s pid)
explicit

Definition at line 205 of file efi_pid.cpp.

205 : Pid(p_parameters) {
206 // call our derived reset()
208}
Pid()
Definition efi_pid.cpp:16
Here is the call graph for this function:

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}
float getOutput(float target, float input, float dTime) override
Definition efi_pid.cpp:219
pid_s * parameters
Definition efi_pid.h:71
@ 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 PidCic::getOutput ( float  p_target,
float  p_input,
float  dTime 
)
overridevirtual
Parameters
dTimeseconds probably? :)

Reimplemented from Pid.

Definition at line 219 of file efi_pid.cpp.

219 {
220 return getUnclampedOutput(p_target, p_input, dTime);
221}
Here is the call graph for this function:

◆ reset()

void PidCic::reset ( void  )
overridevirtual

Reimplemented from Pid.

Definition at line 210 of file efi_pid.cpp.

210 {
211 Pid::reset();
212
213 totalItermCnt = 0;
214 for (int i = 0; i < PID_AVG_BUF_SIZE; i++)
215 iTermBuf[i] = 0;
216 iTermInvNum = 1.0f / (float)PID_AVG_BUF_SIZE;
217}
float iTermInvNum
Definition efi_pid.h:97
int totalItermCnt
Definition efi_pid.h:99
float iTermBuf[PID_AVG_BUF_SIZE]
Definition efi_pid.h:95
virtual void reset()
Definition efi_pid.cpp:103

Referenced by PidCic(), and PidCic().

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

◆ updateITerm()

void PidCic::updateITerm ( float  value)
overrideprivatevirtual

Reimplemented from Pid.

Definition at line 223 of file efi_pid.cpp.

223 {
224 // use a variation of cascaded integrator-comb (CIC) filtering to get non-overflow iTerm
226 int localBufPos = (totalItermCnt >> PID_AVG_BUF_SIZE_SHIFT) % PID_AVG_BUF_SIZE;
227 int localPrevBufPos = ((totalItermCnt - 1) >> PID_AVG_BUF_SIZE_SHIFT) % PID_AVG_BUF_SIZE;
228
229 // reset old buffer cell
230 if (localPrevBufPos != localBufPos)
231 iTermBuf[localBufPos] = 0;
232 // integrator stage
233 iTermBuf[localBufPos] += value;
234
235 // return moving average of all sums, to smoothen the result
236 float iTermSum = 0;
237 for (int i = 0; i < PID_AVG_BUF_SIZE; i++) {
238 iTermSum += iTermBuf[i];
239 }
240 iTerm = iTermSum * iTermInvNum;
241}

Field Documentation

◆ iTermBuf

float PidCic::iTermBuf[PID_AVG_BUF_SIZE]
private

Definition at line 95 of file efi_pid.h.

Referenced by reset(), and updateITerm().

◆ iTermInvNum

float PidCic::iTermInvNum
private

Definition at line 97 of file efi_pid.h.

Referenced by reset(), and updateITerm().

◆ totalItermCnt

int PidCic::totalItermCnt
private

Definition at line 99 of file efi_pid.h.

Referenced by reset(), and updateITerm().


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