Skip to content

Commit

Permalink
Quadruna RSM Tests (#1228)
Browse files Browse the repository at this point in the history
Testing to do

heart beat monitor:
- [x] missing FSM heart beat caught standalone (can recorded a missing
heartbeat when no BMS connected)
- [ ] missing FMS heart beat caught with other boards connected 
- [x] missing VC heart beat caught standalone (can recorded a missing
heartbeat when no BMS connected)
- [ ] missing VC heart beat caught with other boards connected 

watchdog timer:

- [ ] record a timeout when infinite loop placed in code

io/app:
- [ ] Coolant temp transfer functions
- [ ] Coolant pressure adc voltage readings
- [ ] load cell adc voltage readings
- [ ] load cell OCSC warning behaving as expected
- [ ] suspension adc voltage reading
- [ ] suspension OCSC warning behaving as expected

---------

Co-authored-by: Edwin <[email protected]>
  • Loading branch information
shayana18 and Lucien950 authored May 13, 2024
1 parent 7cf4b14 commit 44a328f
Show file tree
Hide file tree
Showing 24 changed files with 677 additions and 179 deletions.
60 changes: 32 additions & 28 deletions can_bus/quadruna/RSM/RSM_alerts.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,71 @@
"warnings_counts_id": 492,
"faults_counts_id": 493,
"warnings": {
"TxOverflow": {
"WatchdogTimeout": {
"id" :401,
"description" : "Example"
"description" : "Watchdog timeout"
},
"RxOverflow": {
"TxOverflow": {
"id" :402,
"description" : "Example"
"description" : "canTX overflow"
},
"StackWaterMarkHighTask1Hz": {
"RxOverflow": {
"id" :403,
"description" : "Example"
"description" : "canRX overflow"
},
"StackWaterMarkHighTask100Hz": {
"StackWaterMarkHighTask1Hz": {
"id" :404,
"description" : "Example"
"description" : "Stack Watermark mark failed for 1Hz"
},
"StackWaterMarkHighTask1kHz": {
"StackWaterMarkHighTask100Hz": {
"id" :405,
"description" : "Example"
"description" : "Stack Watermark mark failed for 100Hz"
},
"StackWaterMarkHighTaskCanRx": {
"StackWaterMarkHighTask1kHz": {
"id" :406,
"description" : "Example"
"description" : "Stack Watermark mark failed for 1kHz"
},
"StackWaterMarkHighTaskCanTx": {
"StackWaterMarkHighTaskCanRx": {
"id" :407,
"description" : "Example"
"description" : "Stack Watermark failed on canRx"
},
"FlowRateOutOfRange": {
"StackWaterMarkHighTaskCanTx": {
"id" :408,
"description" : "Example"
"description" : "Stack Watermark failed on CanTx"
},
"LeftSuspensionOCSC": {
"FlowRateOutOfRange": {
"id" :409,
"description" : "Example"
"description" : "Coolant flow out of range"
},
"RightSuspensionOCSC": {
"LeftSuspensionOCSC": {
"id" :410,
"description" : "Example"
"description" : "Rear left suspension open or short circuit"
},
"LoadCell3OCSC": {
"RightSuspensionOCSC": {
"id" :411,
"description" : "Example"
"description" : "Rear right suspension open or short circuit"
},
"LoadCell4OCSC": {
"LoadCell3OCSC": {
"id" :412,
"description" : "Example"
"description" : "Load cell 3 open or short circuit"
},
"LoadCell4OCSC": {
"id" :413,
"description" : "Load cell 4 open or short circuit"
}
},
"faults": {
"FlowMeterUnderflow": {
"id" :451,
"description" : "Example"
"description" : "Coolant flow meter underflow"
},
"MissingBMSHeartbeat": {
"MissingVCHeartbeat": {
"id" :452,
"description" : "Example"
"description" : "VC Missing Heart beat"
},
"MissingFSMHeartbeat": {
"id" :453,
"description" : "Example"
"description" : "FSM Missing Heart beat"
}

}
Expand Down
12 changes: 6 additions & 6 deletions can_bus/quadruna/RSM/RSM_tx.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"AlertsContext": {
"msg_id": 401,
"msg_id": 414,
"cycle_time": 1000,
"signals": {
"WatchdogTimeoutTaskName": {
Expand All @@ -15,7 +15,7 @@
}
},
"Vitals": {
"msg_id": 406,
"msg_id": 415,
"cycle_time": 100,
"description": "RSM vitals message.",
"signals": {
Expand All @@ -28,7 +28,7 @@
}
},
"Coolant": {
"msg_id": 407,
"msg_id": 416,
"cycle_time": 1000,
"signals": {
"CoolantFlowRate": {
Expand Down Expand Up @@ -64,7 +64,7 @@
}
},
"Suspension": {
"msg_id": 408,
"msg_id": 417,
"cycle_time": 100,
"description": "Suspension travel.",
"signals": {
Expand All @@ -83,8 +83,8 @@
}
},
"LoadCell":{
"msg_id" : 409,
"cycle_time": null,
"msg_id" : 418,
"cycle_time": 100,
"description" : "Mechanical load on load cell",
"signals" : {
"LoadCell3" : {
Expand Down
2 changes: 2 additions & 0 deletions firmware/quadruna/FSM/src/tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ void tasks_init(void)

_Noreturn void tasks_run1Hz(void)
{
io_chimera_sleepTaskIfEnabled();

static const TickType_t period_ms = 1000U;
WatchdogHandle *watchdog = hw_watchdog_allocateWatchdog();
hw_watchdog_initWatchdog(watchdog, RTOS_TASK_1HZ, period_ms);
Expand Down
47 changes: 29 additions & 18 deletions firmware/quadruna/RSM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,36 @@ if("${TARGET}" STREQUAL "deploy")
)

elseif("${TARGET}" STREQUAL "test")
set(HEADERS_TO_FAKE
"${CMAKE_CURRENT_SOURCE_DIR}/src/io/io_brakeLight.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/io/io_coolant.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/io/io_load.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/io/io_suspension.h"
)
jsoncan_sources(
"RSM"
"${CMAKE_CURRENT_BINARY_DIR}"
FALSE
"quadruna"
)

create_fake_library(
"quadruna_RSM_fakes"
"${HEADERS_TO_FAKE}"
)
add_library(quadruna_RSM_can STATIC "${CAN_SRCS}")
target_include_directories(quadruna_RSM_can PUBLIC "${CAN_INCLUDE_DIRS}")

set(HEADERS_TO_FAKE
"${CMAKE_CURRENT_SOURCE_DIR}/src/io/io_coolant.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/io/io_loadCell.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/io/io_suspension.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/io/io_fan.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/io/io_brake_light.h"
)

set(SRCS ${APP_SRCS} ${TEST_SRCS})
set(INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${IO_INCLUDE_DIRS} ${TEST_INCLUDE_DIRS})
compile_gtest_executable(
"quadruna_RSM_test"
"${SRCS}"
"${INCLUDE_DIRS}"
)
target_link_libraries("quadruna_RSM_test" "quadruna_RSM_can" "quadruna_RSM_fakes" "shared_fakes" "m")
create_fake_library(
"quadruna_RSM_fakes"
"${HEADERS_TO_FAKE}"
)

set(SRCS ${APP_SRCS} ${TEST_SRCS})
set(INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${IO_INCLUDE_DIRS} ${TEST_INCLUDE_DIRS})
compile_gtest_executable(
"quadruna_RSM_test"
"${SRCS}"
"${INCLUDE_DIRS}"
)
target_link_libraries("quadruna_RSM_test" "quadruna_RSM_can" "quadruna_RSM_fakes" "shared_fakes" "m")

endif()
9 changes: 0 additions & 9 deletions firmware/quadruna/RSM/src/app/app_globals.c

This file was deleted.

21 changes: 0 additions & 21 deletions firmware/quadruna/RSM/src/app/app_globals.h

This file was deleted.

4 changes: 2 additions & 2 deletions firmware/quadruna/RSM/src/app/app_loadCell.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ void app_loadcell_broadcast()
{
app_canTx_RSM_LoadCell3_set(io_loadCell_getMechanicalLoad3());
app_canTx_RSM_LoadCell4_set(io_loadCell_getMechanicalLoad4());
app_canAlerts_RSM_Warning_LoadCell3OCSC_set(io_loadCell3_OCSC());
app_canAlerts_RSM_Warning_LoadCell3OCSC_set(io_loadCell4_OCSC());
app_canAlerts_RSM_Warning_LoadCell3OCSC_set(io_loadCell_sensor3OCSC());
app_canAlerts_RSM_Warning_LoadCell4OCSC_set(io_loadCell_sensor4OCSC());
}
16 changes: 6 additions & 10 deletions firmware/quadruna/RSM/src/app/app_mainState.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include <stddef.h>
#include "io_led.h"
#include "io_fan.h"
#include "io_brake_light.h"
#include "app_canTx.h"
#include "app_mainState.h"
#include "app_canRx.h"
#include "app_coolant.h"
#include "app_loadCell.h"
#include "app_suspension.h"
#include "app_globals.h"

#include "app_heartbeatMonitor.h"

void mainStateRunOnTick100Hz(void)
Expand All @@ -18,14 +18,10 @@ void mainStateRunOnTick100Hz(void)
app_heartbeatMonitor_tick();
app_heartbeatMonitor_broadcastFaults();

const bool brake_actuated = app_canRx_FSM_BrakeActuated_get();
io_led_enable(globals->config->brake_light, brake_actuated);

io_brake_light_set(app_canRx_FSM_BrakeActuated_get());
const bool hv_on = app_canRx_BMS_State_get() == BMS_DRIVE_STATE;
hw_gpio_writePin(globals->config->acc_fan, hv_on);
hw_gpio_writePin(globals->config->rad_fan, hv_on);

bool missing_hb = app_heartbeatMonitor_checkFaults();
io_acc_fan_set(hv_on);
io_rad_fan_set(hv_on);
}

const State *app_mainState_get(void)
Expand Down
24 changes: 24 additions & 0 deletions firmware/quadruna/RSM/src/hw/hw_watchdogConfig.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "hw_watchdogConfig.h"
#include "hw_hal.h"
#include <string.h>
#include "app_canAlerts.h"
#include "app_canTx.h"
#include "io_canTx.h"
#include "hw_utils.h"

// TODO: Re-enable watchdog.
// extern IWDG_HandleTypeDef hiwdg;

void hw_watchdogConfig_refresh(void)
{
// HAL_IWDG_Refresh(&hiwdg);
}

void hw_watchdogConfig_timeoutCallback(WatchdogHandle *watchdog)
{
BREAK_IF_DEBUGGER_CONNECTED();

const uint8_t watchdog_id = hw_watchdog_getTaskId(watchdog);
app_canAlerts_RSM_Warning_WatchdogTimeout_set(true);
app_canTx_RSM_WatchdogTimeoutTaskName_set((RtosTaskName)watchdog_id);
}
6 changes: 6 additions & 0 deletions firmware/quadruna/RSM/src/hw/hw_watchdogConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "hw_watchdog.h"

void hw_watchdogConfig_refresh(void);
void hw_watchdogConfig_timeoutCallback(WatchdogHandle *watchdog);
13 changes: 13 additions & 0 deletions firmware/quadruna/RSM/src/io/io_brake_light.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "io_brake_light.h"

static const BinaryLed *brake_light = NULL;

void io_brake_light_init(const BinaryLed *brake_light_in)
{
brake_light = brake_light_in;
}

void io_brake_light_set(bool val)
{
io_led_enable(brake_light, val);
}
8 changes: 8 additions & 0 deletions firmware/quadruna/RSM/src/io/io_brake_light.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#ifdef TARGET_EMBEDDED
#include "io_led.h"
void io_brake_light_init(const BinaryLed *brake_light);
#endif

void io_brake_light_set(bool val);
20 changes: 20 additions & 0 deletions firmware/quadruna/RSM/src/io/io_fan.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "io_fan.h"

static const Gpio *acc_fan = NULL;
static const Gpio *rad_fan = NULL;

void io_fan_init(const Gpio *acc_fan_in, const Gpio *rad_fan_in)
{
acc_fan = acc_fan_in;
rad_fan = rad_fan_in;
}

void io_acc_fan_set(bool on)
{
hw_gpio_writePin(acc_fan, on);
}

void io_rad_fan_set(bool on)
{
hw_gpio_writePin(rad_fan, on);
}
13 changes: 13 additions & 0 deletions firmware/quadruna/RSM/src/io/io_fan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <stdbool.h>
#include "app_utils.h"

#ifdef TARGET_EMBEDDED
#include "hw_gpio.h"
void io_fan_init(const Gpio *acc_fan_in, const Gpio *rad_fan_in);
#endif

void io_acc_fan_set(bool on);

void io_rad_fan_set(bool on);
Loading

0 comments on commit 44a328f

Please sign in to comment.