move impl

This commit is contained in:
Matthew Kennedy 2020-07-23 01:23:57 -07:00
parent 49ed4d40a2
commit 5c156ebada
5 changed files with 67 additions and 39 deletions

View File

@ -0,0 +1,46 @@
#include "global.h"
#include "engine.h"
#include "maf_airmass.h"
#include "maf.h"
EXTERN_ENGINE;
AirmassResult MafAirmass::getAirmass(int rpm) {
float maf = getRealMaf(PASS_ENGINE_PARAMETER_SIGNATURE) + engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE);
return getAirmassImpl(maf, rpm);
}
/**
* Function block now works to create a standardised load from the cylinder filling as well as tune fuel via VE table.
* @return total duration of fuel injection per engine cycle, in milliseconds
*/
AirmassResult MafAirmass::getAirmassImpl(float massAirFlow, int rpm) const {
// If the engine is stopped, MAF is meaningless
if (rpm == 0) {
return {};
}
// kg/hr -> g/s
float gramPerSecond = massAirFlow * 1000 / 3600;
// 1/min -> 1/s
float revsPerSecond = rpm / 60.0f;
float airPerRevolution = gramPerSecond / revsPerSecond;
// Now we have to divide among cylinders - on a 4 stroke, half of the cylinders happen every rev
// This math is floating point to work properly on engines with odd cyl count
float halfCylCount = CONFIG(specs.cylindersCount) / 2.0f;
float cylinderAirmass = airPerRevolution / halfCylCount;
//Create % load for fuel table using relative naturally aspiratedcylinder filling
float airChargeLoad = 100 * cylinderAirmass / ENGINE(standardAirCharge);
//Correct air mass by VE table
float correctedAirmass = cylinderAirmass * getVe(rpm, airChargeLoad) / 100;
return {
correctedAirmass,
airChargeLoad, // AFR/VE/ignition table Y axis
};
}

View File

@ -0,0 +1,13 @@
#pragma once
#include "airmass.h"
class MafAirmass final : public AirmassModelBase {
public:
MafAirmass(const ValueProvider3D& veTable) : AirmassModelBase(veTable) {}
AirmassResult getAirmass(int rpm) override;
// Compute airmass based on flow & engine speed
AirmassResult getAirmassImpl(float massAirFlow, int rpm) const;
};

View File

@ -11,4 +11,6 @@ CONTROLLERS_ALGO_SRC_CPP = $(PROJECT_DIR)/controllers/algo/advance_map.cpp \
$(PROJECT_DIR)/controllers/algo/engine2.cpp \
$(PROJECT_DIR)/controllers/gauges/lcd_menu_tree.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_base.cpp \

View File

@ -23,6 +23,7 @@
#include "global.h"
#include "airmass.h"
#include "maf_airmass.h"
#include "fuel_math.h"
#include "interpolation.h"
#include "engine_configuration.h"
@ -153,41 +154,6 @@ floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_SUFFIX) {
/* DISPLAY_ENDIF */
/**
* Function block now works to create a standardised load from the cylinder filling as well as tune fuel via VE table.
* @return total duration of fuel injection per engine cycle, in milliseconds
*/
AirmassResult getRealMafAirmass(float airSpeed, int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
// If the engine is stopped, MAF is meaningless
if (rpm == 0) {
return {};
}
// kg/hr -> g/s
float gramPerSecond = airSpeed * 1000 / 3600;
// 1/min -> 1/s
float revsPerSecond = rpm / 60.0f;
float airPerRevolution = gramPerSecond / revsPerSecond;
// Now we have to divide among cylinders - on a 4 stroke, half of the cylinders happen every rev
// This math is floating point to work properly on engines with odd cyl count
float halfCylCount = CONFIG(specs.cylindersCount) / 2.0f;
float cylinderAirmass = airPerRevolution / halfCylCount;
//Create % load for fuel table using relative naturally aspiratedcylinder filling
float airChargeLoad = 100 * cylinderAirmass / ENGINE(standardAirCharge);
//Correct air mass by VE table
float correctedAirmass = cylinderAirmass * veMap.getValue(rpm, airChargeLoad) / 100;
return {
correctedAirmass,
airChargeLoad, // AFR/VE table Y axis
};
}
constexpr float convertToGramsPerSecond(float ccPerMinute) {
float ccPerSecond = ccPerMinute / 60;
return ccPerSecond * 0.72f; // 0.72g/cc fuel density
@ -202,13 +168,14 @@ float getInjectionDurationForAirmass(float airMass, float afr DECLARE_ENGINE_PAR
return airMass / (afr * gPerSec);
}
static MafAirmass mafAirmass(veMap);
AirmassResult getAirmass(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
switch (CONFIG(fuelAlgorithm)) {
case LM_SPEED_DENSITY:
return getSpeedDensityAirmass(PASS_ENGINE_PARAMETER_SIGNATURE);
case LM_REAL_MAF: {
float maf = getRealMaf(PASS_ENGINE_PARAMETER_SIGNATURE) + engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE);
return getRealMafAirmass(maf, rpm PASS_ENGINE_PARAMETER_SUFFIX);
return mafAirmass.getAirmass(rpm);
} default:
firmwareError(CUSTOM_ERR_ASSERT, "Fuel mode %d is not airmass mode", CONFIG(fuelAlgorithm));
return {};
@ -384,6 +351,8 @@ 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(&mafAirmass);
fuelMap.init(config->fuelTable, config->fuelLoadBins, config->fuelRpmBins);
#if (IGN_LOAD_COUNT == FUEL_LOAD_COUNT) && (IGN_RPM_COUNT == FUEL_RPM_COUNT)
fuelPhaseMap.init(config->injectionPhase, config->injPhaseLoadBins, config->injPhaseRpmBins);

View File

@ -22,8 +22,6 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX);
*/
floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_SUFFIX);
AirmassResult getRealMafAirmass(float airMass, int rpm DECLARE_ENGINE_PARAMETER_SUFFIX);
floatms_t getBaseTableFuel(int rpm, float engineLoad);
float getBaroCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE);
int getNumberOfInjections(injection_mode_e mode DECLARE_ENGINE_PARAMETER_SUFFIX);