fome-fw/firmware/controllers/algo/airmass/speed_density_airmass.cpp

55 lines
1.4 KiB
C++
Raw Normal View History

#include "pch.h"
2020-07-24 19:30:12 -07:00
#include "speed_density_airmass.h"
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;
2020-07-24 19:30:12 -07:00
if (cisnan(tChargeK)) {
warning(CUSTOM_ERR_TCHARGE_NOT_READY2, "tChargeK not ready"); // this would happen before we have CLT reading for example
return {};
}
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
float airMass = getAirmassImpl(ve, map, tChargeK);
2020-07-24 19:30:12 -07:00
if (cisnan(airMass)) {
warning(CUSTOM_ERR_6685, "NaN airMass");
return {};
}
#if EFI_PRINTF_FUEL_DETAILS
printf("getSpeedDensityAirmass map=%.2f\n", map);
2020-07-24 19:30:12 -07:00
#endif /*EFI_PRINTF_FUEL_DETAILS */
return {
airMass,
map, // AFR/VE table Y axis
2020-07-24 19:30:12 -07: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;
} else {
2021-10-16 20:17:45 -07:00
float fallbackMap;
if (engineConfiguration->enableMapEstimationTableFallback) {
2021-10-16 20:17:45 -07:00
// if the map estimation table is enabled, estimate map based on the TPS and RPM
fallbackMap = m_mapEstimationTable->getValue(rpm, Sensor::getOrZero(SensorType::Tps1));
2021-10-16 20:17:45 -07:00
} else {
fallbackMap = engineConfiguration->failedMapFallback;
2021-10-16 20:17:45 -07:00
}
#if EFI_TUNER_STUDIO
engine->outputChannels.fallbackMap = fallbackMap;
#endif // EFI_TUNER_STUDIO
2021-10-16 20:17:45 -07:00
return fallbackMap;
}
}