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

#include <closed_loop_fuel.h>

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

Public Member Functions

void init (stft_s *stftCfg)
 
void onSlowCallback () override
 
bool needsDelayedShutoff () override
 
ClosedLoopFuelResult getCorrection (float rpm, float fuelLoad)
 
- Public Member Functions inherited from EngineModule
virtual void initNoConfiguration ()
 
virtual void setDefaultConfiguration ()
 
virtual void onConfigurationChange (engine_configuration_s const *)
 
virtual void onFastCallback ()
 
virtual void onEngineStop ()
 
virtual void onIgnitionStateChanged (bool)
 
virtual void onEnginePhase (float, efitick_t, angle_t, angle_t)
 

Private Member Functions

SensorType getSensorForBankIndex (size_t index)
 
size_t computeStftBin (float rpm, float load, stft_s &cfg)
 
stft_state_e getCorrectionState ()
 
stft_state_e getLearningState (SensorType sensor)
 

Private Attributes

FuelingBank banks [FT_BANK_COUNT]
 
Deadband< 25 > idleDeadband
 
Deadband< 2 > overrunDeadband
 
Deadband< 2 > loadDeadband
 

Additional Inherited Members

- Data Fields inherited from short_term_fuel_trim_state_s
uint8_t stftCorrectionBinIdx = (uint8_t)0
 
uint8_t stftLearningBinIdx = (uint8_t)0
 
stft_state_e stftCorrectionState
 
stft_state_e stftLearningState [FT_BANK_COUNT] = {}
 
uint8_t alignmentFill_at_5 [3] = {}
 
float stftInputError [FT_BANK_COUNT] = {}
 

Detailed Description

Definition at line 26 of file closed_loop_fuel.h.

Member Function Documentation

◆ computeStftBin()

size_t ShortTermFuelTrim::computeStftBin ( float  rpm,
float  load,
stft_s cfg 
)
private

Definition at line 16 of file closed_loop_fuel.cpp.

16 {
17 // Low RPM -> idle
18 if (idleDeadband.lt(rpm, cfg.maxIdleRegionRpm))
19 {
20 return 0;
21 }
22
23 // Low load -> overrun
24 if (overrunDeadband.lt(load, cfg.maxOverrunLoad))
25 {
26 return 1;
27 }
28
29 // High load -> power
30 if (loadDeadband.gt(load, cfg.minPowerLoad))
31 {
32 return 2;
33 }
34
35 // Default -> normal "in the middle" cell
36 return 3;
37}
bool gt(float lhs, float rhs)
Definition deadband.h:15
bool lt(float lhs, float rhs)
Definition deadband.h:28
Deadband< 2 > loadDeadband
Deadband< 2 > overrunDeadband
Deadband< 25 > idleDeadband
scaled_channel< uint8_t, 1, 50 > maxIdleRegionRpm

Referenced by getCorrection().

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

◆ getCorrection()

ClosedLoopFuelResult ShortTermFuelTrim::getCorrection ( float  rpm,
float  fuelLoad 
)

Definition at line 118 of file closed_loop_fuel.cpp.

118 {
120 if (stftCorrectionState != stftEnabled) {
121 // Learning is also prohibited
122 for (size_t bank = 0; bank < FT_BANK_COUNT; bank++) {
124 }
125 return {};
126 }
127
129
131
132 for (size_t bank = 0; bank < FT_BANK_COUNT; bank++) {
133 auto& cell = banks[bank].cells[stftCorrectionBinIdx];
134
136
138 if (stftLearningState[bank] == stftEnabled) {
139 stftInputError[bank] = cell.getLambdaError();
142 }
143
144 result.banks[bank] = cell.getAdjustment();
145 }
146
147 return result;
148}
FuelingBank banks[FT_BANK_COUNT]
stft_state_e getLearningState(SensorType sensor)
size_t computeStftBin(float rpm, float load, stft_s &cfg)
SensorType getSensorForBankIndex(size_t index)
stft_state_e getCorrectionState()
static constexpr engine_configuration_s * engineConfiguration
static Lps25Sensor sensor(device)
SensorType
Definition sensor_type.h:18
float banks[FT_BANK_COUNT]
ClosedLoopFuelCellImpl cells[STFT_CELL_COUNT]
scaled_channel< uint8_t, 10, 1 > deadband
Here is the call graph for this function:

◆ getCorrectionState()

stft_state_e ShortTermFuelTrim::getCorrectionState ( )
private

Definition at line 39 of file closed_loop_fuel.cpp.

39 {
40 const auto& cfg = engineConfiguration->stft;
41
42 // User disable bit
44 return stftDisabledSettings;
45 }
46
47 // Don't correct if tuning seems to be happening
48 if (checkIfTuningVeNow()) {
49 return stftDisabledTuning;
50 }
51
52 // Don't correct if not running
54 return stftDisabledRPM;
55 }
56
57 // Startup delay - allow O2 sensor to warm up, etc
58 if (cfg.startupDelay > engine->fuelComputer.running.timeSinceCrankingInSecs) {
59 return stftDisabledCrankingDelay;
60 }
61
62 // Check that the engine is hot enough (and clt not failed)
64 if (!clt.Valid || clt.Value < cfg.minClt) {
65 return stftDisabledClt;
66 }
67
68 // If all was well, then we're enabled!
69 return stftEnabled;
70}
FuelComputer fuelComputer
Definition engine.h:139
RpmCalculator rpmCalculator
Definition engine.h:306
bool isRunning() const
virtual SensorResult get() const =0
bool checkIfTuningVeNow()
static EngineAccessor engine
Definition engine.h:413
static CCM_OPTIONAL FunctionalSensor clt(SensorType::Clt, MS2NT(10))

Referenced by getCorrection().

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

◆ getLearningState()

stft_state_e ShortTermFuelTrim::getLearningState ( SensorType  sensor)
private

Definition at line 72 of file closed_loop_fuel.cpp.

72 {
73 const auto& cfg = engineConfiguration->stft;
74
75 // TODO: add check for stftLearningDisabledSettings
76
77 // Pause (but don't reset) correction if the AFR is off scale.
78 // It's probably a transient and poorly tuned transient correction
79 // TODO: use getStoichiometricRatio() instead of STOICH_RATIO
80 auto afr = Sensor::getOrZero(sensor) * STOICH_RATIO;
81 if (!afr || afr < cfg.minAfr || afr > cfg.maxAfr) {
82 return stftDisabledAfrOurOfRange;
83 }
84
85 // Pause correction if DFCO was active recently
86 auto timeSinceDfco = engine->module<DfcoController>()->getTimeSinceCut();
87 if (timeSinceDfco < engineConfiguration->noFuelTrimAfterDfcoTime) {
88 return stftDisabledDFCO;
89 }
90
91 // Pause correction if Accel enrichment was active recently
92 auto timeSinceAccel = engine->module<TpsAccelEnrichment>()->getTimeSinceAcell();
93 if (timeSinceAccel < engineConfiguration->noFuelTrimAfterAccelTime) {
94 return stftDisabledTpsAccel;
95 }
96
97 // Pause if some other cut was active recently
98 auto timeSinceFuelCut = engine->module<LimpManager>()->getTimeSinceAnyCut();
99 // TODO: should duration this be configurable?
100 if (timeSinceFuelCut < 2) {
101 return stftDisabledFuelCut;
102 }
103
104 return stftEnabled;
105}
constexpr auto & module()
Definition engine.h:200
static float getOrZero(SensorType type)
Definition sensor.h:83

Referenced by getCorrection().

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

◆ getSensorForBankIndex()

SensorType ShortTermFuelTrim::getSensorForBankIndex ( size_t  index)
private

Definition at line 8 of file closed_loop_fuel.cpp.

8 {
9 switch (index) {
10 case 0: return SensorType::Lambda1;
11 case 1: return SensorType::Lambda2;
12 default: return SensorType::Invalid;
13 }
14}

Referenced by getCorrection(), and init().

Here is the caller graph for this function:

◆ init()

void ShortTermFuelTrim::init ( stft_s stftCfg)

Definition at line 107 of file closed_loop_fuel.cpp.

107 {
108 for (size_t bank = 0; bank < FT_BANK_COUNT; bank++) {
109 for (size_t bin = 0; bin < STFT_CELL_COUNT; bin++) {
110 auto& cell = banks[bank].cells[bin];
112
113 cell.configure(&stftCfg->cellCfgs[bin], sensor);
114 }
115 }
116}
stft_cell_cfg_s cellCfgs[STFT_CELL_COUNT]
Here is the call graph for this function:

◆ needsDelayedShutoff()

bool ShortTermFuelTrim::needsDelayedShutoff ( )
overridevirtual

Reimplemented from EngineModule.

Definition at line 154 of file closed_loop_fuel.cpp.

154 {
155 return false;
156}

◆ onSlowCallback()

void ShortTermFuelTrim::onSlowCallback ( )
overridevirtual

Reimplemented from EngineModule.

Definition at line 150 of file closed_loop_fuel.cpp.

150 {
151 // Do some magic math here?
152}

Field Documentation

◆ banks

FuelingBank ShortTermFuelTrim::banks[FT_BANK_COUNT]
private

Definition at line 38 of file closed_loop_fuel.h.

Referenced by getCorrection(), and init().

◆ idleDeadband

Deadband<25> ShortTermFuelTrim::idleDeadband
private

Definition at line 40 of file closed_loop_fuel.h.

Referenced by computeStftBin().

◆ loadDeadband

Deadband<2> ShortTermFuelTrim::loadDeadband
private

Definition at line 42 of file closed_loop_fuel.h.

Referenced by computeStftBin().

◆ overrunDeadband

Deadband<2> ShortTermFuelTrim::overrunDeadband
private

Definition at line 41 of file closed_loop_fuel.h.

Referenced by computeStftBin().


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