forked from rusefi/rusefi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_engine_math.cpp
140 lines (112 loc) · 4.4 KB
/
test_engine_math.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* @file test_engine_math.c
*
* @date Nov 14, 2013
* @author Andrey Belomutskiy, (c) 2012-2020
*/
#include "pch.h"
#include "speed_density.h"
#include "maf.h"
#include "advance_map.h"
TEST(misc, testIgnitionPlanning) {
printf("*************************************************** testIgnitionPlanning\r\n");
EngineTestHelper eth(FORD_ESCORT_GT);
eth.engine.periodicFastCallback();
assertEqualsM("testIgnitionPlanning_AFR", 13.5, eth.engine.engineState.targetAFR);
ASSERT_EQ(IM_BATCH, engineConfiguration->injectionMode);
}
TEST(misc, testEngineMath) {
printf("*************************************************** testEngineMath\r\n");
EngineTestHelper eth(FORD_ESCORT_GT);
setCamOperationMode();
engineConfiguration->fuelAlgorithm = LM_SPEED_DENSITY;
ASSERT_NEAR( 50, getOneDegreeTimeMs(600) * 180, EPS4D) << "600 RPM";
ASSERT_EQ( 5, getOneDegreeTimeMs(6000) * 180) << "6000 RPM";
Sensor::setMockValue(SensorType::Clt, 300);
Sensor::setMockValue(SensorType::Iat, 350);
ASSERT_FLOAT_EQ(312.5, getTCharge(1000, 0));
ASSERT_FLOAT_EQ(313.5833, getTCharge(1000, 50));
ASSERT_FLOAT_EQ(314.6667, getTCharge(1000, 100));
ASSERT_FLOAT_EQ(312.5, getTCharge(4000, 0));
ASSERT_FLOAT_EQ(320.0833, getTCharge(4000, 50));
ASSERT_FLOAT_EQ(327.6667, getTCharge(4000, 100));
// test Air Interpolation mode
engineConfiguration->tChargeMode = TCHARGE_MODE_AIR_INTERP;
engineConfiguration->tChargeAirCoefMin = 0.098f;
engineConfiguration->tChargeAirCoefMax = 0.902f;
engineConfiguration->tChargeAirFlowMax = 153.6f;
// calc. some airMass given the engine displacement=1.839 and 4 cylinders (FORD_ESCORT_GT)
engine->engineState.sd.airMassInOneCylinder = SpeedDensityBase::getAirmassImpl(/*VE*/1.0f, /*MAP*/100.0f, /*tChargeK*/273.15f + 20.0f);
ASSERT_NEAR(0.5464f, engine->engineState.sd.airMassInOneCylinder, EPS4D);
Sensor::setMockValue(SensorType::Clt, 90);
Sensor::setMockValue(SensorType::Iat, 20);
Sensor::setMockValue(SensorType::Map, 100);
Sensor::setMockValue(SensorType::Tps1, 0);
Sensor::setMockValue(SensorType::Rpm, 1000);
// calc. airFlow using airMass, and find tCharge
engine->periodicFastCallback();
ASSERT_NEAR(59.1175f, engine->engineState.sd.tCharge, EPS4D);
ASSERT_NEAR(56.9762f/*kg/h*/, engine->engineState.airflowEstimate, EPS4D);
}
typedef enum {
CS_OPEN = 0,
CS_CLOSED = 1,
CS_SWIRL_TUMBLE = 2,
} chamber_style_e;
/**
* @param octane gas octane number
* @param bore in mm
*/
static float getTopAdvanceForBore(chamber_style_e style, int octane, double compression, double bore) {
int octaneCorrection;
if ( octane <= 90) {
octaneCorrection = -2;
} else if (octane < 94) {
octaneCorrection = -1;
} else {
octaneCorrection = 0;
}
int compressionCorrection;
if (compression <= 9) {
compressionCorrection = 2;
} else if (compression <= 10) {
compressionCorrection = 1;
} else if (compression <= 11) {
compressionCorrection = 0;
} else {
// compression ratio above 11
compressionCorrection = -2;
}
int base;
if (style == CS_OPEN) {
base = 33;
} else if (style == CS_CLOSED) {
base = 28;
} else {
// CS_SWIRL_TUMBLE
base = 22;
}
float boreCorrection = (bore - 4 * 25.4) / 25.4 * 6;
float result = base + octaneCorrection + compressionCorrection + boreCorrection;
return ((int)(result * 10)) / 10.0;
}
TEST(misc, testIgnitionMapGenerator) {
printf("*************************************************** testIgnitionMapGenerator\r\n");
ASSERT_EQ(35, getTopAdvanceForBore(CS_OPEN, 98, 8, 101.6));
ASSERT_EQ(33, getTopAdvanceForBore(CS_OPEN, 98, 11, 101.6));
float rpmBin[16];
setRpmBin(rpmBin, 16, 800, 7000);
ASSERT_EQ(650, rpmBin[0]);
ASSERT_EQ( 800, rpmBin[1]) << "@1";
ASSERT_EQ( 1100, rpmBin[2]) << "@2";
ASSERT_EQ( 1400, rpmBin[3]) << "rpm@3";
ASSERT_EQ( 4700, rpmBin[14]) << "rpm@14";
ASSERT_EQ(7000, rpmBin[15]);
ASSERT_FLOAT_EQ(22.0, getTopAdvanceForBore(CS_SWIRL_TUMBLE, 89, 9, 101.6));
ASSERT_FLOAT_EQ(32.2, getTopAdvanceForBore(CS_SWIRL_TUMBLE, 89, 9, 145));
assertEqualsM2("100@6000", 36.0, getInitialAdvance(6000, 100, 36), 0.1);
assertEqualsM2("100@600", 9.9, getInitialAdvance(600, 100, 36), 0.2);
assertEqualsM2("2400", 34.2, getInitialAdvance(2400, 40, 36), 0.1);
assertEqualsM2("4400", 41.9, getInitialAdvance(4400, 40, 36), 0.1);
assertEqualsM2("20@800", 14.2, getInitialAdvance(800, 20, 36), 0.2);
}