rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
speed_density_airmass.cpp
Go to the documentation of this file.
1#include "pch.h"
3#include "accel_enrichment.h"
4
5
8
9 auto map = getMap(rpm, postState);
10
11 return getAirmass(rpm, map, postState);
12}
13
14AirmassResult SpeedDensityAirmass::getAirmass(float rpm, float map, bool postState) {
15 /**
16 * most of the values are pre-calculated for performance reasons
17 */
18 float tChargeK = engine->engineState.sd.tChargeK;
19 if (std::isnan(tChargeK)) {
20 warning(ObdCode::CUSTOM_ERR_TCHARGE_NOT_READY2, "tChargeK not ready"); // this would happen before we have CLT reading for example
21 return {};
22 }
23
24 float ve = getVe(rpm, map, postState);
25
26 float airMass = getAirmassImpl(ve, map, tChargeK);
27 if (std::isnan(airMass)) {
28 warning(ObdCode::CUSTOM_ERR_6685, "NaN airMass");
29 return {};
30 }
31#if EFI_PRINTF_FUEL_DETAILS
32 printf("getSpeedDensityAirmass map=%.2f\n", map);
33#endif /*EFI_PRINTF_FUEL_DETAILS */
34
35 return {
36 airMass,
37 map, // AFR/VE table Y axis
38 };
39}
40
41float SpeedDensityAirmass::getAirflow(float rpm, float map, bool postState) {
42 auto airmassResult = getAirmass(rpm, map, postState);
43
44 float massPerCycle = airmassResult.CylinderAirmass * engineConfiguration->cylindersCount;
45
47 // 4 stroke engines only do a half cycle per rev
48 massPerCycle = massPerCycle / 2;
49 }
50
51 // g/s
52 return massPerCycle * rpm / 60;
53}
54
55float SpeedDensityAirmass::getPredictiveMap(float rpm, bool postState, float mapSensor) {
56 float blendDuration = interpolate2d(rpm, config->predictiveMapBlendDurationBins,
58
59 float elapsedTime = m_predictionTimer.getElapsedSeconds();
60
61 if (m_isMapPredictionActive && elapsedTime >= blendDuration) {
62 // prediction phase is over
64 }
65
66 float effectiveMap = 0;
68 float blendFactor = elapsedTime / blendDuration;
69 // Linearly interpolate between the initial predicted and real values
71
72 if (mapSensor >= effectiveMap) {
74 }
75 } else {
77 float predictedMap = logAndGetFallback(rpm, postState);
78
79 if (predictedMap > mapSensor) {
81 engine->module<TpsAccelEnrichment>()->m_timeSinceAccel.reset();
82 m_predictionTimer.reset();
83 m_initialPredictedMap = predictedMap;
84 m_initialRealMap = mapSensor;
85 effectiveMap = predictedMap;
86 }
87 }
88 }
90
92 effectiveMap = mapSensor;
93 }
94
95#if EFI_TUNER_STUDIO
96 if (postState) {
98 }
99#endif // EFI_TUNER_STUDIO
100
101 return effectiveMap;
102}
103
104float SpeedDensityAirmass::logAndGetFallback(float rpm, bool postState) const {
106#if EFI_TUNER_STUDIO
107 if (postState) {
109 }
110#endif // EFI_TUNER_STUDIO
111 return fallbackMap;
112}
113
114float SpeedDensityAirmass::getMap(float rpm, bool postState) {
115 auto mapSensor = Sensor::get(SensorType::Map);
116 if (mapSensor && engineConfiguration->accelEnrichmentMode == AE_MODE_PREDICTIVE_MAP) {
117 return getPredictiveMap(rpm, postState, mapSensor.Value);
118 }
119 return mapSensor.value_or(logAndGetFallback(rpm, postState));
120}
Acceleration enrichment calculator.
float getVe(float rpm, percent_t load, bool postState) const
Definition airmass.cpp:17
EngineState engineState
Definition engine.h:344
TunerStudioOutputChannels outputChannels
Definition engine.h:109
constexpr auto & module()
Definition engine.h:200
virtual SensorResult get() const =0
static float getOrZero(SensorType type)
Definition sensor.h:83
const ValueProvider3D *const m_mapEstimationTable
float logAndGetFallback(float rpm, bool postState) const
float getAirflow(float rpm, float map, bool postState)
float getMap(float rpm, bool postState)
float getPredictiveMap(float rpm, bool postState, float mapSensor)
AirmassResult getAirmass(float rpm, bool postState) override
static mass_t getAirmassImpl(float ve, float manifoldPressure, float temperature)
virtual float getValue(float xColumn, float yRow) const =0
static EngineAccessor engine
Definition engine.h:413
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
bool warning(ObdCode code, const char *fmt,...)
@ CUSTOM_ERR_TCHARGE_NOT_READY2
@ CUSTOM_ERR_6685
@ GetSpeedDensityFuel
fallbackMap("fallbackMap", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 372, 0.1, 0.0, 1000.0, "kPa")
effectiveMap("Effective MAP", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 374, 0.1, 0.0, 1000.0, "kPa")
scaled_channel< uint16_t, 10, 1 > fallbackMap
scaled_channel< uint16_t, 10, 1 > effectiveMap
scaled_channel< uint8_t, 50, 1 > predictiveMapBlendDurationValues[TPS_TPS_ACCEL_CLT_CORR_TABLE]
scaled_channel< uint8_t, 1, 50 > predictiveMapBlendDurationBins[TPS_TPS_ACCEL_CLT_CORR_TABLE]
printf("\n")