Skip to content

Commit 9c251f3

Browse files
Split pedal faults (#349)
Co-authored-by: Caio <caiodasilva05@outlook.com>
1 parent 0ba31fe commit 9c251f3

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

Core/Inc/fault.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
typedef enum {
88
/* START CRIT FAULTS HERE */
9-
10-
ONBOARD_PEDAL_FAULT,
9+
ONBOARD_PEDAL_OPEN_CIRCUIT_FAULT,
10+
ONBOARD_PEDAL_SHORT_CIRCUIT_FAULT,
11+
ONBOARD_PEDAL_DIFFERENCE_FAULT,
1112
CAN_DISPATCH_FAULT,
1213
CAN_ROUTING_FAULT,
1314
BMS_CAN_MONITOR_FAULT,

Core/Src/pedals.c

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,42 @@ bool get_launch_control()
193193
}
194194

195195
/**
196-
* @brief Callback for pedal fault debouncing.
196+
* @brief Callback for pedal open circuit fault debouncing.
197197
*
198198
* @param arg The fault message as a char*.
199199
*/
200-
void pedal_fault_cb(void *arg)
200+
void pedal_open_circuit_fault_cb(void *arg)
201201
{
202202
fault_data_t fault_data = {
203-
.fault_id = ONBOARD_PEDAL_FAULT,
203+
.fault_id = ONBOARD_PEDAL_OPEN_CIRCUIT_FAULT,
204+
};
205+
fault_data.diag = (char *)arg;
206+
queue_fault(&fault_data);
207+
}
208+
209+
/**
210+
* @brief Callback for pedal short circuit fault debouncing.
211+
*
212+
* @param arg The fault message as a char*.
213+
*/
214+
void pedal_short_circuit_fault_cb(void *arg)
215+
{
216+
fault_data_t fault_data = {
217+
.fault_id = ONBOARD_PEDAL_SHORT_CIRCUIT_FAULT,
218+
};
219+
fault_data.diag = (char *)arg;
220+
queue_fault(&fault_data);
221+
}
222+
223+
/**
224+
* @brief Callback for pedal difference fault debouncing.
225+
*
226+
* @param arg The fault message as a char*.
227+
*/
228+
void pedal_difference_fault_cb(void *arg)
229+
{
230+
fault_data_t fault_data = {
231+
.fault_id = ONBOARD_PEDAL_DIFFERENCE_FAULT,
204232
};
205233
fault_data.diag = (char *)arg;
206234
queue_fault(&fault_data);
@@ -231,14 +259,14 @@ bool calc_pedal_faults(float accel1, float accel2, float accel1_norm,
231259
bool open_circuit = accel1 > MAX_VOLTS_UNSCALED - APPS_THRESHOLD_BUF ||
232260
accel2 > MAX_VOLTS_UNSCALED - APPS_THRESHOLD_BUF;
233261
debounce(open_circuit, &oc_fault_timer, PEDAL_FAULT_TIME,
234-
&pedal_fault_cb,
262+
&pedal_open_circuit_fault_cb,
235263
"Pedal open circuit fault - max acceleration value");
236264

237265
/* Pedal short circuit to gnd */
238266
bool short_circuit = accel1 < MIN_APPS1_VOLTS - APPS_THRESHOLD_BUF ||
239267
accel2 < MIN_APPS2_VOLTS - APPS_THRESHOLD_BUF;
240268
debounce(short_circuit, &sc_fault_timer, PEDAL_FAULT_TIME,
241-
&pedal_fault_cb,
269+
&pedal_short_circuit_fault_cb,
242270
"Pedal grounded circuit fault - no acceleration value");
243271

244272
/* Pedal difference fault evaluation */
@@ -250,7 +278,7 @@ bool calc_pedal_faults(float accel1, float accel2, float accel1_norm,
250278
PEDAL_DIFF_THRESH;
251279

252280
debounce(pedals_too_diff, &diff_fault_timer, PEDAL_FAULT_TIME,
253-
&pedal_fault_cb,
281+
&pedal_difference_fault_cb,
254282
"Pedal short fault - pedal values are too different");
255283

256284
if (open_circuit || short_circuit || pedals_too_diff) {
@@ -281,14 +309,15 @@ bool calc_brake_faults(float brake1, float brake2)
281309
brake1 > BRAKE_SENSOR_IRREGULAR_HIGH + BRAKE_THRESHOLD_BUF ||
282310
brake2 > BRAKE_SENSOR_IRREGULAR_HIGH + BRAKE_THRESHOLD_BUF;
283311
debounce(open_circuit, &oc_fault_timer, BRAKE_FAULT_TIME,
284-
&pedal_fault_cb, "Brake open circuit fault - max brake value");
312+
&pedal_open_circuit_fault_cb,
313+
"Brake open circuit fault - max brake value");
285314

286315
/* Pedal short circuit to gnd */
287316
bool short_circuit =
288317
brake1 < BRAKE_SENSOR_IRREGULAR_LOW - BRAKE_THRESHOLD_BUF ||
289318
brake2 < BRAKE_SENSOR_IRREGULAR_LOW - BRAKE_THRESHOLD_BUF;
290319
debounce(short_circuit, &sc_fault_timer, BRAKE_FAULT_TIME,
291-
&pedal_fault_cb,
320+
&pedal_short_circuit_fault_cb,
292321
"Brake grounded circuit fault - 0 brake value");
293322

294323
if (open_circuit || short_circuit) {

0 commit comments

Comments
 (0)