2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
2020-05-06 05:40:42 -07:00
|
|
|
|
2021-08-03 19:05:01 -07:00
|
|
|
#include "boost_control.h"
|
2020-05-06 05:40:42 -07:00
|
|
|
|
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::StrictMock;
|
|
|
|
|
2024-07-30 03:51:29 -07:00
|
|
|
static Map2D<BOOST_CURVE_SIZE, float, float> testBoostCltCorr { "clt" };
|
|
|
|
static Map2D<BOOST_CURVE_SIZE, float, float> testBoostIatCorr { "iat" };
|
2024-07-31 05:10:09 -07:00
|
|
|
static Map2D<BOOST_CURVE_SIZE, float, float> testBoostCltAdder { "clt (adder)" };
|
|
|
|
static Map2D<BOOST_CURVE_SIZE, float, float> testBoostIatAdder { "iat (adder)" };
|
2024-07-30 03:51:29 -07:00
|
|
|
|
2020-05-06 05:40:42 -07:00
|
|
|
TEST(BoostControl, Setpoint) {
|
|
|
|
MockVp3d targetMap;
|
|
|
|
|
|
|
|
// Just pass TPS input to output
|
|
|
|
EXPECT_CALL(targetMap, getValue(_, _))
|
2021-12-22 05:09:41 -08:00
|
|
|
.WillRepeatedly([](float xRpm, float tps) { return tps; });
|
2020-05-06 05:40:42 -07:00
|
|
|
|
2023-05-31 22:31:28 -07:00
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
2020-11-25 04:27:24 -08:00
|
|
|
engineConfiguration->boostType = CLOSED_LOOP;
|
2020-05-06 05:40:42 -07:00
|
|
|
|
|
|
|
BoostController bc;
|
|
|
|
|
|
|
|
// Should return unexpected without a pedal map cfg'd
|
|
|
|
EXPECT_EQ(bc.getSetpoint(), unexpected);
|
|
|
|
|
2024-07-31 05:10:09 -07:00
|
|
|
testBoostCltCorr.initTable(config->cltBoostCorr, config->cltBoostCorrBins);
|
|
|
|
testBoostIatCorr.initTable(config->iatBoostCorr, config->iatBoostCorrBins);
|
|
|
|
testBoostCltAdder.initTable(config->cltBoostAdder, config->cltBoostAdderBins);
|
|
|
|
testBoostIatAdder.initTable(config->iatBoostAdder, config->iatBoostAdderBins);
|
|
|
|
|
|
|
|
// Now init with mock target map
|
|
|
|
bc.init(nullptr, nullptr, &targetMap, testBoostCltCorr, testBoostIatCorr, testBoostCltAdder, testBoostIatAdder, nullptr);
|
2020-05-06 05:40:42 -07:00
|
|
|
|
|
|
|
// Should still return unxepected since TPS is invalid
|
|
|
|
EXPECT_EQ(bc.getSetpoint(), unexpected);
|
|
|
|
|
|
|
|
// Configure TPS, should get passthru of tps value
|
|
|
|
Sensor::setMockValue(SensorType::DriverThrottleIntent, 35.0f);
|
|
|
|
EXPECT_FLOAT_EQ(bc.getSetpoint().value_or(-1), 35.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BoostControl, ObservePlant) {
|
2023-05-31 22:31:28 -07:00
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
2023-10-19 18:22:59 -07:00
|
|
|
engineConfiguration->boostType = CLOSED_LOOP;
|
2020-05-06 05:40:42 -07:00
|
|
|
|
|
|
|
BoostController bc;
|
|
|
|
|
2020-12-30 05:43:49 -08:00
|
|
|
Sensor::resetMockValue(SensorType::Map);
|
2020-05-06 05:40:42 -07:00
|
|
|
// Check that invalid MAP returns unexpected
|
|
|
|
EXPECT_EQ(bc.observePlant(), unexpected);
|
|
|
|
|
|
|
|
// Test valid MAP value
|
2020-12-30 05:43:49 -08:00
|
|
|
Sensor::setMockValue(SensorType::Map, 150);
|
2020-05-06 05:40:42 -07:00
|
|
|
|
|
|
|
EXPECT_FLOAT_EQ(bc.observePlant().value_or(0), 150.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BoostControl, OpenLoop) {
|
|
|
|
MockVp3d openMap;
|
|
|
|
|
|
|
|
// Just pass MAP input to output
|
|
|
|
EXPECT_CALL(openMap, getValue(_, _))
|
2021-12-22 05:09:41 -08:00
|
|
|
.WillRepeatedly([](float xRpm, float tps) { return tps; });
|
2020-05-06 05:40:42 -07:00
|
|
|
|
2023-05-31 22:31:28 -07:00
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
2020-05-06 05:40:42 -07:00
|
|
|
|
|
|
|
BoostController bc;
|
|
|
|
|
|
|
|
// Without table set, should return unexpected
|
|
|
|
EXPECT_EQ(bc.getOpenLoop(0), unexpected);
|
|
|
|
|
2024-07-30 03:51:29 -07:00
|
|
|
|
|
|
|
testBoostCltCorr.initTable(config->cltBoostCorr, config->cltBoostCorrBins);
|
|
|
|
testBoostIatCorr.initTable(config->iatBoostCorr, config->iatBoostCorrBins);
|
2024-07-31 05:10:09 -07:00
|
|
|
testBoostCltAdder.initTable(config->cltBoostAdder, config->cltBoostAdderBins);
|
|
|
|
testBoostIatAdder.initTable(config->iatBoostAdder, config->iatBoostAdderBins);
|
|
|
|
|
|
|
|
bc.init(
|
|
|
|
nullptr,
|
|
|
|
&openMap,
|
|
|
|
nullptr,
|
|
|
|
testBoostCltCorr,
|
|
|
|
testBoostIatCorr,
|
|
|
|
testBoostCltAdder,
|
|
|
|
testBoostIatAdder,
|
|
|
|
nullptr
|
|
|
|
);
|
2020-05-06 05:40:42 -07:00
|
|
|
|
|
|
|
// Should pass TPS value thru
|
2024-05-15 09:03:39 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 47.0f);
|
2020-05-06 05:40:42 -07:00
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), 47.0f);
|
|
|
|
}
|
|
|
|
|
2024-05-15 13:40:15 -07:00
|
|
|
TEST(BoostControl, BoostOpenLoopYAxis)
|
|
|
|
{
|
|
|
|
MockVp3d openMap;
|
|
|
|
// Just pass MAP input to output
|
|
|
|
EXPECT_CALL(openMap, getValue(_, _))
|
|
|
|
.WillRepeatedly([](float xRpm, float tps) { return tps; });
|
|
|
|
|
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
|
|
|
BoostController bc;
|
|
|
|
|
2024-07-30 03:51:29 -07:00
|
|
|
testBoostCltCorr.initTable(config->cltBoostCorr, config->cltBoostCorrBins);
|
|
|
|
testBoostIatCorr.initTable(config->iatBoostCorr, config->iatBoostCorrBins);
|
2024-07-31 05:10:09 -07:00
|
|
|
testBoostCltAdder.initTable(config->cltBoostAdder, config->cltBoostAdderBins);
|
|
|
|
testBoostIatAdder.initTable(config->iatBoostAdder, config->iatBoostAdderBins);
|
|
|
|
|
|
|
|
bc.init(
|
|
|
|
nullptr,
|
|
|
|
&openMap,
|
|
|
|
nullptr,
|
|
|
|
testBoostCltCorr,
|
|
|
|
testBoostIatCorr,
|
|
|
|
testBoostCltAdder,
|
|
|
|
testBoostIatAdder,
|
|
|
|
nullptr
|
|
|
|
);
|
2024-05-15 13:40:15 -07:00
|
|
|
|
|
|
|
constexpr float RPM_TEST_VALUE = 42.0f;
|
|
|
|
Sensor::setMockValue(SensorType::Rpm, RPM_TEST_VALUE);
|
|
|
|
constexpr float TPS1_TEST_VALUE = 42.1f;
|
|
|
|
Sensor::setMockValue(SensorType::Tps1, TPS1_TEST_VALUE);
|
|
|
|
constexpr float MAP_TEST_VALUE = 42.3f;
|
|
|
|
Sensor::setMockValue(SensorType::Map, MAP_TEST_VALUE);
|
|
|
|
constexpr float CLT_TEST_VALUE = 42.4f;
|
|
|
|
Sensor::setMockValue(SensorType::Clt, CLT_TEST_VALUE);
|
|
|
|
constexpr float IAT_TEST_VALUE = 42.5f;
|
|
|
|
Sensor::setMockValue(SensorType::Iat, IAT_TEST_VALUE);
|
|
|
|
constexpr float LUA_GAUGE1_TEST_VALUE = 42.6f;
|
|
|
|
Sensor::setMockValue(SensorType::LuaGauge1, LUA_GAUGE1_TEST_VALUE);
|
|
|
|
constexpr float LUA_GAUGE2_TEST_VALUE = 42.7f;
|
|
|
|
Sensor::setMockValue(SensorType::LuaGauge2, LUA_GAUGE2_TEST_VALUE);
|
|
|
|
constexpr float AUX_TEMP1_TEST_VALUE = 42.7f;
|
|
|
|
Sensor::setMockValue(SensorType::AuxTemp1, AUX_TEMP1_TEST_VALUE);
|
|
|
|
constexpr float AUX_TEMP2_TEST_VALUE = 42.8f;
|
|
|
|
Sensor::setMockValue(SensorType::AuxTemp2, AUX_TEMP2_TEST_VALUE);
|
|
|
|
constexpr float ACCELERATOR_PEDAL_TEST_VALUE = 42.9f;
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, ACCELERATOR_PEDAL_TEST_VALUE);
|
|
|
|
constexpr float BATTERY_VOLTAGE_TEST_VALUE = 43.0f;
|
|
|
|
Sensor::setMockValue(SensorType::BatteryVoltage, BATTERY_VOLTAGE_TEST_VALUE);
|
|
|
|
constexpr float FUEL_ETANOL_PERCENT_TEST_VALUE = 43.1f;
|
|
|
|
Sensor::setMockValue(SensorType::FuelEthanolPercent, FUEL_ETANOL_PERCENT_TEST_VALUE);
|
|
|
|
constexpr float AUX_LINEAR1_TEST_VALUE = 43.2f;
|
|
|
|
Sensor::setMockValue(SensorType::AuxLinear1, AUX_LINEAR1_TEST_VALUE);
|
|
|
|
constexpr float AUX_LINEAR2_TEST_VALUE = 43.3f;
|
|
|
|
Sensor::setMockValue(SensorType::AuxLinear2, AUX_LINEAR2_TEST_VALUE);
|
2024-05-16 02:57:24 -07:00
|
|
|
// we cannot use value 43.4f for the DetectedGear sensor because gear should be less then TCU_GEAR_COUNT
|
|
|
|
constexpr float DETECTED_GEAR_TEST_VALUE = TCU_GEAR_COUNT - 1;
|
2024-05-15 13:40:15 -07:00
|
|
|
Sensor::setMockValue(SensorType::DetectedGear, DETECTED_GEAR_TEST_VALUE);
|
|
|
|
constexpr float BAROMETRIC_PRESSURE_TEST_VALUE = 43.5f;
|
|
|
|
Sensor::setMockValue(SensorType::BarometricPressure, BAROMETRIC_PRESSURE_TEST_VALUE);
|
|
|
|
constexpr float EGT1_TEST_VALUE = 43.6f;
|
|
|
|
Sensor::setMockValue(SensorType::EGT1, EGT1_TEST_VALUE);
|
|
|
|
constexpr float EGT2_TEST_VALUE = 43.7f;
|
|
|
|
Sensor::setMockValue(SensorType::EGT2, EGT2_TEST_VALUE);
|
|
|
|
|
|
|
|
EXPECT_EQ(engineConfiguration->boostOpenLoopYAxis, gppwm_channel_e::GPPWM_Tps); // default value
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), TPS1_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_Zero;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), 0.0f);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_Rpm;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), RPM_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_Tps;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), TPS1_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_Map;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), MAP_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_Clt;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), CLT_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_Iat;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), IAT_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_LuaGauge1;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), LUA_GAUGE1_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_LuaGauge2;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), LUA_GAUGE2_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_FuelLoad;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), engine->engineState.fuelingLoad);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_IgnLoad;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), engine->engineState.ignitionLoad);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_AuxTemp1;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), AUX_TEMP1_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_AuxTemp2;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), AUX_TEMP2_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_AccelPedal;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), ACCELERATOR_PEDAL_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_Vbatt;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), BATTERY_VOLTAGE_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_VVT_1I;
|
|
|
|
EXPECT_FLOAT_EQ(
|
|
|
|
bc.getOpenLoop(0).value_or(-1),
|
|
|
|
engine->triggerCentral.getVVTPosition(/*bankIndex*/0, /*camIndex*/0)
|
|
|
|
);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_VVT_1E;
|
|
|
|
EXPECT_FLOAT_EQ(
|
|
|
|
bc.getOpenLoop(0).value_or(-1),
|
|
|
|
engine->triggerCentral.getVVTPosition(/*bankIndex*/0, /*camIndex*/1)
|
|
|
|
);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_VVT_2I;
|
|
|
|
EXPECT_FLOAT_EQ(
|
|
|
|
bc.getOpenLoop(0).value_or(-1),
|
|
|
|
engine->triggerCentral.getVVTPosition(/*bankIndex*/1, /*camIndex*/0)
|
|
|
|
);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_VVT_2E;
|
|
|
|
EXPECT_FLOAT_EQ(
|
|
|
|
bc.getOpenLoop(0).value_or(-1),
|
|
|
|
engine->triggerCentral.getVVTPosition(/*bankIndex*/1, /*camIndex*/1)
|
|
|
|
);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_EthanolPercent;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), FUEL_ETANOL_PERCENT_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_AuxLinear1;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), AUX_LINEAR1_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_AuxLinear2;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), AUX_LINEAR2_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_GppwmOutput1;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), (float)engine->outputChannels.gppwmOutput[0]);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_GppwmOutput2;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), (float)engine->outputChannels.gppwmOutput[1]);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_GppwmOutput3;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), (float)engine->outputChannels.gppwmOutput[2]);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_GppwmOutput4;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), (float)engine->outputChannels.gppwmOutput[3]);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_DetectedGear;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), DETECTED_GEAR_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_BaroPressure;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), BAROMETRIC_PRESSURE_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_Egt1;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), EGT1_TEST_VALUE);
|
|
|
|
|
|
|
|
engineConfiguration->boostOpenLoopYAxis = GPPWM_Egt2;
|
|
|
|
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), EGT2_TEST_VALUE);
|
|
|
|
}
|
|
|
|
|
2022-01-20 19:22:52 -08:00
|
|
|
TEST(BoostControl, TestClosedLoop) {
|
2023-05-31 22:31:28 -07:00
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
2020-05-06 05:40:42 -07:00
|
|
|
|
|
|
|
BoostController bc;
|
|
|
|
|
|
|
|
pid_s pidCfg = {
|
|
|
|
1, 0, 0, // P controller, easier to test
|
|
|
|
0, // no offset
|
|
|
|
5, // 5ms period
|
|
|
|
-100, 100 // min/max output
|
|
|
|
};
|
|
|
|
|
2024-07-31 05:10:09 -07:00
|
|
|
bc.init(
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
testBoostCltCorr,
|
|
|
|
testBoostIatCorr,
|
|
|
|
testBoostCltAdder,
|
|
|
|
testBoostIatAdder,
|
|
|
|
&pidCfg
|
|
|
|
);
|
2020-05-06 05:40:42 -07:00
|
|
|
|
|
|
|
// Enable closed loop
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->boostType = CLOSED_LOOP;
|
2021-08-27 14:54:08 -07:00
|
|
|
// Minimum 75kpa
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->minimumBoostClosedLoopMap = 75;
|
2020-05-06 05:40:42 -07:00
|
|
|
|
|
|
|
// At 0 RPM, closed loop is disabled
|
2022-01-20 19:22:52 -08:00
|
|
|
Sensor::setMockValue(SensorType::Rpm, 0);
|
2020-05-06 05:40:42 -07:00
|
|
|
EXPECT_EQ(0, bc.getClosedLoop(150, 100).value_or(-1000));
|
2021-08-27 14:54:08 -07:00
|
|
|
|
|
|
|
// too low MAP, disable closed loop
|
2022-01-20 19:22:52 -08:00
|
|
|
Sensor::setMockValue(SensorType::Rpm, 0);
|
2021-08-27 14:54:08 -07:00
|
|
|
EXPECT_EQ(0, bc.getClosedLoop(150, 50).value_or(-1000));
|
2020-05-06 05:40:42 -07:00
|
|
|
|
|
|
|
// With RPM, we should get an output
|
2022-01-20 19:22:52 -08:00
|
|
|
Sensor::setMockValue(SensorType::Rpm, 1000);
|
2020-05-06 05:40:42 -07:00
|
|
|
// Actual is below target -> positive output
|
|
|
|
EXPECT_FLOAT_EQ(50, bc.getClosedLoop(150, 100).value_or(-1000));
|
|
|
|
// Actual is above target -> negative output
|
|
|
|
EXPECT_FLOAT_EQ(-25.0f, bc.getClosedLoop(150, 175).value_or(-1000));
|
|
|
|
|
|
|
|
// Disabling closed loop should return 0
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->boostType = OPEN_LOOP;
|
2020-05-06 05:40:42 -07:00
|
|
|
EXPECT_FLOAT_EQ(0, bc.getClosedLoop(150, 175).value_or(-1000));
|
|
|
|
}
|
|
|
|
|
2024-11-10 20:12:51 -08:00
|
|
|
|
|
|
|
TEST(BoostControl, TestClosedLoopUint8Overflow) {
|
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
|
|
|
|
|
|
|
BoostController bc;
|
|
|
|
|
|
|
|
pid_s pidCfg = {
|
|
|
|
1, 0, 0, // P controller, easier to test
|
|
|
|
0, // no offset
|
|
|
|
5, // 5ms period
|
|
|
|
-100, 100 // min/max output
|
|
|
|
};
|
|
|
|
|
|
|
|
bc.init(
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
testBoostCltCorr,
|
|
|
|
testBoostIatCorr,
|
|
|
|
testBoostCltAdder,
|
|
|
|
testBoostIatAdder,
|
|
|
|
&pidCfg
|
|
|
|
);
|
|
|
|
|
|
|
|
// Enable closed loop
|
|
|
|
engineConfiguration->boostType = CLOSED_LOOP;
|
|
|
|
// Minimum 260kpa
|
|
|
|
engineConfiguration->minimumBoostClosedLoopMap = 260;
|
|
|
|
|
|
|
|
// At 0 RPM, closed loop is disabled
|
|
|
|
Sensor::setMockValue(SensorType::Rpm, 0);
|
|
|
|
EXPECT_EQ(0, bc.getClosedLoop(350, 100).value_or(-1000));
|
|
|
|
|
|
|
|
// too low MAP, disable closed loop
|
|
|
|
Sensor::setMockValue(SensorType::Rpm, 0);
|
|
|
|
EXPECT_EQ(0, bc.getClosedLoop(350, 50).value_or(-1000));
|
|
|
|
|
|
|
|
// With RPM, we should get an output
|
|
|
|
Sensor::setMockValue(SensorType::Rpm, 1000);
|
|
|
|
|
|
|
|
// Actual is above target -> negative output
|
|
|
|
EXPECT_FLOAT_EQ(-53.0f, bc.getClosedLoop(650, 575).value_or(-1000));
|
|
|
|
|
|
|
|
// Disabling closed loop should return 0
|
|
|
|
engineConfiguration->boostType = OPEN_LOOP;
|
|
|
|
EXPECT_FLOAT_EQ(0, bc.getClosedLoop(350, 375).value_or(-1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-06 05:40:42 -07:00
|
|
|
TEST(BoostControl, SetOutput) {
|
2023-05-31 22:31:28 -07:00
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
2020-10-18 18:57:04 -07:00
|
|
|
|
2022-01-11 17:47:50 -08:00
|
|
|
engineConfiguration->isBoostControlEnabled = true;
|
|
|
|
|
2020-05-06 05:40:42 -07:00
|
|
|
StrictMock<MockPwm> pwm;
|
2020-10-18 18:57:04 -07:00
|
|
|
StrictMock<MockEtb> etb;
|
2020-05-06 05:40:42 -07:00
|
|
|
BoostController bc;
|
|
|
|
|
2020-10-18 18:57:04 -07:00
|
|
|
// ETB wastegate position & PWM should both be set
|
2020-11-25 18:14:06 -08:00
|
|
|
EXPECT_CALL(etb, setWastegatePosition(25.0f));
|
2020-05-06 05:40:42 -07:00
|
|
|
EXPECT_CALL(pwm, setSimplePwmDutyCycle(0.25f));
|
|
|
|
|
|
|
|
// Don't crash if not init'd (don't deref null ptr m_pwm)
|
|
|
|
EXPECT_NO_THROW(bc.setOutput(25.0f));
|
|
|
|
|
2020-10-18 18:57:04 -07:00
|
|
|
// Init with mock PWM device and ETB
|
2024-07-31 05:10:09 -07:00
|
|
|
bc.init(&pwm, nullptr, nullptr, testBoostCltCorr, testBoostIatCorr, testBoostCltAdder, testBoostIatAdder, nullptr);
|
2020-10-18 18:57:04 -07:00
|
|
|
engine->etbControllers[0] = &etb;
|
2020-05-06 05:40:42 -07:00
|
|
|
|
|
|
|
bc.setOutput(25.0f);
|
|
|
|
}
|