Merge pull request #1635 from mck1117/extract-sd
Extract speed density in to an AirmassModel
This commit is contained in:
commit
a50d382a47
|
@ -0,0 +1,43 @@
|
|||
#include "global.h"
|
||||
#include "engine.h"
|
||||
#include "speed_density_airmass.h"
|
||||
#include "map.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 {};
|
||||
}
|
||||
|
||||
float map = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(map), "NaN map", {});
|
||||
|
||||
engine->engineState.sd.manifoldAirPressureAccelerationAdjustment = engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
||||
float adjustedMap = engine->engineState.sd.adjustedManifoldAirPressure = map + engine->engineState.sd.manifoldAirPressureAccelerationAdjustment;
|
||||
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(adjustedMap), "NaN adjustedMap", {});
|
||||
|
||||
float airMass = getAirmassImpl(ENGINE(engineState.currentBaroCorrectedVE), adjustedMap, tChargeK PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
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,
|
||||
map, // AFR/VE table Y axis
|
||||
};
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "speed_density_base.h"
|
||||
|
||||
class SpeedDensityAirmass : public SpeedDensityBase {
|
||||
public:
|
||||
SpeedDensityAirmass(const ValueProvider3D& veTable) : SpeedDensityBase(veTable) {}
|
||||
AirmassResult getAirmass(int rpm) override;
|
||||
};
|
|
@ -9,11 +9,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "engine.h"
|
||||
#include "airmass.h"
|
||||
|
||||
float idealGasLaw(float volume, float pressure, float temperature);
|
||||
|
||||
class SpeedDensityBase {
|
||||
class SpeedDensityBase : public AirmassModelBase {
|
||||
protected:
|
||||
SpeedDensityBase(const ValueProvider3D& veTable) : AirmassModelBase(veTable) {}
|
||||
|
||||
public:
|
||||
static float getAirmassImpl(float ve, float manifoldPressure, float temperature DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
};
|
||||
|
|
|
@ -13,4 +13,5 @@ CONTROLLERS_ALGO_SRC_CPP = $(PROJECT_DIR)/controllers/algo/advance_map.cpp \
|
|||
$(PROJECT_DIR)/controllers/algo/event_registry.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/airmass/airmass.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/airmass/maf_airmass.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/airmass/speed_density_airmass.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/airmass/speed_density_base.cpp \
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "global.h"
|
||||
#include "airmass.h"
|
||||
#include "maf_airmass.h"
|
||||
#include "speed_density_airmass.h"
|
||||
#include "fuel_math.h"
|
||||
#include "interpolation.h"
|
||||
#include "engine_configuration.h"
|
||||
|
@ -168,17 +169,14 @@ float getInjectionDurationForAirmass(float airMass, float afr DECLARE_ENGINE_PAR
|
|||
return airMass / (afr * gPerSec);
|
||||
}
|
||||
|
||||
static SpeedDensityAirmass sdAirmass(veMap);
|
||||
static MafAirmass mafAirmass(veMap);
|
||||
|
||||
AirmassResult getAirmass(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
AirmassModelBase* getAirmassModel(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
switch (CONFIG(fuelAlgorithm)) {
|
||||
case LM_SPEED_DENSITY:
|
||||
return getSpeedDensityAirmass(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
case LM_REAL_MAF: {
|
||||
return mafAirmass.getAirmass(rpm);
|
||||
} default:
|
||||
firmwareError(CUSTOM_ERR_ASSERT, "Fuel mode %d is not airmass mode", CONFIG(fuelAlgorithm));
|
||||
return {};
|
||||
case LM_SPEED_DENSITY: return &sdAirmass;
|
||||
case LM_REAL_MAF: return &mafAirmass;
|
||||
default: return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,13 +195,14 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
|
||||
if ((CONFIG(fuelAlgorithm) == LM_SPEED_DENSITY) || (engineConfiguration->fuelAlgorithm == LM_REAL_MAF)) {
|
||||
// airmass modes - get airmass first, then convert to fuel
|
||||
auto airmass = getAirmass(rpm PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
auto model = getAirmassModel(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
efiAssert(CUSTOM_ERR_ASSERT, model != nullptr, "Invalid airmass mode", 0.0f);
|
||||
|
||||
auto airmass = model->getAirmass(rpm);
|
||||
|
||||
// The airmass mode will tell us how to look up AFR - use the provided Y axis value
|
||||
float targetAfr = afrMap.getValue(rpm, airmass.EngineLoadPercent);
|
||||
|
||||
// TODO: surface airmass.EngineLoadPercent to tunerstudio for proper display
|
||||
|
||||
// Plop some state for others to read
|
||||
ENGINE(engineState.targetAFR) = targetAfr;
|
||||
ENGINE(engineState.sd.airMassInOneCylinder) = airmass.CylinderAirmass;
|
||||
|
@ -351,6 +350,7 @@ floatms_t getInjectorLag(float vBatt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
* is to prepare the fuel map data structure for 3d interpolation
|
||||
*/
|
||||
void initFuelMap(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
INJECT_ENGINE_REFERENCE(&sdAirmass);
|
||||
INJECT_ENGINE_REFERENCE(&mafAirmass);
|
||||
|
||||
fuelMap.init(config->fuelTable, config->fuelLoadBins, config->fuelRpmBins);
|
||||
|
|
|
@ -112,42 +112,6 @@ temperature_t getTCharge(int rpm, float tps DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
return Tcharge;
|
||||
}
|
||||
|
||||
AirmassResult getSpeedDensityAirmass(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
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 {};
|
||||
}
|
||||
|
||||
float map = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(map), "NaN map", {});
|
||||
|
||||
engine->engineState.sd.manifoldAirPressureAccelerationAdjustment = engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
||||
float adjustedMap = engine->engineState.sd.adjustedManifoldAirPressure = map + engine->engineState.sd.manifoldAirPressureAccelerationAdjustment;
|
||||
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(adjustedMap), "NaN adjustedMap", {});
|
||||
|
||||
float airMass = SpeedDensityBase::getAirmassImpl(ENGINE(engineState.currentBaroCorrectedVE), adjustedMap, tChargeK PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
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,
|
||||
map, // AFR/VE table Y axis
|
||||
};
|
||||
}
|
||||
|
||||
void setDefaultVETable(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
setRpmTableBin(config->veRpmBins, FUEL_RPM_COUNT);
|
||||
veMap.setAll(80);
|
||||
|
|
|
@ -18,4 +18,3 @@ temperature_t getTCharge(int rpm, float tps DECLARE_ENGINE_PARAMETER_SUFFIX);
|
|||
|
||||
void setDefaultVETable(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
void initSpeedDensity(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
AirmassResult getSpeedDensityAirmass(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
|
Loading…
Reference in New Issue