forked from rusefi/rusefi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_launch.cpp
More file actions
250 lines (167 loc) · 7.75 KB
/
Copy pathtest_launch.cpp
File metadata and controls
250 lines (167 loc) · 7.75 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#include "pch.h"
#include "launch_control.h"
TEST(LaunchControl, TpsCondition) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
LaunchControlBase dut;
engineConfiguration->launchTpsThreshold = 10;
// Should return false with failed sensor
Sensor::resetMockValue(SensorType::DriverThrottleIntent);
EXPECT_FALSE(dut.isInsideTpsCondition());
// Should return false when throttle is closed
Sensor::setMockValue(SensorType::DriverThrottleIntent, 5.0f);
EXPECT_FALSE(dut.isInsideTpsCondition());
// Should return true when throttle is opened past the threshold
Sensor::setMockValue(SensorType::DriverThrottleIntent, 20.0f);
EXPECT_TRUE(dut.isInsideTpsCondition());
}
TEST(LaunchControl, VSSCondition) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
LaunchControlBase dut;
// Test Speed threshold
engineConfiguration->launchActivationMode = ALWAYS_ACTIVE_LAUNCH;
engineConfiguration->launchSpeedThreshold = 30;
Sensor::setMockValue(SensorType::VehicleSpeed, 10.0);
EXPECT_TRUE(dut.isInsideSpeedCondition());
Sensor::setMockValue(SensorType::VehicleSpeed, 40.0);
EXPECT_FALSE(dut.isInsideSpeedCondition());
}
TEST(LaunchControl, ZeroVSSCondition) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
LaunchControlBase dut;
// Test Speed threshold
engineConfiguration->launchActivationMode = ALWAYS_ACTIVE_LAUNCH;
engineConfiguration->launchSpeedThreshold = 0;
Sensor::setMockValue(SensorType::VehicleSpeed, 10.0);
EXPECT_TRUE(dut.isInsideSpeedCondition());
}
TEST(LaunchControl, VSSConditionWithSwitch) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
LaunchControlBase dut;
// Test Speed threshold
engineConfiguration->launchActivationMode = SWITCH_INPUT_LAUNCH;
engineConfiguration->launchActivatePin = Gpio::G1;
setMockState(engineConfiguration->launchActivatePin, true);
engineConfiguration->launchSpeedThreshold = 30;
Sensor::setMockValue(SensorType::VehicleSpeed, 10.0);
EXPECT_TRUE(dut.isInsideSpeedCondition());
Sensor::setMockValue(SensorType::VehicleSpeed, 40.0);
EXPECT_FALSE(dut.isInsideSpeedCondition());
}
TEST(LaunchControl, RPMCondition) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
LaunchControlBase dut;
engineConfiguration->launchRpm = 3000;
EXPECT_EQ(engineConfiguration->launchRpmWindow, 500);
EXPECT_EQ(dut.calculateRPMLaunchCondition(2499), LaunchCondition::NotMet);
EXPECT_EQ(dut.calculateRPMLaunchCondition(2500), LaunchCondition::PreLaunch);
EXPECT_EQ(dut.calculateRPMLaunchCondition(2900), LaunchCondition::PreLaunch);
EXPECT_EQ(dut.calculateRPMLaunchCondition(2999), LaunchCondition::PreLaunch);
EXPECT_EQ(dut.calculateRPMLaunchCondition(3000), LaunchCondition::Launch);
EXPECT_EQ(dut.calculateRPMLaunchCondition(3100), LaunchCondition::Launch);
}
TEST(LaunchControl, SwitchInputCondition) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
LaunchControlBase dut;
//activation based on VSS
engineConfiguration->launchActivationMode = ALWAYS_ACTIVE_LAUNCH;
EXPECT_TRUE(dut.isInsideSwitchCondition());
//active by switch
engineConfiguration->launchActivationMode = SWITCH_INPUT_LAUNCH;
engineConfiguration->launchActivatePin = Gpio::G1;
setMockState(engineConfiguration->launchActivatePin, true);
EXPECT_TRUE(dut.isInsideSwitchCondition());
setMockState(engineConfiguration->launchActivatePin, false);
EXPECT_FALSE(dut.isInsideSwitchCondition());
//by clutch
engineConfiguration->launchActivationMode = CLUTCH_INPUT_LAUNCH;
engineConfiguration->clutchDownPin = Gpio::G2;
engineConfiguration->clutchDownPinMode = PI_PULLUP;
setMockState(engineConfiguration->clutchDownPin, true);
engine->updateSwitchInputs();
EXPECT_TRUE(dut.isInsideSwitchCondition());
setMockState(engineConfiguration->clutchDownPin, false);
engine->updateSwitchInputs();
EXPECT_FALSE(dut.isInsideSwitchCondition());
engineConfiguration->clutchDownPinMode = PI_INVERTED_PULLDOWN;
setMockState(engineConfiguration->clutchDownPin, false);
engine->updateSwitchInputs();
EXPECT_TRUE(dut.isInsideSwitchCondition());
setMockState(engineConfiguration->clutchDownPin, true);
engine->updateSwitchInputs();
EXPECT_FALSE(dut.isInsideSwitchCondition());
}
TEST(LaunchControl, CombinedCondition) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
LaunchControlBase dut;
//check VSS normal usage
engineConfiguration->launchActivationMode = ALWAYS_ACTIVE_LAUNCH;
engineConfiguration->launchRpm = 3000;
engineConfiguration->launchTpsThreshold = 10;
//valid TPS
Sensor::setMockValue(SensorType::DriverThrottleIntent, 20.0f);
Sensor::setMockValue(SensorType::VehicleSpeed, 10.0);
Sensor::setMockValue(SensorType::Rpm, 1200);
EXPECT_EQ(dut.calculateLaunchCondition(1200), LaunchCondition::NotMet);
Sensor::setMockValue(SensorType::Rpm, 3200);
EXPECT_EQ(dut.calculateLaunchCondition(3200), LaunchCondition::Launch);
Sensor::setMockValue(SensorType::VehicleSpeed, 40.0);
EXPECT_EQ(dut.calculateLaunchCondition(3200), LaunchCondition::NotMet);
}
static void setDefaultLaunchParameters() {
engineConfiguration->launchRpm = 4000; // Rpm to trigger Launch condition
// engineConfiguration->launchTimingRetard = 10; // retard in absolute degrees ATDC
engineConfiguration->launchRpmWindow = 500; // RPM window (Launch RPM - Window) for transitioning to full retard
engineConfiguration->launchSparkCutEnable = true;
engineConfiguration->launchFuelCutEnable = false;
engineConfiguration->launchSpeedThreshold = 10; //maximum speed allowed before disable launch
engineConfiguration->launchFuelAdderPercent = 10; // Extra fuel in % when launch are triggered
// engineConfiguration->launchBoostDuty = 70; // boost valve duty cycle at launch
// engineConfiguration->enableLaunchRetard = true;
engineConfiguration->launchSmoothRetard = true; //interpolates the advance linear from launchrpm to fully retarded at launchtimingrpmrange
}
TEST(LaunchControl, CompleteRun) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
//load default config
setDefaultLaunchParameters();
//check VSS normal usage
engineConfiguration->launchActivationMode = ALWAYS_ACTIVE_LAUNCH;
engineConfiguration->launchSpeedThreshold = 30;
engineConfiguration->launchRpm = 3000;
engineConfiguration->launchTpsThreshold = 10;
engineConfiguration->launchControlEnabled = true;
//valid TPS
Sensor::setMockValue(SensorType::DriverThrottleIntent, 20.0f);
Sensor::setMockValue(SensorType::VehicleSpeed, 10.0);
Sensor::setMockValue(SensorType::Rpm, 1200);
engine->launchController.update();
//check if we have some sort of cut? we should not have at this point
EXPECT_FALSE(engine->launchController.isLaunchSparkRpmRetardCondition());
EXPECT_FALSE(engine->launchController.isLaunchFuelRpmRetardCondition());
Sensor::setMockValue(SensorType::Rpm, 3510);
//update condition check
engine->launchController.update();
eth.moveTimeForwardAndInvokeEventsSec(3);
engine->launchController.update();
EXPECT_TRUE(engine->launchController.isLaunchSparkRpmRetardCondition());
EXPECT_FALSE(engine->launchController.isLaunchFuelRpmRetardCondition());
Sensor::setMockValue(SensorType::VehicleSpeed, 40.0);
engine->launchController.update();
EXPECT_FALSE(engine->launchController.isLaunchSparkRpmRetardCondition());
EXPECT_FALSE(engine->launchController.isLaunchFuelRpmRetardCondition());
}
TEST(LaunchControl, hardSkip) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
SoftSparkLimiter hardSparkLimiter(true);
ASSERT_FALSE(hardSparkLimiter.shouldSkip());
hardSparkLimiter.updateTargetSkipRatio(1.0f, 0.0f);
// open question if we need special handling of '1' or random would just work?
ASSERT_TRUE(hardSparkLimiter.shouldSkip());
int counter = 0;
hardSparkLimiter.updateTargetSkipRatio(0.5f, 0.0f);
for (int i =0;i<1000;i++) {
if (hardSparkLimiter.shouldSkip()) {
counter++;
}
}
ASSERT_TRUE(counter > 400 && counter < 600) << "How good is random " << counter;
}