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() {
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.c1_callback(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.failure_detection_.emergency_signal_);
70
72 as_state._checkup_manager_.checkupState);
73
74 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state_);
75}
76
82 reset();
83
84 bool went_ready = false;
85 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state_);
86
88 // sd.digitalData.watchdog_state = true;
90
91 uint8_t bamo_msg[] = {VDC_BUS, 0x00, BAMOCAR_VDC_HIGH}; // VDC_BUS fill
93
95 uint8_t hydraulic_msg[] = {HYDRAULIC_LINE, HYDRAULIC_PRESSURE_HIGH, 0x00};
96 communicator.c1_callback(hydraulic_msg);
97
98 // // Iterate a few times to go to check wd
99 // Metro time{1};
100 // while (!time.checkWithoutReset()) {
101 // as_state.calculate_state();
102 // }
103
104 // sd.digitalData.watchdog_state = false;
105 sd.digital_data_.asms_on_ = false; // switch previously checked condition
106 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state_);
107 // Wait for wd timeout
108
110 while (!time2.checkWithoutReset()) {
111 if (as_state.state_ == State::AS_READY) 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
137
138 Metro time3{1};
139 while (!time3.checkWithoutReset()) {
141 if (as_state.state_ == State::AS_OFF) reverted_to_off = true;
142 }
143
144 TEST_ASSERT_EQUAL(false, reverted_to_off);
145 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state_);
146}
147
153 reset();
154 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state_);
155 to_ready();
156 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state_);
157
159 while (!time.checkWithoutReset()) {
161 }
162
163 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state_);
164
165 Metro time2{EBS_BUZZER_TIMEOUT / 2};
166 while (!time2.checkWithoutReset()) {
168 }
169 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state_);
170
171 Metro time3{EBS_BUZZER_TIMEOUT / 2};
172 while (!time3.checkWithoutReset()) {
174 }
175 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state_);
176 sd.digital_data_.asms_on_ = false;
178 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state_);
179}
180
186 reset();
187 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state_);
188 to_ready();
189 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state_);
190
191 Metro time{READY_TIMEOUT_MS / 2};
192 while (!time.checkWithoutReset()) {
198 // sd.digitalData.watchdogTimestamp.reset();
199 }
200
201 uint8_t msg[8] = {RES_GO, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
203
204 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state_);
205
206 Metro time2{READY_TIMEOUT_MS / 2};
207 while (!time2.checkWithoutReset()) {
213 // sd.digitalData.watchdogTimestamp.reset();
214 }
215
218 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state_);
219
220 // brake pressure has a threshold to be updated, otherwise emergency
221 Metro time3{RELEASE_EBS_TIMEOUT_MS / 2};
222 while (!time3.checkWithoutReset()) {
227 // sd.digitalData.watchdogTimestamp.reset();
229 }
230
231 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state_); // still within threshold, okay
232
233 Metro time4{RELEASE_EBS_TIMEOUT_MS + 10};
239 // sd.digitalData.watchdogTimestamp.reset();
241 }
242 // threshold over, still with brake pressure, emergency
245 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state_);
246}
247
253 reset();
254 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state_);
255 to_ready();
256 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state_);
257
259 while (!time.checkWithoutReset()) {
265 // sd.digitalData.watchdogTimestamp.reset();
266 }
267
268 uint8_t msg[8] = {RES_GO, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
271
272 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state_);
273
274 uint8_t hydraulic_msg[] = {HYDRAULIC_LINE, HYDRAULIC_PRESSURE_LOW,
275 0x00}; // loose brake activation
276 communicator.c1_callback(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.r2d_logics_.r2d = true;
296 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state_);
297
298 uint8_t pc_msg[] = {MISSION_FINISHED};
300
301 uint8_t c1_msg[] = {RIGHT_WHEEL_CODE, 0x00, 0x01, 0x00, 0x00}; // value not 0
302 communicator.c1_callback(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.c1_callback(c1_msg2); // right wheel = msg
310
312 TEST_ASSERT_EQUAL(State::AS_FINISHED, as_state.state_);
313
314 sd.digital_data_.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.r2d_logics_.r2d = true;
330 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state_);
333 sd.mission_finished_ = 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.digital_data_.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.c1_callback(hydraulic_msg);
374
375 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state_);
376 sd.r2d_logics_.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.r2d_logics_.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
400 // sd.digitalData.watchdog_state = true;
401 sd.digital_data_.sdc_open_ = false;
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
409 // activation
410 communicator.c1_callback(hydraulic_msg);
411
412 // Iterate a few times to go to check wd
413 // Metro time{1};
414 // while (!time.checkWithoutReset()) {
415 // as_state.calculate_state();
416 // }
417
418 // sd.digitalData.watchdog_state = false;
419 // Wait for wd timeout
420 // Metro time2{INITIAL_CHECKUP_STEP_TIMEOUT};
421 // while (!time2.checkWithoutReset()) {
422 // communicator.c1_callback(hydraulic_msg2);
423 // as_state.calculate_state();
424 // sd.failure_detection_.inversor_alive_timestamp_.reset();
425 // sd.failure_detection_.pc_alive_timestamp_.reset();
426 // sd.failure_detection_.steer_alive_timestamp_.reset();
427 // sd.digitalData.watchdogTimestamp.reset();
428 // }
429 // TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state);
430
432 while (!time3.checkWithoutReset()) {
433 communicator.c1_callback(hydraulic_msg);
439 // sd.digitalData.watchdogTimestamp.reset();
440 }
441
442 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state_);
443}
444
449 reset();
450 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state_);
451 to_ready();
452 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state_);
453 sd.r2d_logics_.r2d = true;
455 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state_);
456
457 sd.digital_data_.sdc_open_ = true; // ebs before finished checks
458
460 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state_);
461
462 uint8_t pc_msg[] = {MISSION_FINISHED};
465 uint8_t c1_msg[] = {RIGHT_WHEEL_CODE, 0x00, 0x00, 0x00, 0x00};
466 communicator.c1_callback(c1_msg); // right wheel = msg
468 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state_);
469}
470
475 reset();
476 TEST_ASSERT_EQUAL(State::AS_OFF, as_state.state_);
477 to_ready();
478 TEST_ASSERT_EQUAL(State::AS_READY, as_state.state_);
479 sd.r2d_logics_.r2d = true;
481 TEST_ASSERT_EQUAL(State::AS_DRIVING, as_state.state_);
482
483 uint8_t pc_msg[] = {MISSION_FINISHED};
486 uint8_t c1_msg[] = {RIGHT_WHEEL_CODE, 0x00, 0x00, 0x00, 0x00};
487 communicator.c1_callback(c1_msg); // right wheel = msg
489 TEST_ASSERT_EQUAL(State::AS_FINISHED, as_state.state_);
490
493 TEST_ASSERT_EQUAL(State::AS_FINISHED, as_state.state_);
494
497 TEST_ASSERT_EQUAL(State::AS_EMERGENCY, as_state.state_);
498}
499
500void setUp() {}
501
502int main() {
503 UNITY_BEGIN();
509 RUN_TEST(test_ready_to_emg_to_off);
511 RUN_TEST(test_finished_to_emg);
513 RUN_TEST(test_flow_driving);
514 RUN_TEST(test_flow_ready);
515 RUN_TEST(test_flow_emergency);
516 RUN_TEST(test_flow_finished);
517 return UNITY_END();
518}
The ASState class manages and transitions between different states of the vehicle system.
void calculate_state()
Calculates the state of the vehicle.
CheckupManager _checkup_manager_
CheckupManager object for handling various checkup operations.
State state_
Current state of the vehicle system, initialized to OFF.
Class that contains definitions of typical messages to send via CAN It serves only as an example of t...
static void res_state_callback(const uint8_t *buf)
Callback RES default callback.
static void c1_callback(const uint8_t *buf)
Callback for data from C1 Teensy.
static void pc_callback(const uint8_t *buf)
Callback for message from AS CU.
static void bamocar_callback(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:124
bool checkWithoutReset() const
Checks if the interval has passed without resetting the timer.
Definition metro.h:115
constexpr auto RIGHT_WHEEL_CODE
constexpr auto MISSION_FINISHED
constexpr auto HYDRAULIC_LINE
constexpr auto VDC_BUS
constexpr unsigned long READY_TIMEOUT_MS
constexpr unsigned long RELEASE_EBS_TIMEOUT_MS
constexpr int COMPONENT_TIMESTAMP_TIMEOUT
constexpr int INITIAL_CHECKUP_STEP_TIMEOUT
constexpr int EBS_BUZZER_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.
Mission mission_
DigitalData digital_data_
R2DLogics r2d_logics_
FailureDetection failure_detection_
bool mission_finished_
Sensors sensors_
@ AS_DRIVING
@ AS_MANUAL
@ AS_READY
@ AS_FINISHED
@ AS_EMERGENCY
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 ...