rusEFI
The most advanced open source ECU
speed_density_airmass.cpp
Go to the documentation of this file.
1 #include "pch.h"
3 
6 
7  auto map = getMap(rpm, postState);
8 
9  return getAirmass(rpm, map, postState);
10 }
11 
12 AirmassResult SpeedDensityAirmass::getAirmass(float rpm, float map, bool postState) {
13  /**
14  * most of the values are pre-calculated for performance reasons
15  */
16  float tChargeK = engine->engineState.sd.tChargeK;
17  if (cisnan(tChargeK)) {
18  warning(ObdCode::CUSTOM_ERR_TCHARGE_NOT_READY2, "tChargeK not ready"); // this would happen before we have CLT reading for example
19  return {};
20  }
21 
22  float ve = getVe(rpm, map, postState);
23 
24  float airMass = getAirmassImpl(ve, map, tChargeK);
25  if (cisnan(airMass)) {
26  warning(ObdCode::CUSTOM_ERR_6685, "NaN airMass");
27  return {};
28  }
29 #if EFI_PRINTF_FUEL_DETAILS
30  printf("getSpeedDensityAirmass map=%.2f\n", map);
31 #endif /*EFI_PRINTF_FUEL_DETAILS */
32 
33  return {
34  airMass,
35  map, // AFR/VE table Y axis
36  };
37 }
38 
39 float SpeedDensityAirmass::getAirflow(float rpm, float map, bool postState) {
40  auto airmassResult = getAirmass(rpm, map, postState);
41 
42  float massPerCycle = airmassResult.CylinderAirmass * engineConfiguration->cylindersCount;
43 
45  // 4 stroke engines only do a half cycle per rev
46  massPerCycle = massPerCycle / 2;
47  }
48 
49  // g/s
50  return massPerCycle * rpm / 60;
51 }
52 
53 float SpeedDensityAirmass::getMap(int rpm, bool postState) const {
55 
56 #if EFI_TUNER_STUDIO
57  if (postState) {
59  }
60 #endif // EFI_TUNER_STUDIO
61 
62  return Sensor::get(SensorType::Map).value_or(fallbackMap);
63 }
float getVe(int rpm, percent_t load, bool postState) const
Definition: airmass.cpp:17
EngineState engineState
Definition: engine.h:310
TunerStudioOutputChannels outputChannels
Definition: engine.h:96
virtual SensorResult get() const =0
static float getOrZero(SensorType type)
Definition: sensor.h:92
const ValueProvider3D *const m_mapEstimationTable
AirmassResult getAirmass(int rpm, bool postState) override
float getAirflow(float rpm, float map, bool postState)
float getMap(int rpm, bool postState) const
static mass_t getAirmassImpl(float ve, float manifoldPressure, float temperature)
virtual float getValue(float xColumn, float yRow) const =0
Engine * engine
bool warning(ObdCode code, const char *fmt,...)
@ CUSTOM_ERR_TCHARGE_NOT_READY2
@ CUSTOM_ERR_6685
@ GetSpeedDensityFuel
engine_configuration_s * engineConfiguration
fallbackMap("fallbackMap", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 352, 0.1, 0.0, 1000.0, "kPa")
scaled_channel< uint16_t, 10, 1 > fallbackMap
printf("\n")