Skip to content
Closed
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: 1 addition & 1 deletion Core/Inc/u_rtds.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdbool.h>

/* 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.
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/u_statemachine.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Core/Src/u_bms.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 10 additions & 3 deletions Core/Src/u_dti.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Core/Src/u_faults.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
75 changes: 38 additions & 37 deletions Core/Src/u_rtds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions Core/Src/u_shutdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions Core/Src/u_statemachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 */
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 7 additions & 0 deletions Core/Src/u_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
Expand Down
Loading