2020-05-05 05:01:40 -07:00
|
|
|
#include "engine_test_helper.h"
|
|
|
|
#include "fuel_math.h"
|
2020-07-25 02:00:24 -07:00
|
|
|
#include "alphan_airmass.h"
|
|
|
|
#include "maf_airmass.h"
|
|
|
|
#include "mocks.h"
|
2020-05-05 05:01:40 -07:00
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2020-07-25 02:00:24 -07:00
|
|
|
using ::testing::StrictMock;
|
|
|
|
using ::testing::FloatNear;
|
2020-09-07 07:15:42 -07:00
|
|
|
using ::testing::InSequence;
|
|
|
|
using ::testing::_;
|
2020-07-25 02:00:24 -07:00
|
|
|
|
2020-05-05 05:01:40 -07:00
|
|
|
TEST(FuelMath, getStandardAirCharge) {
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
|
|
|
|
// Miata 1839cc 4cyl
|
|
|
|
CONFIG(specs.displacement) = 1.839f;
|
|
|
|
CONFIG(specs.cylindersCount) = 4;
|
|
|
|
|
2020-07-22 13:11:07 -07:00
|
|
|
EXPECT_FLOAT_EQ(0.5535934f, getStandardAirCharge(PASS_ENGINE_PARAMETER_SIGNATURE));
|
2020-05-05 05:01:40 -07:00
|
|
|
|
|
|
|
// LS 5.3 liter v8
|
|
|
|
CONFIG(specs.displacement) = 5.327f;
|
|
|
|
CONFIG(specs.cylindersCount) = 8;
|
|
|
|
|
2020-07-22 13:11:07 -07:00
|
|
|
EXPECT_FLOAT_EQ(0.80179232f, getStandardAirCharge(PASS_ENGINE_PARAMETER_SIGNATURE));
|
2020-05-05 05:01:40 -07:00
|
|
|
|
|
|
|
// Chainsaw - single cylinder 32cc
|
|
|
|
CONFIG(specs.displacement) = 0.032f;
|
|
|
|
CONFIG(specs.cylindersCount) = 1;
|
2020-07-22 13:11:07 -07:00
|
|
|
EXPECT_FLOAT_EQ(0.038531788f, getStandardAirCharge(PASS_ENGINE_PARAMETER_SIGNATURE));
|
2020-05-05 05:01:40 -07:00
|
|
|
|
|
|
|
// Leopard 1 47.666 liter v12
|
|
|
|
CONFIG(specs.displacement) = 47.666f;
|
|
|
|
CONFIG(specs.cylindersCount) = 12;
|
|
|
|
|
2020-07-22 13:11:07 -07:00
|
|
|
EXPECT_FLOAT_EQ(4.782959f, getStandardAirCharge(PASS_ENGINE_PARAMETER_SIGNATURE));
|
2020-05-05 05:01:40 -07:00
|
|
|
}
|
2020-07-25 02:00:24 -07:00
|
|
|
|
|
|
|
TEST(AirmassModes, AlphaNNormal) {
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
// 4 cylinder 4 liter = easy math
|
|
|
|
engineConfiguration->specs.displacement = 4.0f;
|
|
|
|
engineConfiguration->specs.cylindersCount = 4;
|
|
|
|
|
|
|
|
StrictMock<MockVp3d> veTable;
|
|
|
|
|
|
|
|
EXPECT_CALL(veTable, getValue(1200, FloatNear(0.71f, EPS4D)))
|
|
|
|
.WillOnce(Return(35.0f));
|
|
|
|
|
|
|
|
AlphaNAirmass dut(veTable);
|
|
|
|
INJECT_ENGINE_REFERENCE(&dut);
|
|
|
|
|
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.71f);
|
|
|
|
|
|
|
|
// Mass of 1 liter of air * VE
|
|
|
|
float expectedAirmass = 1.2047f * 0.35f;
|
|
|
|
|
|
|
|
auto result = dut.getAirmass(1200);
|
|
|
|
EXPECT_NEAR(result.CylinderAirmass, expectedAirmass, EPS4D);
|
|
|
|
EXPECT_NEAR(result.EngineLoadPercent, 0.71f, EPS4D);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(AirmassModes, AlphaNFailedTps) {
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
|
|
|
|
// Shouldn't get called
|
|
|
|
StrictMock<MockVp3d> veTable;
|
|
|
|
|
|
|
|
AlphaNAirmass dut(veTable);
|
|
|
|
INJECT_ENGINE_REFERENCE(&dut);
|
|
|
|
|
|
|
|
// explicitly reset the sensor
|
|
|
|
Sensor::resetMockValue(SensorType::Tps1);
|
|
|
|
// Ensure that it's actually failed
|
|
|
|
ASSERT_FALSE(Sensor::get(SensorType::Tps1).Valid);
|
|
|
|
|
|
|
|
auto result = dut.getAirmass(1200);
|
|
|
|
EXPECT_EQ(result.CylinderAirmass, 0);
|
|
|
|
}
|
|
|
|
|
2020-08-10 22:11:25 -07:00
|
|
|
TEST(AirmassModes, MafNormal) {
|
2020-07-25 02:00:24 -07:00
|
|
|
WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996);
|
|
|
|
engineConfiguration->fuelAlgorithm = LM_REAL_MAF;
|
|
|
|
engineConfiguration->injector.flow = 200;
|
|
|
|
setAfrMap(config->afrTable, 13);
|
|
|
|
|
|
|
|
MockVp3d veTable;
|
|
|
|
// Ensure that the correct cell is read from the VE table
|
|
|
|
EXPECT_CALL(veTable, getValue(6000, FloatNear(70.9814f, EPS4D)))
|
|
|
|
.WillOnce(Return(75.0f));
|
|
|
|
|
|
|
|
MafAirmass dut(veTable);
|
|
|
|
INJECT_ENGINE_REFERENCE(&dut);
|
|
|
|
|
|
|
|
auto airmass = dut.getAirmassImpl(200, 6000);
|
|
|
|
|
|
|
|
// Check results
|
|
|
|
EXPECT_NEAR(0.277777f * 0.75f, airmass.CylinderAirmass, EPS4D);
|
|
|
|
EXPECT_NEAR(70.9814f, airmass.EngineLoadPercent, EPS4D);
|
|
|
|
}
|
2020-09-07 07:15:42 -07:00
|
|
|
|
|
|
|
TEST(AirmassModes, VeOverride) {
|
|
|
|
StrictMock<MockVp3d> veTable;
|
|
|
|
|
|
|
|
{
|
|
|
|
InSequence is;
|
|
|
|
|
|
|
|
// Default
|
|
|
|
EXPECT_CALL(veTable, getValue(_, 10.0f)).WillOnce(Return(0));
|
|
|
|
// TPS
|
|
|
|
EXPECT_CALL(veTable, getValue(_, 30.0f)).WillOnce(Return(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct DummyAirmassModel : public AirmassModelBase {
|
|
|
|
DummyAirmassModel(const ValueProvider3D& veTable) : AirmassModelBase(veTable) {}
|
|
|
|
|
|
|
|
AirmassResult getAirmass(int rpm) override {
|
|
|
|
// Default load value 10, will be overriden
|
|
|
|
getVe(rpm, 10.0f);
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
|
|
|
DummyAirmassModel dut(veTable);
|
|
|
|
INJECT_ENGINE_REFERENCE(&dut);
|
|
|
|
|
|
|
|
// Use default mode - will call with 10
|
|
|
|
dut.getAirmass(0);
|
|
|
|
EXPECT_FLOAT_EQ(ENGINE(engineState.currentVeLoad), 10.0f);
|
|
|
|
|
|
|
|
// Override to TPS
|
|
|
|
CONFIG(veOverrideMode) = VE_TPS;
|
|
|
|
Sensor::setMockValue(SensorType::Tps1, 30.0f);
|
|
|
|
dut.getAirmass(0);
|
|
|
|
EXPECT_FLOAT_EQ(ENGINE(engineState.currentVeLoad), 30.0f);
|
|
|
|
}
|