Line data Source code
1 : /*
2 : * @file test_fuelCut.cpp
3 : *
4 : * @date Mar 22, 2018
5 : * @author Andrey Belomutskiy, (c) 2012-2020
6 : */
7 :
8 : #include "pch.h"
9 :
10 : #include "event_queue.h"
11 :
12 : using ::testing::_;
13 :
14 : // Define some helpers for not-cut and cut
15 : #define EXPECT_NORMAL() EXPECT_FLOAT_EQ(normalInjDuration, engine->engineState.injectionDuration)
16 : #define EXPECT_CUT() EXPECT_FLOAT_EQ(0, engine->engineState.injectionDuration)
17 :
18 4 : TEST(fuelCut, coasting) {
19 1 : EngineTestHelper eth(engine_type_e::TEST_ENGINE);
20 3 : EXPECT_CALL(*eth.mockAirmass, getAirmass(_, _))
21 3 : .WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
22 :
23 : // configure coastingFuelCut
24 1 : engineConfiguration->coastingFuelCutEnabled = true;
25 1 : engineConfiguration->coastingFuelCutRpmLow = 1300;
26 1 : engineConfiguration->coastingFuelCutRpmHigh = 1500;
27 1 : engineConfiguration->coastingFuelCutTps = 2;
28 1 : engineConfiguration->coastingFuelCutClt = 30;
29 1 : engineConfiguration->coastingFuelCutMap = 100;
30 : // set cranking threshold
31 1 : engineConfiguration->cranking.rpm = 999;
32 :
33 : // basic engine setup
34 1 : setupSimpleTestEngineWithMafAndTT_ONE_trigger(ð);
35 :
36 1 : Sensor::setMockValue(SensorType::Map, 0);
37 :
38 : // mock CLT - just above threshold ('hot engine')
39 1 : float hotClt = engineConfiguration->coastingFuelCutClt + 1;
40 1 : Sensor::setMockValue(SensorType::Clt, hotClt);
41 : // mock TPS - throttle is opened
42 1 : Sensor::setMockValue(SensorType::DriverThrottleIntent, 60);
43 : // set 'running' RPM - just above RpmHigh threshold
44 1 : Sensor::setMockValue(SensorType::Rpm, engineConfiguration->coastingFuelCutRpmHigh + 1);
45 : // 'advance' time (amount doesn't matter)
46 1 : eth.moveTimeForwardUs(1000);
47 :
48 1 : const float normalInjDuration = 1.5f;
49 : /*
50 : * We need to pass through all rpm changes (high-mid-low-mid-high) because of state-machine
51 : */
52 :
53 : // process
54 1 : eth.engine.periodicFastCallback();
55 :
56 : // this is normal injection mode (the throttle is opened), no fuel cut-off
57 1 : EXPECT_NORMAL();
58 :
59 : // 'releasing' the throttle
60 1 : Sensor::setMockValue(SensorType::DriverThrottleIntent, 0);
61 1 : eth.engine.periodicFastCallback();
62 :
63 : // Fuel cut-off is enabled now
64 1 : EXPECT_CUT();
65 :
66 : // Now drop the CLT below threshold
67 1 : Sensor::setMockValue(SensorType::Clt, engineConfiguration->coastingFuelCutClt - 1);
68 1 : eth.engine.periodicFastCallback();
69 :
70 : // Fuel cut-off should be diactivated - the engine is 'cold'
71 1 : EXPECT_NORMAL();
72 :
73 : // restore CLT
74 1 : Sensor::setMockValue(SensorType::Clt, hotClt);
75 : // And set RPM - somewhere between RpmHigh and RpmLow threshold
76 1 : Sensor::setMockValue(SensorType::Rpm, (engineConfiguration->coastingFuelCutRpmHigh + engineConfiguration->coastingFuelCutRpmLow) / 2);
77 1 : eth.engine.periodicFastCallback();
78 :
79 : // Fuel cut-off is enabled - nothing should change
80 1 : EXPECT_NORMAL();
81 :
82 : // Now drop RPM just below RpmLow threshold
83 1 : Sensor::setMockValue(SensorType::Rpm, engineConfiguration->coastingFuelCutRpmLow - 1);
84 1 : eth.engine.periodicFastCallback();
85 :
86 : // Fuel cut-off is now disabled (the engine is idling)
87 1 : EXPECT_NORMAL();
88 :
89 : // Now change RPM just below RpmHigh threshold
90 1 : Sensor::setMockValue(SensorType::Rpm, engineConfiguration->coastingFuelCutRpmHigh - 1);
91 1 : eth.engine.periodicFastCallback();
92 :
93 : // Fuel cut-off is still disabled
94 1 : EXPECT_NORMAL();
95 :
96 : // Now set RPM just above RpmHigh threshold
97 1 : Sensor::setMockValue(SensorType::Rpm, engineConfiguration->coastingFuelCutRpmHigh + 1);
98 1 : eth.engine.periodicFastCallback();
99 :
100 : // Fuel cut-off is active again!
101 1 : EXPECT_CUT();
102 :
103 : // Configure vehicle speed thresholds
104 1 : engineConfiguration->coastingFuelCutVssHigh = 50;
105 1 : engineConfiguration->coastingFuelCutVssLow = 40;
106 :
107 : // High speed, should still be cut.
108 1 : Sensor::setMockValue(SensorType::VehicleSpeed, 55);
109 1 : eth.engine.periodicFastCallback();
110 1 : EXPECT_CUT();
111 :
112 : // Between thresholds, still cut.
113 1 : Sensor::setMockValue(SensorType::VehicleSpeed, 45);
114 1 : eth.engine.periodicFastCallback();
115 1 : EXPECT_CUT();
116 :
117 : // Below lower threshold, normal fuel resumes
118 1 : Sensor::setMockValue(SensorType::VehicleSpeed, 35);
119 1 : eth.engine.periodicFastCallback();
120 1 : EXPECT_NORMAL();
121 :
122 : // Between thresholds, still normal.
123 1 : Sensor::setMockValue(SensorType::VehicleSpeed, 45);
124 1 : eth.engine.periodicFastCallback();
125 1 : EXPECT_NORMAL();
126 :
127 : // Back above upper, cut again.
128 1 : Sensor::setMockValue(SensorType::VehicleSpeed, 55);
129 1 : eth.engine.periodicFastCallback();
130 1 : EXPECT_CUT();
131 2 : }
132 :
133 4 : TEST(fuelCut, delay) {
134 1 : EngineTestHelper eth(engine_type_e::TEST_ENGINE);
135 3 : EXPECT_CALL(*eth.mockAirmass, getAirmass(_, _))
136 3 : .WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
137 :
138 : // configure coastingFuelCut
139 1 : engineConfiguration->coastingFuelCutEnabled = true;
140 1 : engineConfiguration->coastingFuelCutRpmLow = 1300;
141 1 : engineConfiguration->coastingFuelCutRpmHigh = 1500;
142 1 : engineConfiguration->coastingFuelCutTps = 2;
143 1 : engineConfiguration->coastingFuelCutClt = 30;
144 1 : engineConfiguration->coastingFuelCutMap = 100;
145 : // set cranking threshold
146 1 : engineConfiguration->cranking.rpm = 999;
147 :
148 : // delay is 1 second
149 1 : engineConfiguration->dfcoDelay = 1.0f;
150 :
151 : // basic engine setup
152 1 : setupSimpleTestEngineWithMafAndTT_ONE_trigger(ð);
153 :
154 1 : Sensor::setMockValue(SensorType::Map, 0);
155 :
156 : // mock CLT - just above threshold ('hot engine')
157 1 : float hotClt = engineConfiguration->coastingFuelCutClt + 1;
158 1 : Sensor::setMockValue(SensorType::Clt, hotClt);
159 : // mock TPS - throttle is opened
160 1 : Sensor::setMockValue(SensorType::DriverThrottleIntent, 60);
161 : // set 'running' RPM - just above RpmHigh threshold
162 1 : Sensor::setMockValue(SensorType::Rpm, engineConfiguration->coastingFuelCutRpmHigh + 1);
163 : // 'advance' time (amount doesn't matter)
164 1 : eth.moveTimeForwardUs(1000);
165 :
166 1 : const float normalInjDuration = 1.5f;
167 :
168 1 : setTimeNowUs(1e6);
169 :
170 : // process
171 1 : eth.engine.periodicFastCallback();
172 :
173 : // this is normal injection mode (the throttle is opened), no fuel cut-off
174 1 : EXPECT_NORMAL();
175 :
176 : // 'releasing' the throttle
177 1 : Sensor::setMockValue(SensorType::DriverThrottleIntent, 0);
178 1 : eth.engine.periodicFastCallback();
179 :
180 : // Shouldn't cut yet, since not enough time has elapsed
181 1 : EXPECT_NORMAL();
182 :
183 : // Change nothing else, but advance time and update again
184 1 : advanceTimeUs(0.9e6);
185 1 : eth.engine.periodicFastCallback();
186 :
187 : // too soon, still no cut
188 1 : EXPECT_NORMAL();
189 :
190 : // Change nothing else, but advance time and update again
191 1 : advanceTimeUs(0.2e6);
192 1 : eth.engine.periodicFastCallback();
193 :
194 : // Should now be cut!
195 1 : EXPECT_CUT();
196 :
197 : // Put the throtle back, and it should come back instantly
198 1 : Sensor::setMockValue(SensorType::DriverThrottleIntent, 30);
199 1 : eth.engine.periodicFastCallback();
200 1 : EXPECT_NORMAL();
201 2 : }
|