Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
test_integration.cpp
Go to the documentation of this file.
5#include "unity.h"
6
7#define HYDRAULIC_PRESSURE_HIGH 0xf8
8#define HYDRAULIC_PRESSURE_LOW 0x01
9#define BAMOCAR_VDC_HIGH 0x11
10#define RES_GO 0x02
11
16
24
28void to_ready() {
29 sd.digitalData.asms_on = true;
30 // sd.digitalData.watchdog_state = true;
32
33 uint8_t bamo_msg[] = {VDC_BUS, 0x00, BAMOCAR_VDC_HIGH}; // VDC_BUS fill
35
37 uint8_t hydraulic_msg[] = {HYDRAULIC_LINE, HYDRAULIC_PRESSURE_HIGH, 0x00};
38 communicator.c1Callback(hydraulic_msg);
39
40 // Iterate a few times to go to check wd
41 Metro time{1};
42 while (!time.checkWithoutReset()) {
44 }
45
46 // sd.digitalData.watchdog_state = false;
47 // Wait for wd timeout
49 while (!time2.checkWithoutReset()) {
55 // sd.digitalData.watchdogTimestamp.reset();
56 }
57}
58
64 reset();
65 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
66
67 to_ready();
68
69 TEST_ASSERT_EQUAL(false, sd.failureDetection.emergencySignal);
70
72
73 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state);
74}
75
81 reset();
82
83 bool went_ready = false;
84 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
85
86 sd.digitalData.asms_on = true;
87 // sd.digitalData.watchdog_state = true;
89
90 uint8_t bamo_msg[] = {VDC_BUS, 0x00, BAMOCAR_VDC_HIGH}; // VDC_BUS fill
92
94 uint8_t hydraulic_msg[] = {HYDRAULIC_LINE, HYDRAULIC_PRESSURE_HIGH, 0x00};
95 communicator.c1Callback(hydraulic_msg);
96
97 // // Iterate a few times to go to check wd
98 // Metro time{1};
99 // while (!time.checkWithoutReset()) {
100 // as_state.calculateState();
101 // }
102
103 // sd.digitalData.watchdog_state = false;
104 sd.digitalData.asms_on = false; // switch previously checked condition
105 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
106 // Wait for wd timeout
107
109 while (!time2.checkWithoutReset()) {
111 went_ready = true;
112
117 // sd.digitalData.watchdogTimestamp.reset(); // todo check
118 }
119
120 TEST_ASSERT_EQUAL(false, went_ready);
121 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
122}
123
128 bool reverted_to_off = false;
129 reset();
130 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
131 to_ready();
132 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state);
133
134 // Procedure to go back to AS_OFF state
135 uint8_t bamo_msg2[] = {VDC_BUS, 0x00, 0x00}; // cd voltage set to below threshold
136 communicator.bamocarCallback(bamo_msg2);
137
138 Metro time3{1};
139 while (!time3.checkWithoutReset()) {
141 if (as_state.state == AS_OFF)
142 reverted_to_off = true;
143 }
144
145 TEST_ASSERT_EQUAL(false, reverted_to_off);
146 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state);
147}
148
154 reset();
155 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
156 to_ready();
157 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state);
158
160 while (!time.checkWithoutReset()){
162 }
163
164 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state);
165
166 Metro time2{EBS_BUZZER_TIMEOUT / 2};
167 while (!time2.checkWithoutReset()){
169 }
170 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state);
171
172 Metro time3{EBS_BUZZER_TIMEOUT / 2};
173 while (!time3.checkWithoutReset()){
175 }
176 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state);
177 sd.digitalData.asms_on = false;
179 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
180}
181
187 reset();
188 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
189 to_ready();
190 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state);
191
192 Metro time{READY_TIMEOUT_MS / 2};
193 while (!time.checkWithoutReset()){
199 // sd.digitalData.watchdogTimestamp.reset();
200 }
201
202 uint8_t msg[8] = {RES_GO, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
204
205 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state);
206
207 Metro time2{READY_TIMEOUT_MS / 2};
208 while (!time2.checkWithoutReset()){
214 // sd.digitalData.watchdogTimestamp.reset();
215 }
216
219 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state);
220
221 // brake pressure has a threshold to be updated, otherwise emergency
222 Metro time3{RELEASE_EBS_TIMEOUT_MS / 2};
223 while (!time3.checkWithoutReset()){
228 // sd.digitalData.watchdogTimestamp.reset();
230 }
231
232 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state); // still within threshold, okay
233
234 Metro time4{RELEASE_EBS_TIMEOUT_MS + 10};
240 // sd.digitalData.watchdogTimestamp.reset();
242 }
243 // threshold over, still with brake pressure, emergency
246 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state);
247}
248
254 reset();
255 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
256 to_ready();
257 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state);
258
260 while (!time.checkWithoutReset()){
266 // sd.digitalData.watchdogTimestamp.reset();
267 }
268
269 uint8_t msg[8] = {RES_GO, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
272
273 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state);
274
275 uint8_t hydraulic_msg[] = {HYDRAULIC_LINE, HYDRAULIC_PRESSURE_LOW, 0x00}; // loose brake activation
276 communicator.c1Callback(hydraulic_msg);
278 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state);
279
282 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state);
283}
284
290 reset();
291 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
292 to_ready();
293 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state);
294 sd.r2dLogics.r2d = true;
296 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state);
297
298 uint8_t pc_msg[] = {MISSION_FINISHED};
299 communicator.pcCallback(pc_msg);
300
301 uint8_t c1_msg[] = {RIGHT_WHEEL_CODE, 0x00, 0x01, 0x00, 0x00}; // value not 0
302 communicator.c1Callback(c1_msg); // right wheel = msg
304
306 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state);
307
308 uint8_t c1_msg2[] = {RIGHT_WHEEL_CODE, 0x00, 0x00, 0x00, 0x00};
309 communicator.c1Callback(c1_msg2); // right wheel = msg
310
312 TEST_ASSERT_EQUAL(State::AS_FINISHED, as_state.state);
313
314 sd.digitalData.asms_on = false;
316 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
317}
318
324 reset();
325 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
326 to_ready();
327 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state);
328 sd.r2dLogics.r2d = true;
330 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state);
333 sd.missionFinished = true;
335 TEST_ASSERT_EQUAL(State::AS_FINISHED, as_state.state);
338 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state);
339}
340
346 reset();
347 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
348 sd.digitalData.asms_on = false;
350 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
351
354 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
355
358 TEST_ASSERT_EQUAL(State::AS_MANUAL, as_state.state);
359
362 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
363}
364
369 reset();
370 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
371 uint8_t hydraulic_msg[] = {HYDRAULIC_LINE, HYDRAULIC_PRESSURE_HIGH, 0x00};
372 communicator.c1Callback(hydraulic_msg);
374
375 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
376 sd.r2dLogics.r2d = true;
377
379 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
380 to_ready(); // will validate asms is on and ts is active
382 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state);
383
385 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state); // r2d reset after transition to ready
386
387 sd.r2dLogics.r2d = true;
389 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state);
390}
391
396 reset();
397 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
398
399 sd.digitalData.asms_on = true;
400 // sd.digitalData.watchdog_state = true;
402
403 uint8_t bamo_msg[] = {VDC_BUS, 0x00, BAMOCAR_VDC_HIGH};
405
407 uint8_t hydraulic_msg[] = {HYDRAULIC_LINE, HYDRAULIC_PRESSURE_HIGH, 0x00};
408 // uint8_t hydraulic_msg2[] = {HYDRAULIC_LINE, HYDRAULIC_PRESSURE_LOW, 0x00}; // loose brake activation
409 communicator.c1Callback(hydraulic_msg);
410
411 // Iterate a few times to go to check wd
412 // Metro time{1};
413 // while (!time.checkWithoutReset()) {
414 // as_state.calculateState();
415 // }
416
417 // sd.digitalData.watchdog_state = false;
418 // Wait for wd timeout
419 // Metro time2{INITIAL_CHECKUP_STEP_TIMEOUT};
420 // while (!time2.checkWithoutReset()) {
421 // communicator.c1Callback(hydraulic_msg2);
422 // as_state.calculateState();
423 // sd.failureDetection.inversorAliveTimestamp.reset();
424 // sd.failureDetection.pcAliveTimestamp.reset();
425 // sd.failureDetection.steerAliveTimestamp.reset();
426 // sd.digitalData.watchdogTimestamp.reset();
427 // }
428 // TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
429
431 while (!time3.checkWithoutReset()) {
432 communicator.c1Callback(hydraulic_msg);
438 // sd.digitalData.watchdogTimestamp.reset();
439 }
440
441 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state);
442}
443
448 reset();
449 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
450 to_ready();
451 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state);
452 sd.r2dLogics.r2d = true;
454 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state);
455
456 sd.digitalData.sdcState_OPEN = true; // ebs before finished checks
457
459 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state);
460
461 uint8_t pc_msg[] = {MISSION_FINISHED};
462 communicator.pcCallback(pc_msg);
464 uint8_t c1_msg[] = {RIGHT_WHEEL_CODE, 0x00, 0x00, 0x00, 0x00};
465 communicator.c1Callback(c1_msg); // right wheel = msg
467 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state);
468}
469
474 reset();
475 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
476 to_ready();
477 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state);
478 sd.r2dLogics.r2d = true;
480 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state);
481
482 uint8_t pc_msg[] = {MISSION_FINISHED};
483 communicator.pcCallback(pc_msg);
485 uint8_t c1_msg[] = {RIGHT_WHEEL_CODE, 0x00, 0x00, 0x00, 0x00};
486 communicator.c1Callback(c1_msg); // right wheel = msg
488 TEST_ASSERT_EQUAL(State::AS_FINISHED, as_state.state);
489
492 TEST_ASSERT_EQUAL(State::AS_FINISHED, as_state.state);
493
496 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state);
497}
498
499void setUp() {
500
501}
502
503int main() {
504 UNITY_BEGIN();
510 RUN_TEST(test_ready_to_emg_to_off);
512 RUN_TEST(test_finished_to_emg);
514 RUN_TEST(test_flow_driving);
515 RUN_TEST(test_flow_ready);
516 RUN_TEST(test_flow_emergency);
517 RUN_TEST(test_flow_finished);
518 return UNITY_END();
519}
The ASState class manages and transitions between different states of the vehicle system.
void calculateState()
Calculates the state of the vehicle.
CheckupManager _checkupManager
CheckupManager object for handling various checkup operations.
State state
Current state of the vehicle system, initialized to OFF.
CheckupState checkupState
Current state of the checkup process.
Class that contains definitions of typical messages to send via CAN It serves only as an example of t...
static void c1Callback(const uint8_t *buf)
Callback for data from C1 Teensy.
static void resStateCallback(const uint8_t *buf)
Callback RES default callback.
static void pcCallback(const uint8_t *buf)
Callback for message from AS CU.
static void bamocarCallback(const uint8_t *buf)
Callback from inversor, for alive signal and data.
Class responsible for controlling digital outputs in the Master Teensy.
Our own implementation of Metro class.
Definition metro.h:13
void reset()
Resets the timer to the current time.
Definition metro.h:125
bool checkWithoutReset() const
Checks if the interval has passed without resetting the timer.
Definition metro.h:116
constexpr auto RIGHT_WHEEL_CODE
constexpr auto MISSION_FINISHED
constexpr auto HYDRAULIC_LINE
constexpr auto VDC_BUS
#define COMPONENT_TIMESTAMP_TIMEOUT
#define EBS_BUZZER_TIMEOUT
#define INITIAL_CHECKUP_STEP_TIMEOUT
bool pneumatic_line_pressure
Metro releaseEbsTimestamp
double _right_wheel_rpm
Definition sensors.hpp:7
double _left_wheel_rpm
Definition sensors.hpp:8
The whole model of the system: holds all the data necessary.
Sensors sensors
DigitalData digitalData
Mission mission
bool missionFinished
FailureDetection failureDetection
R2DLogics r2dLogics
@ AS_DRIVING
Definition structure.hpp:12
@ AS_READY
Definition structure.hpp:11
@ AS_MANUAL
Definition structure.hpp:9
@ AS_FINISHED
Definition structure.hpp:13
@ AS_EMERGENCY
Definition structure.hpp:14
@ AS_OFF
Definition structure.hpp:10
@ MANUAL
Definition structure.hpp:18
constexpr unsigned long READY_TIMEOUT_MS
constexpr unsigned long RELEASE_EBS_TIMEOUT_MS
CAN_message_t msg
void test_off_to_ready_wayback_impossible()
Test function to validate AS_READY doesn't revert to AS_Ready.
void test_driving_to_finished_to_off()
Test function to validate AS_DRIVING to AS_FINISHED transition and AS_FINISHED to AS_OFF after.
void test_flow_finished()
Test function to validate flow diagram conditions to go AS_FINISHED.
Communicator communicator
void test_ready_to_emg_to_off()
Test function to validate AS_READY to AS_Emergency and the AS_EMERGENCY to AS_OFF transition.
#define RES_GO
ASState as_state
void test_off_to_ready_success(void)
Test function to validate AS_OFF to AS_Ready transition normal and successful transition.
void test_finished_to_emg()
Test function to validate AS_FINISHED to AS_EMERGENCY transition if RES is activated after mission fi...
void test_flow_emergency()
Test function to validate flow diagram conditions to go AS_EMERGENCY.
void setUp()
void test_ready_to_driving_to_emg2()
Test function to validate AS_READY to AS_Driving transition and AS_DRIVING to AS_EMERGENCY if failure...
DigitalSender digitalSender
#define HYDRAULIC_PRESSURE_HIGH
#define BAMOCAR_VDC_HIGH
void to_ready()
Auxiliary function to set state as ready.
void test_flow_ready()
Test function to validate flow diagram conditions to go AS_READY.
#define HYDRAULIC_PRESSURE_LOW
void reset()
Auxiliary function to reset data values.
SystemData sd
void test_off_to_manual_wayback()
Test function to validate AS_OFF to AS_Manual transition and the other way around.
void test_off_to_ready_recheck()
Test function to validate AS_OFF to AS_Ready transition with checks reverting to invalid mid transiti...
int main()
void test_flow_driving()
Test function to validate flow diagram conditions to go AS_DRIVING.
void test_ready_to_driving_to_emg()
Test function to validate AS_READY to AS_Driving transition and AS_DRIVING to AS_EMERGENCY if brakes ...