Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Core/Inc/u_pedals.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ void pedals_process(void); // Pedal Processing Function. Meant to be called by
// the pedals thread.
bool pedals_getBrakeState(void); // Returns the brake state (true=brake pressed,
// false=brake not pressed).
bool pedals_getAccelState(void); // Returns the accel state (true=accel pressed,
// false=accel not pressed).
float pedals_getTorqueLimitPercentage(
void); // Returns the torque limit percentage.
void pedals_setTorqueLimitPercentage(
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/u_threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void vEFuses(ULONG thread_input);
void vMux(ULONG thread_input);
void vPeripherals(ULONG thread_input);
void vTest(ULONG thread_input);
void vRTDS(ULONG thread_input);
void vTelemetry(ULONG thread_input);


#endif /* u_threads.h */
21 changes: 15 additions & 6 deletions Core/Src/u_pedals.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef enum {
static uint8_t drive_lock_map = 0;

static _Atomic bool brake_pressed = false;
static _Atomic bool accel_pressed = false;
static _Atomic bool launch_control_enabled = false;
static float torque_limit_percentage = 1.0f;

Expand Down Expand Up @@ -71,11 +72,11 @@ static pedal_data_t pedal_data = { 0 };

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

/* Performance Limits */
#define PIT_MAX_SPEED 5.0 // (mph). Speed limit in pit mode.
Expand Down Expand Up @@ -539,9 +540,11 @@ int pedals_init(void) {
/* Returns the brake state (true=brake pressed, false=brake not pressed). */
bool pedals_getBrakeState(void) {
return brake_pressed;
}

/* TEMPORARY OVERRIDE FOR TSMS! should be commented out normally! */
//return true;
/* Returns the accel state (true=accel pressed, false= accel not pressed)*/
bool pedals_getAccelState(void) {
return accel_pressed;
}

/* Returns the torque limit percentgae. */
Expand Down Expand Up @@ -693,6 +696,12 @@ void pedals_process(void) {
}
}

if (pedal_data.percentage_accel >= 0.05) {
accel_pressed = true;
} else {
accel_pressed = false;
}

uint16_t dc_current = dti_get_dc_current();
float mph = dti_get_mph();

Expand Down
5 changes: 5 additions & 0 deletions Core/Src/u_statemachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ static int transition_functional_state(func_state_t new_state)
printf("FAULTED\r\n");
}

if (pedals_getAccelState()) {
PRINTLN_WARNING("Accelerator should not be pressed when entering a state");
return 3;
}

/* Make sure wheels are not spinning before changing modes */
bool brake_state;
rtds_stopReverseSound();
Expand Down
26 changes: 14 additions & 12 deletions Core/Src/u_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#define PRIO_vShutdown 2
#define PRIO_vEFuses 3
#define PRIO_vMux 3
#define PRIO_vRTDS 3
#define PRIO_vTelemetry 3
#define PRIO_vTest 3
#define PRIO_vPeripherals 3

Expand Down Expand Up @@ -875,24 +875,23 @@ void vPeripherals(ULONG thread_input) {
}
}

/* RTDS Telemetry Thread.
This thread is for RTDS telemetry. The actual state of the RTDS is managed by the statemachine. */
static thread_t rtds_telemetry_thread = {
.name = "RTDS Telemetry Thread", /* Name */
/* Misc. Telemetry Thread.
This thread periodically reports the RTDS and statemachine state data. The actual states of these things are managed by the statemachine thread. This is specifically for telemetry. */
static thread_t misc_telemetry_thread = {
.name = "Misc Telemetry Thread", /* Name */
.size = 2048, /* Stack Size (in bytes) */
.priority = PRIO_vRTDS, /* Priority */
.priority = PRIO_vTelemetry, /* Priority */
.threshold = 0, /* Preemption Threshold */
.time_slice = TX_NO_TIME_SLICE, /* Time Slice */
.auto_start = TX_AUTO_START, /* Auto Start */
.sleep = 100, /* Sleep (in ticks) */
.function = vRTDS /* Thread Function */
.function = vTelemetry /* Thread Function */
};
void vRTDS(ULONG thread_input) {
void vTelemetry(ULONG thread_input) {

while(1) {

PRINTLN_INFO("thread ran");

/* Send RTDS State Telemetry. */
bool rtds_pin_state = rtds_readRTDS();
bool rtds_sounding_state = false;
bool rtds_reverse_state = false;
Expand All @@ -910,8 +909,11 @@ void vRTDS(ULONG thread_input) {

send_rtds_state_message(rtds_pin_state, rtds_sounding_state, rtds_reverse_state, error_state);

/* Send Carstate message. */
send_carstate_msg();

/* Sleep Thread for specified number of ticks. */
tx_thread_sleep(rtds_telemetry_thread.sleep);
tx_thread_sleep(misc_telemetry_thread.sleep);
}
}

Expand All @@ -933,7 +935,7 @@ uint8_t threads_init(TX_BYTE_POOL *byte_pool) {
CATCH_ERROR(create_thread(byte_pool, &mux_thread), U_SUCCESS); // Create Mux thread.
CATCH_ERROR(create_thread(byte_pool, &peripherals_thread), U_SUCCESS); // Create Peripherals thread.
// CATCH_ERROR(create_thread(byte_pool, &test_thread), U_SUCCESS); // Create Test thread.
CATCH_ERROR(create_thread(byte_pool, &rtds_telemetry_thread), U_SUCCESS); // Create RTDS Telemetry thread.
CATCH_ERROR(create_thread(byte_pool, &misc_telemetry_thread), U_SUCCESS); // Create RTDS Telemetry thread.

// add more threads here if need

Expand Down
Loading