Skip to content

Commit 2e0dcd1

Browse files
committed
wheel speed on dash
1 parent 40becb9 commit 2e0dcd1

18 files changed

Lines changed: 911 additions & 19 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
******************************************************************************
3+
* @file : FEB_CAN_SensorNodes.h
4+
* @brief : CAN SensorNodes Receiving Module
5+
* @author : Formula Electric @ Berkeley
6+
******************************************************************************
7+
*/
8+
9+
#ifndef FEB_CAN_SensorNodes_H
10+
#define FEB_CAN_SensorNodes_H
11+
12+
#include <stdbool.h>
13+
#include <stdint.h>
14+
15+
void FEB_CAN_SensorNodes_Init(void);
16+
uint16_t FEB_CAN_SensorNodes_GetLastRearWheelSpeed(void);
17+
bool FEB_CAN_SensorNodes_IsDataFresh(uint32_t timeout_ms);
18+
19+
#endif /* FEB_CAN_SensorNodes_H */

DASH/Core/User/Inc/UI_Elements/FEB_UI_Torque.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define FEB_UI_TORQUE_H
88

99
// ── API ───────────────────────────────────────────────────────────────
10-
void FEB_UI_Update_Torque(int16_t torque);
10+
void FEB_UI_Update_Torque();
1111
void FEB_UI_Init_Torque(lv_obj_t *ui_Screen);
1212
void FEB_UI_Destroy_Torque(void);
1313

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* FEB_UI_WSS.h
3+
* Formula Electric Berkeley - DASH UI Wheel Speed
4+
*/
5+
6+
#ifndef FEB_UI_WSS_H
7+
#define FEB_UI_WSS_H
8+
9+
// ── API ───────────────────────────────────────────────────────────────
10+
void FEB_UI_Update_WSS();
11+
void FEB_UI_Init_WSS(lv_obj_t *ui_Screen);
12+
void FEB_UI_Destroy_WSS(void);
13+
14+
#endif /* FEB_UI_WSS_H */

DASH/Core/User/Src/FEB_CAN.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "FEB_CAN_LVPDB.h"
3131
#include "FEB_CAN_PCU.h"
3232
#include "FEB_CAN_BMS.h"
33+
#include "FEB_CAN_SensorNodes.h"
3334

3435
/* ========================== External HAL handles ========================== */
3536
extern CAN_HandleTypeDef hcan1;
@@ -150,6 +151,7 @@ void StartDASHTaskRx(void *argument)
150151
FEB_CAN_BMS_Init();
151152
FEB_CAN_PCU_Init();
152153
FEB_CAN_LVPDB_Init();
154+
FEB_CAN_SensorNodes_Init();
153155

154156
/* Signal that CAN is ready for state publishing */
155157
FEB_CAN_State_SetReady();

DASH/Core/User/Src/FEB_CAN_LVPDB.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ static LVPDB_State_t lvpdb_state = {.lv_24v_voltage = 0, .lv_12v_voltage = 0, .l
3333
static void rx_callback_lv_voltages(FEB_CAN_Instance_t instance, uint32_t can_id, FEB_CAN_ID_Type_t id_type,
3434
const uint8_t *data, uint8_t length, void *user_data)
3535
{
36-
LOG_I("CAN RX", "Received can message %X %X", data[0], data[1]);
3736
struct feb_can_lvpdb_lv_24v_bus_and_12v_bus_voltages_t msg;
3837
if (feb_can_lvpdb_lv_24v_bus_and_12v_bus_voltages_unpack(&msg, data, length) == 0)
3938
{
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
******************************************************************************
3+
* @file : FEB_CAN_SensorNodes.c
4+
* @brief : CAN SensorNodes Receiving Module Implementation
5+
* @author : Formula Electric @ Berkeley
6+
******************************************************************************
7+
*/
8+
9+
#include "FEB_CAN_LVPDB.h"
10+
#include "feb_can.h"
11+
#include "feb_can_lib.h"
12+
#include "feb_log.h"
13+
#include "stm32f4xx_hal.h"
14+
#include <stdbool.h>
15+
#include <stdint.h>
16+
17+
static int16_t rear_wheel_speed = 0;
18+
static uint32_t last_rx_tick;
19+
20+
/* ============================================================================
21+
* RX Callback Handlers
22+
* ============================================================================ */
23+
24+
static void rx_callback_rear_wss(FEB_CAN_Instance_t instance, uint32_t can_id, FEB_CAN_ID_Type_t id_type,
25+
const uint8_t *data, uint8_t length, void *user_data)
26+
{
27+
struct feb_can_wss_rear_data_t msg;
28+
if (feb_can_wss_rear_data_unpack(&msg, data, length) == 0)
29+
{
30+
rear_wheel_speed = msg.wss_right_rear;
31+
__DMB();
32+
last_rx_tick = HAL_GetTick();
33+
}
34+
}
35+
36+
/* ============================================================================
37+
* API Implementation
38+
* ============================================================================ */
39+
40+
void FEB_CAN_SensorNodes_Init(void)
41+
{
42+
FEB_CAN_RX_Params_t rx_params = {
43+
.instance = FEB_CAN_INSTANCE_1,
44+
.can_id = FEB_CAN_WSS_REAR_DATA_FRAME_ID,
45+
.id_type = FEB_CAN_ID_STD,
46+
.filter_type = FEB_CAN_FILTER_EXACT,
47+
.fifo = FEB_CAN_FIFO_0,
48+
.callback = rx_callback_rear_wss,
49+
.user_data = NULL,
50+
};
51+
52+
FEB_CAN_RX_Register(&rx_params);
53+
}
54+
55+
uint16_t FEB_CAN_SensorNodes_GetLastRearWheelSpeed(void)
56+
{
57+
return rear_wheel_speed;
58+
}
59+
60+
bool FEB_CAN_SensorNodes_IsDataFresh(uint32_t timeout_ms)
61+
{
62+
uint32_t last = last_rx_tick;
63+
if (last == 0)
64+
return false;
65+
return (HAL_GetTick() - last) < timeout_ms;
66+
}

DASH/Core/User/Src/FEB_IO.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ void FEB_IO_Update_GPIO(void)
156156
state.button_3 = (bool)(received_data[0] & (1 << 3));
157157
state.button_4 = (bool)(received_data[0] & (1 << 4));
158158

159-
state.switch_logging = !(bool)(received_data[1] & (1 << 1));
160-
state.switch_accumulator_fans = !(bool)(received_data[1] & (1 << 2));
161-
state.switch_coolant_pump_radiator_fan = !(bool)(received_data[1] & (1 << 3));
162-
state.switch_4 = !(bool)(received_data[1] & (1 << 0));
159+
state.switch_accumulator_fans = !(bool)(received_data[1] & (1 << 3)); // switch 1
160+
state.switch_coolant_pump_radiator_fan = !(bool)(received_data[1] & (1 << 2)); // switch 2
161+
state.switch_logging = !(bool)(received_data[1] & (1 << 1)); // // switch 3
162+
state.switch_4 = !(bool)(received_data[1] & (1 << 0)); // switch 4
163163

164164
FEB_IO_Update_Buzzer();
165165
}

DASH/Core/User/Src/FEB_RTD.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static uint32_t rtd_trying_to_toggle_start_tick = 0;
1414
static bool rtd_toggle_complete = false;
1515

1616
// Minimum brake pressure required for RTD activation (safety interlock)
17-
#define RTD_BRAKE_THRESHOLD 20
17+
#define RTD_BRAKE_THRESHOLD 200
1818

1919
// Any RTD input older than this is treated as missing — RTD will not arm on
2020
// stale CAN data. Matches BMS_STATE_TIMEOUT_MS.

DASH/Core/User/Src/FEB_UI_Helpers.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "FEB_UI_Helpers.h"
77
#include "FEB_CAN_PCU.h"
88
#include "UI_Elements/FEB_UI_BMS_State.h"
9+
#include "UI_Elements/FEB_UI_WSS.h"
910
#include "lvgl.h"
1011
#include "src/core/lv_obj_pos.h"
1112
#include "src/core/lv_obj_style.h"
@@ -35,6 +36,7 @@ void ui_init(void)
3536
FEB_UI_Init_Torque(ui_Screen1);
3637
FEB_UI_Init_IO_States(ui_Screen1);
3738
FEB_UI_Init_BMS_State(ui_Screen1);
39+
FEB_UI_Init_WSS(ui_Screen1);
3840

3941
// Load screen
4042
lv_disp_load_scr(ui_Screen1);
@@ -46,7 +48,8 @@ void ui_update(void)
4648
{
4749
fake_torque += 1;
4850

49-
FEB_UI_Update_Torque(FEB_CAN_PCU_GetLastTorque());
51+
FEB_UI_Update_Torque();
52+
FEB_UI_Update_WSS();
5053
FEB_UI_Update_IO_States();
5154
FEB_UI_Update_BMS_State();
5255

DASH/Core/User/Src/UI_Elements/FEB_UI_BMS_State.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int16_t cell_max_temperature = 67;
2222
uint16_t accumulator_total_voltage = 67;
2323
uint16_t low_voltage = 67;
2424

25-
char buf[16];
25+
static char buf[16];
2626

2727
void FEB_UI_Update_BMS_State()
2828
{

0 commit comments

Comments
 (0)