This commit is contained in:
Matthew Kennedy 2020-06-03 18:12:12 -07:00 committed by GitHub
parent d1290eff0f
commit 2bdd8128db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 33 additions and 81 deletions

View File

@ -289,7 +289,7 @@ static void showFuelInfo2(float rpm, float engineLoad) {
float magicAir = getCylinderAirMass(1, 100, convertCelsiusToKelvin(20) PASS_ENGINE_PARAMETER_SUFFIX);
scheduleMsg(&logger, "SD magic fuel %.2f", sdMath(magicAir, 14.7 PASS_ENGINE_PARAMETER_SUFFIX));
scheduleMsg(&logger, "SD magic fuel %.2f", getInjectionDurationForAirmass(magicAir, 14.7 PASS_ENGINE_PARAMETER_SUFFIX));
scheduleMsg(&logger, "inj flow %.2fcc/min displacement %.2fL", engineConfiguration->injector.flow,
engineConfiguration->specs.displacement);

View File

@ -169,13 +169,27 @@ float getRealMafFuel(float airSpeed, int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
//Correct air mass by VE table
float corrCylAirmass = cylinderAirmass * veMap.getValue(rpm, airChargeLoad) / 100;
float fuelMassGram = corrCylAirmass / afrMap.getValue(rpm, airSpeed);
float pulseWidthSeconds = fuelMassGram / cc_minute_to_gramm_second(engineConfiguration->injector.flow);
float afr = afrMap.getValue(rpm, airChargeLoad);
float pulseWidthSeconds = getInjectionDurationForAirmass(corrCylAirmass, afr PASS_ENGINE_PARAMETER_SUFFIX);
// Convert to ms
return 1000 * pulseWidthSeconds;
}
constexpr float convertToGramsPerSecond(float ccPerMinute) {
float ccPerSecond = ccPerMinute / 60;
return ccPerSecond * 0.72f; // 0.72g/cc fuel density
}
/**
* @return per cylinder injection time, in seconds
*/
float getInjectionDurationForAirmass(float airMass, float afr DECLARE_ENGINE_PARAMETER_SUFFIX) {
float gPerSec = convertToGramsPerSecond(CONFIG(injector.flow));
return airMass / (afr * gPerSec);
}
/**
* per-cylinder fuel amount
* todo: rename this method since it's now base+TPSaccel

View File

@ -41,3 +41,4 @@ float getStandardAirCharge(DECLARE_ENGINE_PARAMETER_SIGNATURE);
// convert injection duration (Ms/Nt) to fuel rate (L/h)
float getFuelRate(floatms_t totalInjDuration, efitick_t timePeriod DECLARE_ENGINE_PARAMETER_SUFFIX);
float getInjectionDurationForAirmass(float airMass, float afr DECLARE_ENGINE_PARAMETER_SUFFIX);

View File

@ -1,40 +0,0 @@
/*
* @file config_engine_specs.h
*
* @date Jan 28, 2019
* @author Andrey Belomutskiy, (c) 2012-2020
*/
#pragma once
#include "global.h"
/**
* All these scary macro are about three goals:
* 1) performance optimization: real ECU hardware firmware should access configuration via direct global variable access without any pointers
* 2) design enforcement: unit tests should access configuration via pointers, NOT via global variables
* 3) design enforcement: user code should take special considerations in order to access specific group of configuration and not have access to complete configuration by default
*/
#if EFI_UNIT_TEST
#define DECLARE_GLOBAL_SIGNATURE Engine *engine, engine_configuration_s *___engineConfiguration, persistent_config_s *config
#define DECLARE_GLOBAL_SUFFIX , DECLARE_GLOBAL_SIGNATURE
#define PASS_GLOBAL_SIGNATURE engine, ___engineConfiguration, config
#define PASS_GLOBAL_SUFFIX , PASS_GLOBAL_SIGNATURE
#define CONFIG_ACCESS_FOR_CONFIG_HEADER_ONLY(x) ___engineConfiguration->x
#else /* EFI_UNIT_TEST */
#define DECLARE_GLOBAL_SIGNATURE void
// Use this version of the macro as the suffix if method has other parameters
#define DECLARE_GLOBAL_SUFFIX
// Pass this if only magic references are needed
#define PASS_GLOBAL_SIGNATURE
// Pass this after some other parameters are passed
#define PASS_GLOBAL_SUFFIX
#define CONFIG_ACCESS_FOR_CONFIG_HEADER_ONLY(x) persistentState.persistentConfiguration.engineConfiguration.x
#endif /* EFI_UNIT_TEST */
#define get_specs_displacement CONFIG_ACCESS_FOR_CONFIG_HEADER_ONLY(specs.displacement)
#define get_specs_cylindersCount CONFIG_ACCESS_FOR_CONFIG_HEADER_ONLY(specs.cylindersCount)
#define get_injector_flow CONFIG_ACCESS_FOR_CONFIG_HEADER_ONLY(injector.flow)

View File

@ -29,7 +29,6 @@
#include "efi_gpio.h"
#include "fuel_math.h"
#include "advance_map.h"
#include "config_engine_specs.h"
EXTERN_ENGINE;
#if EFI_UNIT_TEST

View File

@ -8,12 +8,11 @@
*/
#include "global.h"
#include "globalaccess.h"
#include "speed_density.h"
#include "fuel_math.h"
#include "interpolation.h"
#include "engine.h"
#include "engine_math.h"
#include "config_engine_specs.h"
#include "perf_trace.h"
#include "sensor.h"
@ -120,40 +119,19 @@ temperature_t getTCharge(int rpm, float tps DECLARE_ENGINE_PARAMETER_SUFFIX) {
/**
* @return air mass in grams
*/
static float getCycleAirMass(float volumetricEfficiency, float MAP, float tempK DECLARE_GLOBAL_SUFFIX) {
return (get_specs_displacement * volumetricEfficiency * MAP) / (GAS_R * tempK);
static float getCycleAirMass(float volumetricEfficiency, float MAP, float tempK DECLARE_ENGINE_PARAMETER_SUFFIX) {
return (CONFIG(specs.displacement) * volumetricEfficiency * MAP) / (GAS_R * tempK);
}
float getCylinderAirMass(float volumetricEfficiency, float MAP, float tempK DECLARE_GLOBAL_SUFFIX) {
return getCycleAirMass(volumetricEfficiency, MAP, tempK PASS_GLOBAL_SUFFIX)
/ get_specs_cylindersCount;
float getCylinderAirMass(float volumetricEfficiency, float MAP, float tempK DECLARE_ENGINE_PARAMETER_SUFFIX) {
return getCycleAirMass(volumetricEfficiency, MAP, tempK PASS_ENGINE_PARAMETER_SUFFIX)
/ CONFIG(specs.cylindersCount);
}
/**
* @return per cylinder injection time, in seconds
*/
float sdMath(float airMass, float AFR DECLARE_GLOBAL_SUFFIX) {
/**
* todo: pre-calculate gramm/second injector flow to save one multiplication
* open question if that's needed since that's just a multiplication
*/
float injectorFlowRate = cc_minute_to_gramm_second(get_injector_flow);
/**
* injection_pulse_duration = fuel_mass / injector_flow
* fuel_mass = air_mass / target_afr
*
* injection_pulse_duration = (air_mass / target_afr) / injector_flow
*/
return airMass / (AFR * injectorFlowRate);
}
EXTERN_ENGINE;
/**
* @return per cylinder injection time, in Milliseconds
*/
floatms_t getSpeedDensityFuel(float map DECLARE_GLOBAL_SUFFIX) {
floatms_t getSpeedDensityFuel(float map DECLARE_ENGINE_PARAMETER_SUFFIX) {
ScopePerf perf(PE::GetSpeedDensityFuel);
/**
@ -166,12 +144,12 @@ floatms_t getSpeedDensityFuel(float map DECLARE_GLOBAL_SUFFIX) {
}
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(map), "NaN map", 0);
engine->engineState.sd.manifoldAirPressureAccelerationAdjustment = engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_GLOBAL_SIGNATURE);
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", 0);
float airMass = getCylinderAirMass(ENGINE(engineState.currentBaroCorrectedVE), adjustedMap, tChargeK PASS_GLOBAL_SUFFIX);
float airMass = getCylinderAirMass(ENGINE(engineState.currentBaroCorrectedVE), adjustedMap, tChargeK PASS_ENGINE_PARAMETER_SUFFIX);
if (cisnan(airMass)) {
warning(CUSTOM_ERR_6685, "NaN airMass");
return 0;
@ -182,7 +160,7 @@ floatms_t getSpeedDensityFuel(float map DECLARE_GLOBAL_SUFFIX) {
#endif /*EFI_PRINTF_FUEL_DETAILS */
engine->engineState.sd.airMassInOneCylinder = airMass;
return sdMath(airMass, ENGINE(engineState.targetAFR) PASS_GLOBAL_SUFFIX) * 1000;
return getInjectionDurationForAirmass(airMass, ENGINE(engineState.targetAFR) PASS_ENGINE_PARAMETER_SUFFIX) * 1000;
}
void setDefaultVETable(DECLARE_ENGINE_PARAMETER_SIGNATURE) {

View File

@ -7,12 +7,13 @@
#pragma once
#include "engine.h"
#define gramm_second_to_cc_minute(gs) ((gs) / 0.0119997981)
#define cc_minute_to_gramm_second(ccm) ((ccm) * 0.0119997981)
temperature_t getTCharge(int rpm, float tps DECLARE_ENGINE_PARAMETER_SUFFIX);
float getCylinderAirMass(float volumetricEfficiency, float MAP, float tempK DECLARE_ENGINE_PARAMETER_SUFFIX);
float sdMath(float airMass, float AFR DECLARE_ENGINE_PARAMETER_SUFFIX);
void setDefaultVETable(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void initSpeedDensity(DECLARE_ENGINE_PARAMETER_SIGNATURE);

View File

@ -16,7 +16,6 @@
#include "sensor.h"
TEST(misc, testMafFuelMath) {
printf("====================================================================================== testMafFuelMath\r\n");
WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996);
extern fuel_Map3D_t veMap;
veMap.setAll(75);
@ -26,8 +25,7 @@ TEST(misc, testMafFuelMath) {
setAfrMap(config->afrTable, 13);
float fuelMs = getRealMafFuel(300, 6000 PASS_ENGINE_PARAMETER_SUFFIX);
assertEqualsM("fuelMs", 0.75 * 13.3550, fuelMs);
EXPECT_NEAR(0.75 * 13.3547, getRealMafFuel(300, 6000 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D);
}
TEST(misc, testFuelMap) {

View File

@ -7,6 +7,7 @@
#include "engine_test_helper.h"
#include "speed_density.h"
#include "fuel_math.h"
TEST(big, testSpeedDensity) {
printf("*************************************************** testSpeedDensity\r\n");
@ -29,5 +30,5 @@ TEST(big, testSpeedDensity) {
ASSERT_FLOAT_EQ(0.9371106624, airMass);
// 0.01414 sec or 14.14 ms
ASSERT_FLOAT_EQ(0.014137065038, sdMath(airMass, 12.5 PASS_ENGINE_PARAMETER_SUFFIX));
EXPECT_NEAR(0.014137, getInjectionDurationForAirmass(airMass, 12.5 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D);
}