2020-07-24 19:30:12 -07:00
|
|
|
#include "global.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "speed_density_airmass.h"
|
|
|
|
#include "perf_trace.h"
|
|
|
|
|
|
|
|
EXTERN_ENGINE;
|
|
|
|
|
|
|
|
AirmassResult SpeedDensityAirmass::getAirmass(int rpm) {
|
|
|
|
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-02 16:13:10 -08:00
|
|
|
auto map = Sensor::get(SensorType::Map);
|
|
|
|
if (!map) {
|
2020-11-17 19:45:43 -08:00
|
|
|
warning(CUSTOM_ERR_TCHARGE_NOT_READY2, "map not ready"); // this could happen during HW CI during configuration reset
|
|
|
|
return {};
|
|
|
|
}
|
2020-07-24 19:30:12 -07:00
|
|
|
|
|
|
|
engine->engineState.sd.manifoldAirPressureAccelerationAdjustment = engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
|
2021-01-02 16:13:10 -08:00
|
|
|
float adjustedMap = engine->engineState.sd.adjustedManifoldAirPressure = map.Value + engine->engineState.sd.manifoldAirPressureAccelerationAdjustment;
|
2020-07-24 19:30:12 -07:00
|
|
|
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(adjustedMap), "NaN adjustedMap", {});
|
|
|
|
|
2020-09-06 16:06:32 -07:00
|
|
|
float ve = getVe(rpm, adjustedMap);
|
|
|
|
|
|
|
|
float airMass = getAirmassImpl(ve, adjustedMap, 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
|
|
|
|
printf("getSpeedDensityAirmass map=%.2f adjustedMap=%.2f airMass=%.2f\t\n",
|
|
|
|
map, adjustedMap, engine->engineState.sd.adjustedManifoldAirPressure);
|
|
|
|
#endif /*EFI_PRINTF_FUEL_DETAILS */
|
|
|
|
|
|
|
|
return {
|
|
|
|
airMass,
|
2021-01-02 16:13:10 -08:00
|
|
|
map.Value, // AFR/VE table Y axis
|
2020-07-24 19:30:12 -07:00
|
|
|
};
|
|
|
|
}
|