2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
2020-07-24 19:30:12 -07:00
|
|
|
#include "speed_density_airmass.h"
|
|
|
|
|
2021-06-30 21:05:42 -07:00
|
|
|
AirmassResult SpeedDensityAirmass::getAirmass(int rpm) {
|
2020-07-24 19:30:12 -07:00
|
|
|
ScopePerf perf(PE::GetSpeedDensityFuel);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* most of the values are pre-calculated for performance reasons
|
|
|
|
*/
|
|
|
|
float tChargeK = ENGINE(engineState.sd.tChargeK);
|
|
|
|
if (cisnan(tChargeK)) {
|
|
|
|
warning(CUSTOM_ERR_TCHARGE_NOT_READY2, "tChargeK not ready"); // this would happen before we have CLT reading for example
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2021-01-31 14:19:06 -08:00
|
|
|
auto map = getMap(rpm);
|
2020-07-24 19:30:12 -07:00
|
|
|
|
2021-10-16 19:08:47 -07:00
|
|
|
float ve = getVe(rpm, map);
|
2020-07-24 19:30:12 -07:00
|
|
|
|
2021-10-16 19:08:47 -07:00
|
|
|
float airMass = getAirmassImpl(ve, map, tChargeK PASS_ENGINE_PARAMETER_SUFFIX);
|
2020-07-24 19:30:12 -07:00
|
|
|
if (cisnan(airMass)) {
|
|
|
|
warning(CUSTOM_ERR_6685, "NaN airMass");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
#if EFI_PRINTF_FUEL_DETAILS
|
2021-10-16 18:49:38 -07:00
|
|
|
printf("getSpeedDensityAirmass map=%.2f\n",
|
|
|
|
map);
|
2020-07-24 19:30:12 -07:00
|
|
|
#endif /*EFI_PRINTF_FUEL_DETAILS */
|
|
|
|
|
|
|
|
return {
|
|
|
|
airMass,
|
2021-01-27 17:31:29 -08:00
|
|
|
map, // AFR/VE table Y axis
|
2020-07-24 19:30:12 -07:00
|
|
|
};
|
|
|
|
}
|
2021-01-31 14:19:06 -08:00
|
|
|
|
|
|
|
float SpeedDensityAirmass::getMap(int rpm) const {
|
2021-10-16 20:17:45 -07:00
|
|
|
SensorResult map = Sensor::get(SensorType::Map);
|
|
|
|
if (map) {
|
|
|
|
return map.Value;
|
2021-01-31 14:19:06 -08:00
|
|
|
} else {
|
2021-10-16 20:17:45 -07:00
|
|
|
float fallbackMap;
|
|
|
|
if (CONFIG(enableMapEstimationTableFallback)) {
|
|
|
|
// if the map estimation table is enabled, estimate map based on the TPS and RPM
|
2021-11-03 16:53:26 -07:00
|
|
|
fallbackMap = m_mapEstimationTable->getValue(rpm, Sensor::getOrZero(SensorType::Tps1));
|
2021-10-16 20:17:45 -07:00
|
|
|
} else {
|
|
|
|
fallbackMap = CONFIG(failedMapFallback);
|
|
|
|
}
|
2021-01-31 14:19:06 -08:00
|
|
|
|
|
|
|
#if EFI_TUNER_STUDIO
|
|
|
|
if (CONFIG(debugMode) == DBG_MAP) {
|
|
|
|
tsOutputChannels.debugFloatField4 = fallbackMap;
|
|
|
|
}
|
|
|
|
#endif // EFI_TUNER_STUDIO
|
|
|
|
|
2021-10-16 20:17:45 -07:00
|
|
|
return fallbackMap;
|
|
|
|
}
|
2021-01-31 14:19:06 -08:00
|
|
|
}
|