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
|
|
|
|
*/
|
2021-11-17 00:54:21 -08:00
|
|
|
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 {};
|
|
|
|
}
|
|
|
|
|
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-11-16 01:15:29 -08: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
|
2022-03-15 07:31:19 -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 {
|
2022-04-28 05:16:02 -07:00
|
|
|
float fallbackMap;
|
|
|
|
if (engineConfiguration->enableMapEstimationTableFallback) {
|
|
|
|
// 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-01-31 14:19:06 -08:00
|
|
|
} else {
|
2022-04-28 05:16:02 -07:00
|
|
|
fallbackMap = engineConfiguration->failedMapFallback;
|
|
|
|
}
|
2021-01-31 14:19:06 -08:00
|
|
|
|
|
|
|
#if EFI_TUNER_STUDIO
|
2021-12-07 17:18:47 -08:00
|
|
|
engine->outputChannels.fallbackMap = fallbackMap;
|
2021-01-31 14:19:06 -08:00
|
|
|
#endif // EFI_TUNER_STUDIO
|
|
|
|
|
2022-04-28 05:16:02 -07:00
|
|
|
return Sensor::get(SensorType::Map).value_or(fallbackMap);
|
2021-01-31 14:19:06 -08:00
|
|
|
}
|