diff --git a/Core/Inc/u_rtds.h b/Core/Inc/u_rtds.h index 722d8b8..f623883 100644 --- a/Core/Inc/u_rtds.h +++ b/Core/Inc/u_rtds.h @@ -4,7 +4,7 @@ #include /* Config: */ -#define RTDS_DURATION 5000 /* RTDS duration (in ticks). */ +#define RTDS_DURATION 1500 /* RTDS duration (in ticks). */ /* API */ int rtds_init(void); // Initializes the RTDS timer. diff --git a/Core/Inc/u_statemachine.h b/Core/Inc/u_statemachine.h index e61a52a..9660714 100644 --- a/Core/Inc/u_statemachine.h +++ b/Core/Inc/u_statemachine.h @@ -1,7 +1,7 @@ #ifndef STATE_MACHINE_H #define STATE_MACHINE_H -// #define TSMS_OVERRIDE //Uncomment to remove all checks for state machine +#define TSMS_OVERRIDE //Uncomment to remove all checks for state machine // #define IGNORE_FAULT #include "u_dti.h" diff --git a/Core/Src/u_bms.c b/Core/Src/u_bms.c index 096218e..260c453 100644 --- a/Core/Src/u_bms.c +++ b/Core/Src/u_bms.c @@ -11,7 +11,7 @@ /* Globals. */ static _Atomic float battbox_temp; -static _Atomic bool precharge = false; // Default to false until BMS confirms precharge is complete +static _Atomic bool precharge = true; // u_TODO - set this back to false once testing done!!! // Default to false until BMS confirms precharge is complete static void _bms_fault_callback(ULONG args); // Forward declaration diff --git a/Core/Src/u_dti.c b/Core/Src/u_dti.c index 716321e..db68d02 100644 --- a/Core/Src/u_dti.c +++ b/Core/Src/u_dti.c @@ -20,6 +20,7 @@ #include "c_utils.h" #include "u_bms.h" #include "u_can.h" +#include "serial.h" #include "u_emrax.h" #include "u_queues.h" #include "u_mutexes.h" @@ -122,9 +123,15 @@ void dti_set_regen(uint16_t current_target) void dti_set_current(int16_t current) { - if (!bms_getPrecharge()) { - return; - } + static uint32_t count = 0; + serial_monitor("dti_current", "current", "%d", current); + serial_monitor("dti_current", "count", "%ld", count); + count++; + + // u_TODO - uncomment this when done testing + // if (!bms_getPrecharge()) { + // return; + // } can_msg_t msg = { .id = 0x036, .len = 2, .data = { 0 } }; #ifdef TSMS_OVERRIDE diff --git a/Core/Src/u_faults.c b/Core/Src/u_faults.c index 4d1ed08..4f35894 100644 --- a/Core/Src/u_faults.c +++ b/Core/Src/u_faults.c @@ -102,6 +102,8 @@ int faults_init(void) { /* Triggers a fault. */ /* If the fault is already triggered, this just resets the fault's timer. */ int trigger_fault(fault_t fault_id) { + return U_SUCCESS; // u_TODO - remove this once testing done!!! + /* Set the relevant fault bit in the fault flags list. */ atomic_fetch_or(&fault_flags, (uint32_t)(1 << fault_id)); // This is the _Atomic version of: fault_flags |= (uint32_t)(1 << fault_id); diff --git a/Core/Src/u_rtds.c b/Core/Src/u_rtds.c index b4f1f9a..5290ec2 100644 --- a/Core/Src/u_rtds.c +++ b/Core/Src/u_rtds.c @@ -95,26 +95,6 @@ int rtds_init(void) { return U_SUCCESS; } -/* Sounds the RTDS (Ready-to-drive sound). */ -int rtds_soundRTDS(void) { - - /* Stop the reverse sound if active. */ - rtds_stopReverseSound(); - - /* Trigger the RTDS sound. */ - _set_rtds_pin(); - - /* Restart RTDS timer. */ - int status = timer_restart(&rtds_timer); - if(status != U_SUCCESS) { - PRINTLN_ERROR("Failed to restart RTDS timer (Status: %d).", status); - queue_send(&faults, &(fault_t){RTDS_FAULT}, TX_NO_WAIT); - return U_ERROR; - } - - return U_SUCCESS; -} - /* Cancels the RTDS sound. The RTDS sound already stops automatically once it's over, but this function lets you cancel it prematurely. */ int rtds_cancelRTDS(void) { /* Stop the RTDS sound. */ @@ -148,23 +128,6 @@ int rtds_startReverseSound(void) { return U_SUCCESS; } -/* Stops the reverse sound. */ -int rtds_stopReverseSound(void) { - /* Turn off the RTDS sound */ - _clear_rtds_pin(); - - /* Deactivate the reverse sound timer */ - int status = timer_stop(&reverse_sound_timer); - if(status != U_SUCCESS) { - PRINTLN_ERROR("Failed to deactivate reverse sound timer (Status: %d).", status); - queue_send(&faults, &(fault_t){RTDS_FAULT}, TX_NO_WAIT); - return U_ERROR; - } - - PRINTLN_INFO("Stopped reverse sound."); - return U_SUCCESS; -} - /* Reads the status of the RTDS pin (true = RTDS pin is active, false = RTDS pin is not active). */ /* Useful for debugging. */ bool rtds_readRTDS(void) { @@ -212,3 +175,41 @@ int rtds_isInSounding(bool* state) { return U_SUCCESS; } + +/* Stops the reverse sound. */ +int rtds_stopReverseSound(void) { + + /* Turn off the RTDS sound */ + _clear_rtds_pin(); + + /* Deactivate the reverse sound timer */ + int status = timer_stop(&reverse_sound_timer); + if(status != U_SUCCESS) { + PRINTLN_ERROR("Failed to deactivate reverse sound timer (Status: %d).", status); + queue_send(&faults, &(fault_t){RTDS_FAULT}, TX_NO_WAIT); + return U_ERROR; + } + + PRINTLN_INFO("Stopped reverse sound."); + return U_SUCCESS; +} + +/* Sounds the RTDS (Ready-to-drive sound). */ +int rtds_soundRTDS(void) { + + /* Stop the reverse sound if active. */ + rtds_stopReverseSound(); + + /* Trigger the RTDS sound. */ + _set_rtds_pin(); + + /* Restart RTDS timer. */ + int status = timer_restart(&rtds_timer); + if(status != U_SUCCESS) { + PRINTLN_ERROR("Failed to restart RTDS timer (Status: %d).", status); + queue_send(&faults, &(fault_t){RTDS_FAULT}, TX_NO_WAIT); + return U_ERROR; + } + + return U_SUCCESS; +} diff --git a/Core/Src/u_shutdown.c b/Core/Src/u_shutdown.c index 58f3943..4cac49b 100644 --- a/Core/Src/u_shutdown.c +++ b/Core/Src/u_shutdown.c @@ -9,8 +9,8 @@ #include "debounce.h" #include "can_messages_tx.h" -/* Bool to track the BMS shutdown state. */ -static _Atomic bool bms_shutdown = false; // We should assume that we are shutdown is open (`false`) until BMS confirms that shutdown is open (`true`). +/* Bool to track the BMS shutdown state. */ // u_TODO - make sure this is 'false' again!! +static _Atomic bool bms_shutdown = true; // We should assume that we are shutdown is open (`false`) until BMS confirms that shutdown is closed (`true`). // BMS periodically sends out a CAN message reporting the shutdown state. That state is tracked here. // When this bool is `false`, BMS is indicating that shutdown is open, which is bad. // When this bool is `true`, BMS is indicating that shutdown is closed, meaning that we are in normal operation and everything is good diff --git a/Core/Src/u_statemachine.c b/Core/Src/u_statemachine.c index cb9d169..8e8d130 100644 --- a/Core/Src/u_statemachine.c +++ b/Core/Src/u_statemachine.c @@ -72,6 +72,11 @@ int init_statemachine(void) { return U_ERROR; } + // u_TODO - Remove this when done tesgin!! default the state to functional + cerberus_state.functional = F_PERFORMANCE; + cerberus_state.nero.home_mode = false; + cerberus_state.nero.nero_index = PERFORMANCE; + PRINTLN_INFO("Ran init_statemachine()."); return U_SUCCESS; } @@ -96,6 +101,7 @@ nero_state_t get_nero_state() static int transition_functional_state(func_state_t new_state) { + /* Special case: should be able to fault no matter what conditions */ if (new_state == FAULTED) { /* Turn off high power peripherals */ @@ -111,7 +117,11 @@ static int transition_functional_state(func_state_t new_state) /* Make sure wheels are not spinning before changing modes */ bool brake_state; - rtds_stopReverseSound(); + + /* If we're actively in the reverse state, stop the reverse sound before doing any state changes. */ + if(cerberus_state.functional == F_REVERSE) { + rtds_stopReverseSound(); + } /* Catching state transitions */ switch (new_state) { @@ -214,7 +224,6 @@ static int transition_nero_state(nero_state_t new_state) cerberus_state.nero = new_state; PRINTLN_INFO("ran transition_nero_state()"); - return 0; } diff --git a/Core/Src/u_threads.c b/Core/Src/u_threads.c index 2ed6d6e..05244b8 100644 --- a/Core/Src/u_threads.c +++ b/Core/Src/u_threads.c @@ -230,6 +230,13 @@ void vCANOutgoing(ULONG thread_input) { queue_send(&faults, &(fault_t){CAN_OUTGOING_FAULT}, TX_NO_WAIT); } + + // u_TODO - when done testing, comment this out + if(message.id == 0x036) { + static uint32_t count = 0; + serial_monitor("dti_current", "sent_count", "%ld", count); + count++; + } tx_thread_sleep(1); // This is needed, or else the queue will try to send messages too fast and outpace the HAL. } }