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

#include <limp_manager.h>

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

Public Types

using interface_t = LimpManager
 

Public Member Functions

void updateState (float rpm, efitick_t nowNt)
 
void onFastCallback () override
 
void onIgnitionStateChanged (bool ignitionOn) override
 
bool allowElectronicThrottle () const
 
LimpState allowInjection () const
 
LimpState allowIgnition () const
 
float getTimeSinceAnyCut () const
 
bool allowTriggerInput () const
 
void updateRevLimit (float rpm)
 
angle_t getLimitingTimingRetard () const
 
float getLimitingFuelCorrection () const
 
void reportEtbProblem ()
 
void fatalError ()
 
- Public Member Functions inherited from EngineModule
virtual void initNoConfiguration ()
 
virtual void setDefaultConfiguration ()
 
virtual void onConfigurationChange (engine_configuration_s const *)
 
virtual void onSlowCallback ()
 
virtual void onEngineStop ()
 
virtual bool needsDelayedShutoff ()
 
virtual void onEnginePhase (float, efitick_t, angle_t, angle_t)
 

Data Fields

ShutdownController shutdownController
 
Timer externalGdiCanBusComms
 

Private Member Functions

void setFaultRevLimit (int limit, ClearReason rpmLimitReason)
 

Private Attributes

Hysteresis m_revLimitHysteresis
 
MaxLimitWithHysteresis m_boostCutHysteresis
 
Hysteresis m_injectorDutyCutHysteresis
 
int32_t m_faultRevLimit = INT32_MAX
 
Clearable m_allowEtb
 
Clearable m_allowInjection
 
Clearable m_allowIgnition
 
Clearable m_allowTriggerInput
 
Clearable m_transientAllowInjection = true
 
Clearable m_transientAllowIgnition = true
 
bool m_hadOilPressureAfterStart = false
 
bool m_ignitionOn = false
 
angle_t m_timingRetard = 0
 
float m_fuelCorrection = 1.0f
 
float m_revLimit
 
ClearReason m_rpmLimitReason = ClearReason::None
 
float resumeRpm
 
Timer m_lastCutTime
 
Timer m_injectorDutySustainedTimer
 
Timer m_lowOilPressureTimer
 
Timer m_highOilPressureTimer
 

Detailed Description

Definition at line 90 of file limp_manager.h.

Member Typedef Documentation

◆ interface_t

Definition at line 94 of file limp_manager.h.

Member Function Documentation

◆ allowElectronicThrottle()

bool LimpManager::allowElectronicThrottle ( ) const

Definition at line 295 of file limp_manager.cpp.

295 {
297}
bool etbIgnoreJamProtection
Definition engine.h:297
Clearable m_allowEtb
static EngineAccessor engine
Definition engine.h:413

Referenced by EtbController::setOutput().

Here is the caller graph for this function:

◆ allowIgnition()

LimpState LimpManager::allowIgnition ( ) const

Definition at line 314 of file limp_manager.cpp.

314 {
315 if (!m_allowIgnition) {
316 return {false, m_allowIgnition.clearReason};
317 }
320 }
321 return {true, ClearReason::None};
322}
ClearReason clearReason
Clearable m_allowIgnition
Clearable m_transientAllowIgnition

Referenced by onTriggerEventSparkLogic().

Here is the caller graph for this function:

◆ allowInjection()

LimpState LimpManager::allowInjection ( ) const

Definition at line 304 of file limp_manager.cpp.

304 {
305 if (!m_allowInjection) {
306 return {false, m_allowInjection.clearReason};
307 }
310 }
311 return {true, ClearReason::None};
312}
Clearable m_transientAllowInjection
Clearable m_allowInjection

Referenced by handleFuel().

Here is the caller graph for this function:

◆ allowTriggerInput()

bool LimpManager::allowTriggerInput ( ) const

Definition at line 300 of file limp_manager.cpp.

300 {
301 return m_allowTriggerInput;
302}
Clearable m_allowTriggerInput

Referenced by handleShaftSignal().

Here is the caller graph for this function:

◆ fatalError()

void LimpManager::fatalError ( )

Definition at line 276 of file limp_manager.cpp.

276 {
281
283}
void clear(ClearReason p_clearReason)
void setFaultRevLimit(int limit, ClearReason rpmLimitReason)

Referenced by firmwareErrorV().

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

◆ getLimitingFuelCorrection()

float LimpManager::getLimitingFuelCorrection ( ) const

Definition at line 330 of file limp_manager.cpp.

330 {
332 return 1.0f; // no correction
333 return m_fuelCorrection;
334}
float m_fuelCorrection
static constexpr engine_configuration_s * engineConfiguration

Referenced by getRunningFuel().

Here is the caller graph for this function:

◆ getLimitingTimingRetard()

angle_t LimpManager::getLimitingTimingRetard ( ) const

Definition at line 324 of file limp_manager.cpp.

Referenced by EngineState::periodicFastCallback().

Here is the caller graph for this function:

◆ getTimeSinceAnyCut()

float LimpManager::getTimeSinceAnyCut ( ) const

Definition at line 336 of file limp_manager.cpp.

336 {
337 return m_lastCutTime.getElapsedSeconds();
338}
Timer m_lastCutTime

◆ onFastCallback()

void LimpManager::onFastCallback ( )
overridevirtual

Reimplemented from EngineModule.

Definition at line 40 of file limp_manager.cpp.

40 {
42}
void updateState(float rpm, efitick_t nowNt)
static float getOrZero(SensorType type)
Definition sensor.h:83
efitick_t getTimeNowNt()
Definition efitime.cpp:19

Referenced by TriggerCentral::decodeMapCam().

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

◆ onIgnitionStateChanged()

void LimpManager::onIgnitionStateChanged ( bool  ignitionOn)
overridevirtual

Reimplemented from EngineModule.

Definition at line 267 of file limp_manager.cpp.

267 {
268 m_ignitionOn = ignitionOn;
269}

◆ reportEtbProblem()

void LimpManager::reportEtbProblem ( )

Definition at line 271 of file limp_manager.cpp.

Referenced by EtbController::checkJam().

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

◆ setFaultRevLimit()

void LimpManager::setFaultRevLimit ( int  limit,
ClearReason  rpmLimitReason 
)
private

Definition at line 285 of file limp_manager.cpp.

285 {
286 // Only allow decreasing the limit
287 // aka uses the limit of the worst fault to yet occur
288 if (limit < m_faultRevLimit) {
289 m_faultRevLimit = limit;
290 m_rpmLimitReason = rpmLimitReason;
291 }
292}
int32_t m_faultRevLimit
ClearReason m_rpmLimitReason

Referenced by fatalError(), and reportEtbProblem().

Here is the caller graph for this function:

◆ updateRevLimit()

void LimpManager::updateRevLimit ( float  rpm)

Definition at line 44 of file limp_manager.cpp.

44 {
45 // User-configured hard RPM limit, either constant or CLT-lookup
48 : (float)engineConfiguration->rpmHardLimit;
49
50 // Require configurable rpm drop before resuming
52
54
56 m_fuelCorrection = 1.0f + fuelAdded / 100;
57}
float interpolateClamped(float x1, float y1, float x2, float y2, float x)
static constexpr persistent_config_s * config
float percent_t
scaled_channel< int16_t, 1, 1 > cltRevLimitRpmBins[CLT_LIMITER_CURVE_SIZE]

Referenced by EngineState::periodicFastCallback(), and updateState().

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

◆ updateState()

void LimpManager::updateState ( float  rpm,
efitick_t  nowNt 
)

todo: we need explicit clarification on why do we cut fuel but do not cut spark here!

Definition at line 59 of file limp_manager.cpp.

59 {
62
63#if EFI_SHAFT_POSITION_INPUT && !EFI_UNIT_TEST
64 if (!m_ignitionOn
65 && !engine->triggerCentral.directSelfStimulation // useful to try things on real ECU even without ignition voltage
66 ) {
69 }
70#endif
71
73 if (externalGdiCanBusComms.getElapsedSeconds() > 1) {
75 }
76 }
77
79 allowSpark.clear(ClearReason::Lua);
80 }
81
83 allowFuel.clear(ClearReason::Lua);
84 }
85
86 updateRevLimit(rpm);
90 }
91
93 allowSpark.clear(ClearReason::HardLimit);
94 }
95 }
96
97#if EFI_SHAFT_POSITION_INPUT
98 if (engine->lambdaMonitor.isCut()) {
100 }
101
104 // Any engine that requires cam-assistance for a full crank sync (symmetrical crank) can't schedule until we have cam sync
105 // examples:
106 // NB2, Nissan VQ/MR: symmetrical crank wheel and we need to make sure no spark happens out of sync
107 // VTwin Harley: uneven firing order, so we need "cam" MAP sync to make sure no spark happens out of sync
110 }
111
112 // Force fuel limiting on the fault rev limit
113 if (rpm > m_faultRevLimit) {
114 allowFuel.clear(m_rpmLimitReason);
115 }
116
117 // Limit fuel only on boost pressure (limiting spark bends valves)
119 if (mapCut != 0) {
120 // require drop of 'boostCutPressureHyst' kPa to resume fuel
122 allowFuel.clear(ClearReason::BoostCut);
123 }
124 }
125
127 bool hasOilpSensor = Sensor::hasSensor(SensorType::OilPressure);
129 uint16_t minOilPressure = engineConfiguration->minOilPressureAfterStart;
130
131 // Only check if the setting is enabled and you have an oil pressure sensor
132 if (minOilPressure > 0 && hasOilpSensor) {
133 // Has it been long enough we should have pressure?
134 bool isTimedOut = engine->rpmCalculator.getSecondsSinceEngineStart(nowNt) > 5.0f;
135
136 // Only check before timed out
137 if (!isTimedOut) {
138 if (oilp) {
139 // We had oil pressure! Set the flag.
140 if (oilp.Value > minOilPressure) {
142 }
143 }
144 }
145
146 // If time is up, the sensor works, and no pressure, kill the engine.
147 if (isTimedOut && !m_hadOilPressureAfterStart) {
149 }
150 }
151
153 float minPressure = interpolate2d(rpm, config->minimumOilPressureBins, config->minimumOilPressureValues);
154 bool isPressureSufficient = oilp.Value > minPressure;
155
156 if (isPressureSufficient) {
157 m_lowOilPressureTimer.reset(nowNt);
158 }
159
162 }
163 }
164
165 // check the maximum oil pressure
166 float maxOilPressure = interpolate2d(rpm, config->maximumOilPressureBins, config->maximumOilPressureValues);
167 if (maxOilPressure > 0 && hasOilpSensor) {
168 if (oilp.Value < maxOilPressure) {
169 m_highOilPressureTimer.reset(nowNt);
170 }
173 }
174 }
175
176 } else {
177 // reset state in case of stalled engine
179 m_lowOilPressureTimer.reset(nowNt);
180 }
181
182 // If we're in engine stop mode, inhibit fuel
183 if (shutdownController.isEngineStop(nowNt)) {
184 /**
185 * todo: we need explicit clarification on why do we cut fuel but do not cut spark here!
186 */
188 }
189
190 {
191 // todo: we need to add some tests of this?
192 // If duty cycle is high, impose a fuel cut rev limiter.
193 // This is safer than attempting to limp along with injectors or a pump that are out of flow.
194 // Two conditions will trigger a cut:
195 // - An instantaneous excursion above maxInjectorDutyInstant
196 // - A sustained excursion above maxInjectorDutySustained for a duration of >= maxInjectorDutySustainedTimeout
197 // Only reset once below 20% duty to force the driver to lift off the pedal
198
199 auto injDutyCycle = getInjectorDutyCycle(rpm);
200 bool isOverInstantDutyCycle = injDutyCycle > engineConfiguration->maxInjectorDutyInstant;
201 bool isOverSustainedDutyCycle = injDutyCycle > engineConfiguration->maxInjectorDutySustained;
202 bool isUnderLowDuty = injDutyCycle < 20;
203
204 if (!isOverSustainedDutyCycle) {
205 // Duty cycle is OK, reset timer.
206 m_injectorDutySustainedTimer.reset(nowNt);
207 }
208
209 // True if isOverSustainedDutyCycle has been true for longer than the timeout
210 bool sustainedLimitTimedOut = m_injectorDutySustainedTimer.hasElapsedSec(engineConfiguration->maxInjectorDutySustainedTimeout);
211
212 bool someLimitTripped = isOverInstantDutyCycle || sustainedLimitTimedOut;
213
214 if (m_injectorDutyCutHysteresis.test(someLimitTripped, isUnderLowDuty)) {
216 warning(ObdCode::CUSTOM_TOO_LONG_FUEL_INJECTION, "Injector duty cycle cut %.1f", injDutyCycle);
217 }
218 }
219
220 {
221 // GDI Fuel cut
222 bool isGDIDriverInjectorTimeTooLong = engine->engineState.injectionDuration > engineConfiguration->mc33_t_hold_tot;
223
224 if (isGdiEngine() && isGDIDriverInjectorTimeTooLong) {
225 allowFuel.clear(ClearReason::GdiLimits);
226 warning(ObdCode::CUSTOM_TOO_LONG_FUEL_INJECTION, "Injection duration excess PT2001 limits time: %.4f", engine->engineState.injectionDuration);
227 }
228 }
229
230 // If the pedal is pushed while not running, cut fuel to clear a flood condition.
235 }
236#endif // EFI_SHAFT_POSITION_INPUT
237
238 if (!engine->isMainRelayEnabled()) {
239/*
240todo AndreiKA this change breaks 22 unit tests?
241 allowFuel.clear();
242 allowSpark.clear();
243*/
244 }
245
246#if EFI_LAUNCH_CONTROL
247 // Fuel cut if launch control engaged
249 allowFuel.clear(ClearReason::LaunchCut);
250 }
251
252 // Spark cut if launch control engaged
254 allowSpark.clear(ClearReason::LaunchCut);
255 }
256#endif // EFI_LAUNCH_CONTROL
257
258 m_transientAllowInjection = allowFuel;
259 m_transientAllowIgnition = allowSpark;
260
262 // Tracks the last time any cut happened
263 m_lastCutTime.reset(nowNt);
264 }
265}
TriggerCentral triggerCentral
Definition engine.h:318
bool isMainRelayEnabled() const
Definition engine.cpp:539
LaunchControlBase launchController
Definition engine.h:220
EngineState engineState
Definition engine.h:344
RpmCalculator rpmCalculator
Definition engine.h:306
LambdaMonitor lambdaMonitor
Definition engine.h:236
floatms_t injectionDuration
bool test(float value, float rising, float falling)
Definition hysteresis.h:31
bool isLaunchFuelRpmRetardCondition() const
bool isLaunchSparkRpmRetardCondition() const
Hysteresis m_revLimitHysteresis
Timer m_lowOilPressureTimer
Timer m_highOilPressureTimer
bool m_hadOilPressureAfterStart
MaxLimitWithHysteresis m_boostCutHysteresis
Timer m_injectorDutySustainedTimer
void updateRevLimit(float rpm)
Hysteresis m_injectorDutyCutHysteresis
ShutdownController shutdownController
Timer externalGdiCanBusComms
bool checkIfLimitIsExceeded(const float value, const float maxLimit, const float hysteresis)
bool hasSynchronizedPhase() const
float getSecondsSinceEngineStart(efitick_t nowNt) const
bool isRunning() const
virtual bool hasSensor() const
Definition sensor.h:141
virtual SensorResult get() const =0
bool isEngineStop(efitick_t nowNt) const
PrimaryTriggerDecoder triggerState
bool warning(ObdCode code, const char *fmt,...)
percent_t getInjectorDutyCycle(float rpm)
bool isGdiEngine()
static bool noFiringUntilVvtSync()
@ CUSTOM_TOO_LONG_FUEL_INJECTION
@ DriverThrottleIntent
scaled_channel< uint8_t, 1, 100 > maximumOilPressureBins[4]
scaled_channel< uint8_t, 1, 10 > minimumOilPressureValues[8]
scaled_channel< uint8_t, 1, 100 > minimumOilPressureBins[8]
scaled_channel< uint8_t, 1, 10 > maximumOilPressureValues[4]

Referenced by onFastCallback().

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

Field Documentation

◆ externalGdiCanBusComms

Timer LimpManager::externalGdiCanBusComms

Definition at line 119 of file limp_manager.h.

Referenced by processCanRxMessage(), and updateState().

◆ m_allowEtb

Clearable LimpManager::m_allowEtb
private

Definition at line 131 of file limp_manager.h.

Referenced by allowElectronicThrottle(), fatalError(), and reportEtbProblem().

◆ m_allowIgnition

Clearable LimpManager::m_allowIgnition
private

Definition at line 133 of file limp_manager.h.

Referenced by allowIgnition(), and fatalError().

◆ m_allowInjection

Clearable LimpManager::m_allowInjection
private

Definition at line 132 of file limp_manager.h.

Referenced by allowInjection(), and fatalError().

◆ m_allowTriggerInput

Clearable LimpManager::m_allowTriggerInput
private

Definition at line 134 of file limp_manager.h.

Referenced by allowTriggerInput(), and fatalError().

◆ m_boostCutHysteresis

MaxLimitWithHysteresis LimpManager::m_boostCutHysteresis
private

Definition at line 125 of file limp_manager.h.

Referenced by updateState().

◆ m_faultRevLimit

int32_t LimpManager::m_faultRevLimit = INT32_MAX
private

Definition at line 129 of file limp_manager.h.

Referenced by setFaultRevLimit(), and updateState().

◆ m_fuelCorrection

float LimpManager::m_fuelCorrection = 1.0f
private

Definition at line 145 of file limp_manager.h.

Referenced by getLimitingFuelCorrection(), and updateRevLimit().

◆ m_hadOilPressureAfterStart

bool LimpManager::m_hadOilPressureAfterStart = false
private

Definition at line 139 of file limp_manager.h.

Referenced by updateState().

◆ m_highOilPressureTimer

Timer LimpManager::m_highOilPressureTimer
private

Definition at line 160 of file limp_manager.h.

Referenced by updateState().

◆ m_ignitionOn

bool LimpManager::m_ignitionOn = false
private

Definition at line 142 of file limp_manager.h.

Referenced by onIgnitionStateChanged(), and updateState().

◆ m_injectorDutyCutHysteresis

Hysteresis LimpManager::m_injectorDutyCutHysteresis
private

Definition at line 126 of file limp_manager.h.

Referenced by updateState().

◆ m_injectorDutySustainedTimer

Timer LimpManager::m_injectorDutySustainedTimer
private

Definition at line 156 of file limp_manager.h.

Referenced by updateState().

◆ m_lastCutTime

Timer LimpManager::m_lastCutTime
private

Definition at line 153 of file limp_manager.h.

Referenced by getTimeSinceAnyCut(), and updateState().

◆ m_lowOilPressureTimer

Timer LimpManager::m_lowOilPressureTimer
private

Definition at line 159 of file limp_manager.h.

Referenced by updateState().

◆ m_revLimit

float LimpManager::m_revLimit
private

Definition at line 148 of file limp_manager.h.

Referenced by updateRevLimit(), and updateState().

◆ m_revLimitHysteresis

Hysteresis LimpManager::m_revLimitHysteresis
private

Definition at line 124 of file limp_manager.h.

Referenced by updateState().

◆ m_rpmLimitReason

ClearReason LimpManager::m_rpmLimitReason = ClearReason::None
private

Definition at line 149 of file limp_manager.h.

Referenced by setFaultRevLimit(), and updateState().

◆ m_timingRetard

angle_t LimpManager::m_timingRetard = 0
private

Definition at line 144 of file limp_manager.h.

Referenced by getLimitingTimingRetard(), and updateRevLimit().

◆ m_transientAllowIgnition

Clearable LimpManager::m_transientAllowIgnition = true
private

Definition at line 137 of file limp_manager.h.

Referenced by allowIgnition(), and updateState().

◆ m_transientAllowInjection

Clearable LimpManager::m_transientAllowInjection = true
private

Definition at line 136 of file limp_manager.h.

Referenced by allowInjection(), and updateState().

◆ resumeRpm

float LimpManager::resumeRpm
private

Definition at line 150 of file limp_manager.h.

Referenced by updateRevLimit(), and updateState().

◆ shutdownController

ShutdownController LimpManager::shutdownController

Definition at line 92 of file limp_manager.h.

Referenced by configureRusefiLuaHooks(), doScheduleStopEngine(), and updateState().


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