implement `FuelDifferentialPressureTest` (closes #6972)

This commit is contained in:
kifir 2024-11-22 17:03:47 +02:00 committed by kifir23917
parent 00376273d4
commit a36a8614da
9 changed files with 327 additions and 0 deletions

View File

@ -31,14 +31,20 @@ namespace engine_configuration_defaults {
constexpr launchActivationMode_e LAUNCH_ACTIVATION_MODE = SWITCH_INPUT_LAUNCH;
constexpr int LAUNCH_SPEED_THRESHOLD = 0;
constexpr fuel_pressure_sensor_mode_e FUEL_PRESSURE_SENSOR_MODE = FPM_Absolute;
/* Injector */
constexpr bool INJECTOR_FLOW_AS_MASS_FLOW = false;
constexpr float INJECTOR_FLOW = 200.0f;
constexpr BattLagCorrCurve INJECTOR_BATT_LAG_CURR { 3.371f, 1.974f, 1.383f, 1.194f, 1.04f, 0.914f, 0.797f, 0.726 };
constexpr float FUEL_REFERENCE_PRESSURE = 300.0f;
constexpr injector_compensation_mode_e INJECTOR_COMPENSATION_MODE = ICM_None;
/* Secondary injector: */
constexpr float INJECTOR_SECONDARY_FLOW = INJECTOR_FLOW;
constexpr BattLagCorrCurve INJECTOR_SECONDARY_BATT_LAG_CURR = INJECTOR_BATT_LAG_CURR;
constexpr float SECONDARY_INJECTOR_FUEL_REFERENCE_PRESSURE = 0.0f;
constexpr injector_compensation_mode_e SECONDARY_INJECTOR_COMPENSATION_MODE = INJECTOR_COMPENSATION_MODE;
/* Staged injection: */
constexpr bool ENABLE_STAGED_INJECTION = false;

View File

@ -0,0 +1,188 @@
//
// Created by kifir on 11/21/24.
//
#include "pch.h"
#include "util/test_base.h"
namespace {
constexpr float TEST_PRIMARY_INJECTOR_FUEL_REFERENCE_PRESSURE = 5423.1f;
constexpr float TEST_SECONDARY_INJECTOR_FUEL_REFERENCE_PRESSURE = 678.9f;
constexpr float TEST_MAP = 78.9f;
constexpr float TEST_BAROMETRIC_PRESSURE = 67.8f;
constexpr float TEST_FUEL_PRESSURE_INJECTOR = 76.5f;
constexpr float TEST_PRIMARY_INJECTOR_FIXED_RAIL_FUEL_DIFFERENTIAL_PRESSURE
= TEST_PRIMARY_INJECTOR_FUEL_REFERENCE_PRESSURE + TEST_BAROMETRIC_PRESSURE - TEST_MAP;
constexpr float TEST_SECONDARY_INJECTOR_FIXED_RAIL_FUEL_DIFFERENTIAL_PRESSURE
= TEST_SECONDARY_INJECTOR_FUEL_REFERENCE_PRESSURE + TEST_BAROMETRIC_PRESSURE - TEST_MAP;
constexpr float TEST_SENSED_RAIL_ABSOLUTE_FUEL_DIFFERENTIAL_PRESSURE
= TEST_FUEL_PRESSURE_INJECTOR - TEST_MAP;
constexpr float TEST_SENSED_RAIL_GAUGE_FUEL_DIFFERENTIAL_PRESSURE
= TEST_FUEL_PRESSURE_INJECTOR + TEST_BAROMETRIC_PRESSURE - TEST_MAP;
const EngineConfig TEST_ENGINE_CONFIG = EngineConfig()
.setFuelReferencePressure(TEST_PRIMARY_INJECTOR_FUEL_REFERENCE_PRESSURE)
.setSecondaryInjectorFuelReferencePressure(TEST_SECONDARY_INJECTOR_FUEL_REFERENCE_PRESSURE);
class FuelDifferentialPressureTest : public TestBase {
protected:
void SetUp() override;
void checkFuelDifferrentialPressure(
const EngineConfig& engineConfig,
std::optional<float> primaryInjectorFuelDifferentialPressure,
std::optional<float> secondaryInjectorFuelDifferentialPressure,
const char* context
);
private:
expected<float> getPrimaryInjectorFuelDifferentialPressure();
expected<float> getSecondaryInjectorFuelDifferentialPressure();
};
void FuelDifferentialPressureTest::SetUp(){
TestBase::SetUp();
Sensor::setMockValue(SensorType::Map, TEST_MAP);
Sensor::setMockValue(SensorType::BarometricPressure, TEST_BAROMETRIC_PRESSURE);
Sensor::setMockValue(SensorType::FuelPressureInjector, TEST_FUEL_PRESSURE_INJECTOR);
}
void FuelDifferentialPressureTest::checkFuelDifferrentialPressure(
const EngineConfig& engineConfig,
const std::optional<float> expectedPrimaryInjectorFuelDifferentialPressure,
const std::optional<float> expectedSecondaryInjectorFuelDifferentialPressure,
const char* const context
) {
setUpEngineConfiguration(engineConfig);
constexpr float INVALID_PRESSURE = -1.0f;
if (expectedPrimaryInjectorFuelDifferentialPressure.has_value()) {
EXPECT_NE(expectedPrimaryInjectorFuelDifferentialPressure, INVALID_PRESSURE) << context;
EXPECT_NEAR(
expectedPrimaryInjectorFuelDifferentialPressure.value(),
getPrimaryInjectorFuelDifferentialPressure().value_or(INVALID_PRESSURE),
EPS5D
) << context;
} else {
EXPECT_FALSE(getPrimaryInjectorFuelDifferentialPressure().Valid);
}
if (expectedSecondaryInjectorFuelDifferentialPressure.has_value()) {
EXPECT_NE(expectedSecondaryInjectorFuelDifferentialPressure.value(), INVALID_PRESSURE) << context;
EXPECT_NEAR(
expectedSecondaryInjectorFuelDifferentialPressure.value(),
getSecondaryInjectorFuelDifferentialPressure().value_or(INVALID_PRESSURE),
EPS5D
) << context;
} else {
EXPECT_FALSE(getSecondaryInjectorFuelDifferentialPressure().Valid);
}
}
expected<float> FuelDifferentialPressureTest::getPrimaryInjectorFuelDifferentialPressure() {
return getModule<InjectorModelPrimary>().getFuelDifferentialPressure();
}
expected<float> FuelDifferentialPressureTest::getSecondaryInjectorFuelDifferentialPressure() {
return getModule<InjectorModelSecondary>().getFuelDifferentialPressure();
}
TEST_F(FuelDifferentialPressureTest, checkDefault) {
checkFuelDifferrentialPressure(
TEST_ENGINE_CONFIG,
{},
{},
"default"
);
}
TEST_F(FuelDifferentialPressureTest, checkNone) {
checkFuelDifferrentialPressure(
TEST_ENGINE_CONFIG.clone()
.setInjectorCompensationMode(ICM_None)
.setSecondaryInjectorCompensationMode(ICM_None),
{},
{},
"primaryInjectorCompensationMode=ICM_None, "
"secondaryInjectorCompensationMode=ICM_None"
);
}
TEST_F(FuelDifferentialPressureTest, checkFixedRailPressure) {
checkFuelDifferrentialPressure(
TEST_ENGINE_CONFIG.clone()
.setInjectorCompensationMode(ICM_FixedRailPressure)
.setSecondaryInjectorCompensationMode(ICM_FixedRailPressure),
{ TEST_PRIMARY_INJECTOR_FIXED_RAIL_FUEL_DIFFERENTIAL_PRESSURE },
{ TEST_SECONDARY_INJECTOR_FIXED_RAIL_FUEL_DIFFERENTIAL_PRESSURE },
"primaryInjectorCompensationMode=ICM_FixedRailPressure, "
"secondaryInjectorCompensationMode=ICM_FixedRailPressure"
);
}
TEST_F(FuelDifferentialPressureTest, checkSensedRailPressureDefault) {
checkFuelDifferrentialPressure(
TEST_ENGINE_CONFIG.clone()
.setInjectorCompensationMode(ICM_SensedRailPressure)
.setSecondaryInjectorCompensationMode(ICM_SensedRailPressure),
{ TEST_SENSED_RAIL_ABSOLUTE_FUEL_DIFFERENTIAL_PRESSURE },
{ TEST_SENSED_RAIL_ABSOLUTE_FUEL_DIFFERENTIAL_PRESSURE },
"primaryInjectorCompensationMode=ICM_SensedRailPressure, "
"secondaryInjectorCompensationMode=ICM_SensedRailPressure"
);
}
TEST_F(FuelDifferentialPressureTest, checkSensedRailPressureAbsolute) {
checkFuelDifferrentialPressure(
TEST_ENGINE_CONFIG.clone()
.setInjectorCompensationMode(ICM_SensedRailPressure)
.setSecondaryInjectorCompensationMode(ICM_SensedRailPressure)
.setFuelPressureSensorMode(FPM_Absolute),
{ TEST_SENSED_RAIL_ABSOLUTE_FUEL_DIFFERENTIAL_PRESSURE },
{ TEST_SENSED_RAIL_ABSOLUTE_FUEL_DIFFERENTIAL_PRESSURE },
"primaryInjectorCompensationMode=ICM_SensedRailPressure, "
"secondaryInjectorCompensationMode=ICM_SensedRailPressure, "
"fuelPressureSensorMode=FPM_Absolute"
);
}
TEST_F(FuelDifferentialPressureTest, checkSensedRailPressureGauge) {
checkFuelDifferrentialPressure(
TEST_ENGINE_CONFIG.clone()
.setInjectorCompensationMode(ICM_SensedRailPressure)
.setSecondaryInjectorCompensationMode(ICM_SensedRailPressure)
.setFuelPressureSensorMode(FPM_Gauge),
{ TEST_SENSED_RAIL_GAUGE_FUEL_DIFFERENTIAL_PRESSURE },
{ TEST_SENSED_RAIL_GAUGE_FUEL_DIFFERENTIAL_PRESSURE },
"primaryInjectorCompensationMode=ICM_SensedRailPressure, "
"secondaryInjectorCompensationMode=ICM_SensedRailPressure, "
"fuelPressureSensorMode=FPM_Gauge"
);
}
TEST_F(FuelDifferentialPressureTest, checkSensedRailPressureDifferential) {
checkFuelDifferrentialPressure(
TEST_ENGINE_CONFIG.clone()
.setInjectorCompensationMode(ICM_SensedRailPressure)
.setSecondaryInjectorCompensationMode(ICM_SensedRailPressure)
.setFuelPressureSensorMode(FPM_Differential),
{ TEST_FUEL_PRESSURE_INJECTOR },
{ TEST_FUEL_PRESSURE_INJECTOR },
"primaryInjectorCompensationMode=ICM_SensedRailPressure, "
"secondaryInjectorCompensationMode=ICM_SensedRailPressure, "
"fuelPressureSensorMode=FPM_Differential"
);
}
TEST_F(FuelDifferentialPressureTest, checkMix) {
checkFuelDifferrentialPressure(
TEST_ENGINE_CONFIG.clone()
.setInjectorCompensationMode(ICM_FixedRailPressure)
.setSecondaryInjectorCompensationMode(ICM_SensedRailPressure),
{ TEST_PRIMARY_INJECTOR_FIXED_RAIL_FUEL_DIFFERENTIAL_PRESSURE },
{ TEST_SENSED_RAIL_ABSOLUTE_FUEL_DIFFERENTIAL_PRESSURE },
"primaryInjectorCompensationMode=ICM_FixedRailPressure, "
"secondaryInjectorCompensationMode=ICM_SensedRailPressure"
);
}
}

View File

@ -49,6 +49,7 @@ TESTS_SRC_CPP = \
tests/ignition_injection/test_odd_firing_engine.cpp \
tests/ignition_injection/test_three_cylinder.cpp \
testa/ignition_injection/test_staged_injection.cpp \
testa/ignition_injection/test_fuel_differential_pressure.cpp \
tests/util/test_base.cpp \
tests/util/test_engine_configuration.cpp \
tests/util/engine_config.cpp \

View File

@ -122,6 +122,11 @@ EngineConfig EngineConfig::setTorqueReductionIgnitionRetard(const std::optional<
return *this;
}
EngineConfig EngineConfig::setFuelPressureSensorMode(std::optional<fuel_pressure_sensor_mode_e> value) {
m_fuelPressureSensorMode = value;
return *this;
}
EngineConfig EngineConfig::setInjectorFlowAsMassFlow(const std::optional<bool> injectorFlowAsMassFlow) {
m_injectorFlowAsMassFlow = injectorFlowAsMassFlow;
return *this;
@ -137,6 +142,16 @@ EngineConfig EngineConfig::setInjectorBattLagCorr(const std::optional<BattLagCor
return *this;
}
EngineConfig EngineConfig::setFuelReferencePressure(const std::optional<float> value) {
m_fuelReferencePressure = value;
return *this;
}
EngineConfig EngineConfig::setInjectorCompensationMode(const std::optional<injector_compensation_mode_e> value) {
m_injectorCompensationMode = value;
return *this;
}
EngineConfig EngineConfig::setInjectorSecondaryFlow(const std::optional<float> flow) {
m_injectorSecondaryFlow = flow;
return *this;
@ -151,3 +166,15 @@ EngineConfig EngineConfig::setStagedInjectionEnabled(const std::optional<bool> v
m_isStagedInjectionEnabled = value;
return *this;
}
EngineConfig EngineConfig::setSecondaryInjectorFuelReferencePressure(const std::optional<float> value) {
m_secondaryInjectorFuelReferencePressure = value;
return *this;
}
EngineConfig EngineConfig::setSecondaryInjectorCompensationMode(
const std::optional<injector_compensation_mode_e> value
) {
m_secondaryInjectorCompensationMode = value;
return *this;
}

View File

@ -41,14 +41,20 @@ public:
std::optional<int8_t> getTorqueReductionIgnitionCut() const { return m_torqueReductionIgnitionCut; }
std::optional<float> getTorqueReductionIgnitionRetard() const { return m_torqueReductionIgnitionRetard; }
std::optional<fuel_pressure_sensor_mode_e> getFuelPressureSensorMode() const { return m_fuelPressureSensorMode; };
// Injector
std::optional<float> getInjectorFlow() const { return m_injectorFlow; }
std::optional<BattLagCorrCurve> getInjectorBattLagCorr() const { return m_injectorBattLagCorrCurve; }
std::optional<bool> getInjectorFlowAsMassFlow() const { return m_injectorFlowAsMassFlow; }
std::optional<float> getFuelReferencePressure() const { return m_fuelReferencePressure; }
std::optional<injector_compensation_mode_e> getInjectorCompensationMode() const { return m_injectorCompensationMode; }
// Secondary injector
std::optional<float> getInjectorSecondaryFlow() const { return m_injectorSecondaryFlow; }
std::optional<BattLagCorrCurve> getInjectorSecondaryBattLagCorr() const { return m_injectorSecondaryBattLagCorrCurve; }
std::optional<float> getSecondaryInjectorFuelReferencePressure() const { return m_secondaryInjectorFuelReferencePressure; }
std::optional<injector_compensation_mode_e> getSecondaryInjectorCompensationMode() const { return m_secondaryInjectorCompensationMode; }
// Staged injection
std::optional<bool> getStagedInjectionEnabled() const { return m_isStagedInjectionEnabled; }
@ -82,14 +88,20 @@ public:
EngineConfig setTorqueReductionIgnitionCut(std::optional<int8_t> value);
EngineConfig setTorqueReductionIgnitionRetard(std::optional<float> value);
EngineConfig setFuelPressureSensorMode(std::optional<fuel_pressure_sensor_mode_e> value);
// Injector
EngineConfig setInjectorFlowAsMassFlow(std::optional<bool> injectorFlowAsMassFlow);
EngineConfig setInjectorFlow(std::optional<float> flow);
EngineConfig setInjectorBattLagCorr(std::optional<BattLagCorrCurve> battLagCorr);
EngineConfig setFuelReferencePressure(std::optional<float> value);
EngineConfig setInjectorCompensationMode(std::optional<injector_compensation_mode_e> value);
// Secondary injector
EngineConfig setInjectorSecondaryFlow(std::optional<float> flow);
EngineConfig setInjectorSecondaryBattLagCorr(std::optional<BattLagCorrCurve> battLagCorr);
EngineConfig setSecondaryInjectorFuelReferencePressure(std::optional<float> value);
EngineConfig setSecondaryInjectorCompensationMode(std::optional<injector_compensation_mode_e> value);
// Staged injection
EngineConfig setStagedInjectionEnabled(std::optional<bool> value);
@ -120,14 +132,20 @@ private:
std::optional<int8_t> m_torqueReductionIgnitionCut;
std::optional<float> m_torqueReductionIgnitionRetard;
std::optional<fuel_pressure_sensor_mode_e> m_fuelPressureSensorMode;
// Injector
std::optional<float> m_injectorFlow;
std::optional<BattLagCorrCurve> m_injectorBattLagCorrCurve;
std::optional<bool> m_injectorFlowAsMassFlow;;
std::optional<float> m_fuelReferencePressure;
std::optional<injector_compensation_mode_e> m_injectorCompensationMode;
// Secondary injector
std::optional<float> m_injectorSecondaryFlow;
std::optional<BattLagCorrCurve> m_injectorSecondaryBattLagCorrCurve;
std::optional<float> m_secondaryInjectorFuelReferencePressure;
std::optional<injector_compensation_mode_e> m_secondaryInjectorCompensationMode;
// Staged injection
std::optional<bool> m_isStagedInjectionEnabled;

View File

@ -53,14 +53,24 @@ void TestBase::setUpEngineConfiguration(const EngineConfig& config) {
getTestEngineConfiguration().configureTorqueReductionIgnitionCut(config.getTorqueReductionIgnitionCut());
getTestEngineConfiguration().configureTorqueReductionIgnitionRetard(config.getTorqueReductionIgnitionRetard());
getTestEngineConfiguration().configureFuelPressureSensorMode(config.getFuelPressureSensorMode());
// Injector
getTestEngineConfiguration().configureInjectorFlowAsMassFlow(config.getInjectorFlowAsMassFlow());
getTestEngineConfiguration().configureInjectorFlow(config.getInjectorFlow());
getTestEngineConfiguration().configureInjectorBattLagCorr(config.getInjectorBattLagCorr());
getTestEngineConfiguration().configureFuelReferencePressure(config.getFuelReferencePressure());
getTestEngineConfiguration().configureInjectorCompensationMode(config.getInjectorCompensationMode());
// Secondary injector
getTestEngineConfiguration().configureInjectorSecondaryFlow(config.getInjectorSecondaryFlow());
getTestEngineConfiguration().configureInjectorSecondaryBattLagCorr(config.getInjectorSecondaryBattLagCorr());
getTestEngineConfiguration().configureSecondaryInjectorFuelReferencePressure(
config.getSecondaryInjectorFuelReferencePressure()
);
getTestEngineConfiguration().configureSecondaryInjectorCompensationMode(
config.getSecondaryInjectorCompensationMode()
);
// Staged injection
getTestEngineConfiguration().configureEnableStagedInjection(config.getStagedInjectionEnabled());

View File

@ -25,6 +25,12 @@ protected:
void updateRpm(float rpm);
void updateApp(std::optional<float> app);
template<typename ModuleType> ModuleType& getModule();
private:
std::unique_ptr<EngineTestHelper> eth;
};
template<typename ModuleType> ModuleType& TestBase::getModule() {
return engine->module<ModuleType>().unmock();
}

View File

@ -252,6 +252,19 @@ void TestEngineConfiguration::configureTorqueReductionIgnitionRetard(const std::
}
}
void TestEngineConfiguration::configureFuelPressureSensorMode(
const std::optional<fuel_pressure_sensor_mode_e> fuelPressureSensorMode
) {
if (fuelPressureSensorMode.has_value()) {
engineConfiguration->fuelPressureSensorMode = fuelPressureSensorMode.value();
} else {
ASSERT_EQ(
engineConfiguration->fuelPressureSensorMode,
engine_configuration_defaults::FUEL_PRESSURE_SENSOR_MODE
); // check default value
}
}
void TestEngineConfiguration::configureInjectorFlowAsMassFlow(const std::optional<bool> injectorFlowAsMassFlow) {
if (injectorFlowAsMassFlow.has_value()) {
engineConfiguration->injectorFlowAsMassFlow = injectorFlowAsMassFlow.value();
@ -286,6 +299,30 @@ void TestEngineConfiguration::configureInjectorBattLagCorr(const std::optional<B
}
}
void TestEngineConfiguration::configureFuelReferencePressure(const std::optional<float> fuelReferencePressure) {
if (fuelReferencePressure.has_value()) {
engineConfiguration->fuelReferencePressure = fuelReferencePressure.value();
} else {
ASSERT_EQ(
engineConfiguration->fuelReferencePressure,
engine_configuration_defaults::FUEL_REFERENCE_PRESSURE
); // check default value
}
}
void TestEngineConfiguration::configureInjectorCompensationMode(
const std::optional<injector_compensation_mode_e> injectorCompensationMode
) {
if (injectorCompensationMode.has_value()) {
engineConfiguration->injectorCompensationMode = injectorCompensationMode.value();
} else {
ASSERT_EQ(
engineConfiguration->injectorCompensationMode,
engine_configuration_defaults::INJECTOR_COMPENSATION_MODE
); // check default value
}
}
void TestEngineConfiguration::configureInjectorSecondaryFlow(const std::optional<float> flow) {
if (flow.has_value()) {
engineConfiguration->injectorSecondary.flow = flow.value();
@ -312,6 +349,32 @@ void TestEngineConfiguration::configureInjectorSecondaryBattLagCorr(const std::o
}
}
void TestEngineConfiguration::configureSecondaryInjectorFuelReferencePressure(
const std::optional<float> secondaryInjectorFuelReferencePressure
) {
if (secondaryInjectorFuelReferencePressure.has_value()) {
engineConfiguration->secondaryInjectorFuelReferencePressure = secondaryInjectorFuelReferencePressure.value();
} else {
ASSERT_EQ(
engineConfiguration->secondaryInjectorFuelReferencePressure,
engine_configuration_defaults::SECONDARY_INJECTOR_FUEL_REFERENCE_PRESSURE
); // check default value
}
}
void TestEngineConfiguration::configureSecondaryInjectorCompensationMode(
const std::optional<injector_compensation_mode_e> secondaryInjectorCompensationMode
) {
if (secondaryInjectorCompensationMode.has_value()) {
engineConfiguration->secondaryInjectorCompensationMode = secondaryInjectorCompensationMode.value();
} else {
ASSERT_EQ(
engineConfiguration->secondaryInjectorCompensationMode,
engine_configuration_defaults::SECONDARY_INJECTOR_COMPENSATION_MODE
); // check default value
}
}
void TestEngineConfiguration::configureEnableStagedInjection(const std::optional<bool> isStagedInjectionEnabled) {
if (isStagedInjectionEnabled.has_value()) {
engineConfiguration->enableStagedInjection = isStagedInjectionEnabled.value();

View File

@ -42,14 +42,22 @@ public:
void configureTorqueReductionIgnitionCut(std::optional<int8_t> ignitionCut);
void configureTorqueReductionIgnitionRetard(std::optional<int8_t> ignitionRetard);
void configureFuelPressureSensorMode(std::optional<fuel_pressure_sensor_mode_e> fuelPressureSensorMode);
// Injector
void configureInjectorFlow(std::optional<float> flow);
void configureInjectorBattLagCorr(std::optional<BattLagCorrCurve> battLagCorr);
void configureInjectorFlowAsMassFlow(std::optional<bool> injectorFlowAsMassFlow);
void configureFuelReferencePressure(std::optional<float> fuelReferencePressure);
void configureInjectorCompensationMode(std::optional<injector_compensation_mode_e> injectorCompensationMode);
// Secondary Injector
void configureInjectorSecondaryFlow(std::optional<float> flow);
void configureInjectorSecondaryBattLagCorr(std::optional<BattLagCorrCurve> battLagCorr);
void configureSecondaryInjectorFuelReferencePressure(std::optional<float> secondaryInjectorFuelReferencePressure);
void configureSecondaryInjectorCompensationMode(
std::optional<injector_compensation_mode_e> secondaryInjectorCompensationMode
);
// Staged injection
void configureEnableStagedInjection(std::optional<bool> isStagedInjectionEnabled);