rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
lambda_monitor.cpp
Go to the documentation of this file.
1#include "pch.h"
2
3#include "lambda_monitor.h"
4
5#if EFI_SHAFT_POSITION_INPUT
6
7float LambdaMonitor::getMaxAllowedLambda(float rpm, float load) const {
8 return
10 + interpolate3d(
14 );
15}
16
20
22 return lambdaMonitorCut;
23}
24
25void LambdaMonitorBase::update(float rpm, float load) {
26 bool isGood = isCurrentlyGood(rpm, load);
27 lambdaCurrentlyGood = isGood;
28 if (isGood) {
30 }
31
32 lambdaTimeSinceGood = m_timeSinceGoodLambda.getElapsedSeconds();
33
34 if (m_timeSinceGoodLambda.hasElapsedSec(getTimeout())) {
35 // Things have been bad long enough, cut!
36 lambdaMonitorCut = true;
37 }
38
39 if (lambdaMonitorCut) {
40 // If things are back to normal, cancel the cut and force a reset
41 if (restoreConditionsMet(rpm, load)) {
42 lambdaMonitorCut = false;
44 }
45 }
46}
47
48bool LambdaMonitorBase::isCurrentlyGood(float rpm, float load) const {
49 // Lambda is always good if disabled
51 return true;
52 }
53
54 // Below min RPM, don't check
55 if (rpm < engineConfiguration->lambdaProtectionMinRpm) {
56 return true;
57 }
58
59 // Below min load, don't check
60 if (load < engineConfiguration->lambdaProtectionMinLoad) {
61 return true;
62 }
63
64 // Below min TPS, don't check
66 return true;
67 }
68
69 // Pause checking if DFCO was active recently
70 auto timeSinceDfco = engine->module<DfcoController>()->getTimeSinceCut();
71 if (timeSinceDfco < engineConfiguration->noFuelTrimAfterDfcoTime) {
72 return true;
73 }
74
75 // Pause checking if some other cut was active recently
76 auto timeSinceFuelCut = engine->module<LimpManager>()->getTimeSinceAnyCut();
77 // TODO: should this duration be configurable?
78 if (timeSinceFuelCut < 2) {
79 return true;
80 }
81
82 // TODO: multiple banks
83 if (auto lambda = Sensor::get(SensorType::Lambda1)) {
84 if (lambda.Value < getMaxAllowedLambda(rpm, load)) {
85 // Lambda is OK, we're good.
86 return true;
87 }
88 } else {
89 // Broken lambda sensor doesn't imply bad lambda
90
91 // TODO: can/should we be smarter here?
92 return true;
93 }
94
95 // All checks failed, lambda is currently bad.
96 return false;
97}
98
99bool LambdaMonitorBase::restoreConditionsMet(float rpm, float load) const {
101 return false;
102 }
103
105 return false;
106 }
107
109 return false;
110 }
111
112 return true;
113}
114#endif // EFI_SHAFT_POSITION_INPUT
FuelComputer fuelComputer
Definition engine.h:139
constexpr auto & module()
Definition engine.h:200
float getTimeout() const override
float getMaxAllowedLambda(float rpm, float load) const override
virtual SensorResult get() const =0
static float getOrZero(SensorType type)
Definition sensor.h:83
static EngineAccessor engine
Definition engine.h:413
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
virtual bool isCurrentlyGood(float rpm, float load) const
virtual float getTimeout() const =0
virtual float getMaxAllowedLambda(float rpm, float load) const =0
void update(float rpm, float load)
virtual bool restoreConditionsMet(float rpm, float load) const
scaled_channel< uint16_t, 10000, 1 > targetLambda
scaled_channel< uint16_t, 100, 1 > lambdaTimeSinceGood
scaled_channel< uint8_t, 100, 1 > lambdaMaxDeviationTable[LAM_SIZE][LAM_SIZE]