Skip to content

Commit cef49e6

Browse files
committed
add check for accel pedal
1 parent 3abffd5 commit cef49e6

4 files changed

Lines changed: 28 additions & 8 deletions

File tree

Core/Inc/u_pedals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ void pedals_process(void); // Pedal Processing Function. Meant to be called by
3030
// the pedals thread.
3131
bool pedals_getBrakeState(void); // Returns the brake state (true=brake pressed,
3232
// false=brake not pressed).
33+
bool pedals_getAccelState(void); // Returns the accel state (true=accel pressed,
34+
// false=accel not pressed).
3335
float pedals_getTorqueLimitPercentage(
3436
void); // Returns the torque limit percentage.
3537
void pedals_setTorqueLimitPercentage(

Core/Src/u_pedals.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef enum {
3737
static uint8_t drive_lock_map = 0;
3838

3939
static _Atomic bool brake_pressed = false;
40+
static _Atomic bool accel_pressed = false;
4041
static _Atomic bool launch_control_enabled = false;
4142
static float torque_limit_percentage = 1.0f;
4243

@@ -71,15 +72,15 @@ static pedal_data_t pedal_data = { 0 };
7172

7273
/* Pedal Tuning */
7374
#define MAX_APPS1_VOLTS 3.50 // (Volts). Upper bound on APPS1 voltage range.
74-
#define MIN_APPS1_VOLTS 2.00 // (Volts). Lower bound on APPS1 voltage range.
75+
#define MIN_APPS1_VOLTS 2.15 // (Volts). Lower bound on APPS1 voltage range.
7576
#define MAX_APPS2_VOLTS 2.50 // (Volts). Upper bound on APPS2 voltage range.
76-
#define MIN_APPS2_VOLTS 1.00 // (Volts). Lower bound on APPS2 voltage range.
77-
#define PEDAL_BRAKE_THRESH 0.20 // (Percantage). Pedal position above which the system registers the brake pedal as "pressed".
78-
#define PEDAL_HARD_BRAKE_THRESH 0.50 // (Percentage). Pedal position above which a "hard brake" is detected.
77+
#define MIN_APPS2_VOLTS 1.15 // (Volts). Lower bound on APPS2 voltage range.
78+
#define PEDAL_BRAKE_THRESH 0.15 // (Percantage). Pedal position above which the system registers the brake pedal as "pressed".
79+
#define PEDAL_HARD_BRAKE_THRESH 0.22 // (Percentage). Pedal position above which a "hard brake" is detected.
7980

8081
/* Performance Limits */
8182
#define PIT_MAX_SPEED 5.0 // (mph). Speed limit in pit mode.
82-
#define MAX_TORQUE 220 // (Nm). Maximum torque output
83+
#define MAX_TORQUE 40 // (Nm). Maximum torque output
8384
#define TORQUE_ACCUMULATOR_SIZE 10 // (Number). Size of the moving average filter for torque stuff.
8485
#define MAX_REGEN_CURRENT 250 // (AC Amps). Maximum regenerative braking current.
8586

@@ -539,9 +540,11 @@ int pedals_init(void) {
539540
/* Returns the brake state (true=brake pressed, false=brake not pressed). */
540541
bool pedals_getBrakeState(void) {
541542
return brake_pressed;
543+
}
542544

543-
/* TEMPORARY OVERRIDE FOR TSMS! should be commented out normally! */
544-
//return true;
545+
/* Returns the accel state (true=accel pressed, false= accel not pressed)*/
546+
bool pedals_getAccelState(void) {
547+
return accel_pressed;
545548
}
546549

547550
/* Returns the torque limit percentgae. */
@@ -693,6 +696,12 @@ void pedals_process(void) {
693696
}
694697
}
695698

699+
if (pedal_data.percentage_accel >= 0.05) {
700+
accel_pressed = true;
701+
} else {
702+
accel_pressed = false;
703+
}
704+
696705
uint16_t dc_current = dti_get_dc_current();
697706
float mph = dti_get_mph();
698707

Core/Src/u_statemachine.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ static int transition_functional_state(func_state_t new_state)
104104
printf("FAULTED\r\n");
105105
}
106106

107+
if (pedals_getAccelState()) {
108+
PRINTLN_WARNING("Accelerator should not be pressed when entering a state");
109+
return;
110+
}
111+
107112
/* Make sure wheels are not spinning before changing modes */
108113
bool brake_state;
109114
rtds_stopReverseSound();

Core/Src/u_threads.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,16 @@ static thread_t statemachine_thread = {
273273
};
274274
void vStatemachine(ULONG thread_input) {
275275

276+
const uint32_t telem_timeout = 50;
277+
276278
while(1) {
277279
state_req_t new_state_req;
278-
while(queue_receive(&state_transition_queue, &new_state_req, TX_WAIT_FOREVER) == U_SUCCESS) {
280+
while(queue_receive(&state_transition_queue, &new_state_req, telem_timeout) == U_SUCCESS) {
279281
statemachine_process(new_state_req);
280282
}
281283

284+
send_carstate_msg();
285+
282286
/* No sleep. Thread timing is controlled completely by the queue timeout. */
283287
}
284288
}

0 commit comments

Comments
 (0)