Skip to content

Commit dbd03a1

Browse files
Merge branch 'main' into debug/tsms-override-test
2 parents 21fd2aa + a174567 commit dbd03a1

5 files changed

Lines changed: 37 additions & 19 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/Inc/u_threads.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void vEFuses(ULONG thread_input);
3030
void vMux(ULONG thread_input);
3131
void vPeripherals(ULONG thread_input);
3232
void vTest(ULONG thread_input);
33-
void vRTDS(ULONG thread_input);
33+
void vTelemetry(ULONG thread_input);
3434

3535

3636
#endif /* u_threads.h */

Core/Src/u_pedals.c

Lines changed: 15 additions & 6 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,11 +72,11 @@ 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.
@@ -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 3;
110+
}
111+
107112
/* Make sure wheels are not spinning before changing modes */
108113
bool brake_state;
109114

Core/Src/u_threads.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#define PRIO_vShutdown 2
4242
#define PRIO_vEFuses 3
4343
#define PRIO_vMux 3
44-
#define PRIO_vRTDS 3
44+
#define PRIO_vTelemetry 3
4545
#define PRIO_vTest 3
4646
#define PRIO_vPeripherals 3
4747

@@ -875,24 +875,23 @@ void vPeripherals(ULONG thread_input) {
875875
}
876876
}
877877

878-
/* RTDS Telemetry Thread.
879-
This thread is for RTDS telemetry. The actual state of the RTDS is managed by the statemachine. */
880-
static thread_t rtds_telemetry_thread = {
881-
.name = "RTDS Telemetry Thread", /* Name */
878+
/* Misc. Telemetry Thread.
879+
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. */
880+
static thread_t misc_telemetry_thread = {
881+
.name = "Misc Telemetry Thread", /* Name */
882882
.size = 2048, /* Stack Size (in bytes) */
883-
.priority = PRIO_vRTDS, /* Priority */
883+
.priority = PRIO_vTelemetry, /* Priority */
884884
.threshold = 0, /* Preemption Threshold */
885885
.time_slice = TX_NO_TIME_SLICE, /* Time Slice */
886886
.auto_start = TX_AUTO_START, /* Auto Start */
887887
.sleep = 100, /* Sleep (in ticks) */
888-
.function = vRTDS /* Thread Function */
888+
.function = vTelemetry /* Thread Function */
889889
};
890-
void vRTDS(ULONG thread_input) {
890+
void vTelemetry(ULONG thread_input) {
891891

892892
while(1) {
893893

894-
PRINTLN_INFO("thread ran");
895-
894+
/* Send RTDS State Telemetry. */
896895
bool rtds_pin_state = rtds_readRTDS();
897896
bool rtds_sounding_state = false;
898897
bool rtds_reverse_state = false;
@@ -910,8 +909,11 @@ void vRTDS(ULONG thread_input) {
910909

911910
send_rtds_state_message(rtds_pin_state, rtds_sounding_state, rtds_reverse_state, error_state);
912911

912+
/* Send Carstate message. */
913+
send_carstate_msg();
914+
913915
/* Sleep Thread for specified number of ticks. */
914-
tx_thread_sleep(rtds_telemetry_thread.sleep);
916+
tx_thread_sleep(misc_telemetry_thread.sleep);
915917
}
916918
}
917919

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

938940
// add more threads here if need
939941

0 commit comments

Comments
 (0)