Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Core/Inc/msb.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ int8_t debug2_write(bool status);

int8_t vcc5_en_write(bool status);

int32_t imu_data_get(stmdev_ctx_t *ctx, stmdev_ctx_t *aux_ctx,
lsm6dso_md_t *imu_md_temp, lsm6dso_data_t *imu_data_temp);
int32_t imu_data_get_accel(LSM6DSO_Axes_t *axes);
int32_t imu_data_get_gyro(LSM6DSO_Axes_t *axes);

#ifdef SENSOR_SHOCKPOT
void shockpot_read(uint32_t *shockpot_sense);
Expand Down
4 changes: 2 additions & 2 deletions Core/Inc/msb_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#define CAN_ENABLE

// on central
#define SENSOR_TEMP // SHT30
#define SENSOR_SHOCKPOT // ADC1
#define SENSOR_TEMP // SHT30
//#define SENSOR_SHOCKPOT // ADC1
//#define SENSOR_STRAIN // ADC1
//#define SENSOR_TOF // VL6180X

Expand Down
2 changes: 1 addition & 1 deletion Core/Src/can_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void vCanDispatch(void *pv_params)
&msg_from_queue, NULL,
osWaitForever)) {
#ifdef CAN_ENABLE
while (HAL_CAN_GetTxMailboxesFreeLevel(&hcan1) == 0) {
while (HAL_CAN_GetTxMailboxesFreeLevel(&hcan1) == 0) {
osDelay(1);
}

Expand Down
2 changes: 1 addition & 1 deletion Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ static void MX_CAN1_Init(void)
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = ENABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoRetransmission = ENABLE;
hcan1.Init.AutoRetransmission = DISABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK)
Expand Down
66 changes: 28 additions & 38 deletions Core/Src/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,6 @@ void vIMUMonitor(void *pv_params)
int16_t gyro_z;
} gyro_data;

struct __attribute__((__packed__)) {
float_t temp;
} temperature_data;

stmdev_ctx_t ctx;
stmdev_ctx_t aux_ctx;
// int16_t temperature_data_temp;

lsm6dso_md_t imu_md_temp;
lsm6dso_data_t imu_data_temp;

can_msg_t imu_orientation_msg = {
.id = convert_can(CANID_IMU_ORIENTATION, device_loc),
.len = 6,
Expand All @@ -142,40 +131,35 @@ void vIMUMonitor(void *pv_params)
int16_t yaw;
} orientation_data;

/* Add parameters for formatting data */
imu_md_temp.ui.gy.fs = LSM6DSO_500dps;
imu_md_temp.ui.gy.odr = LSM6DSO_GY_UI_52Hz_LP;
imu_md_temp.ui.xl.fs = LSM6DSO_XL_UI_2g;
imu_md_temp.ui.xl.odr = LSM6DSO_XL_UI_52Hz_LP;
LSM6DSO_Axes_t axes_accel;
LSM6DSO_Axes_t axes_gyro;

for (;;) {
/* Take measurement */
if (imu_data_get(&ctx, &aux_ctx, &imu_md_temp,
&imu_data_temp)) {
printf("Failed to get IMU data \r\n");
if (imu_data_get_accel(&axes_accel)) {
printf("Failed to get accel data \r\n");
}
if (imu_data_get_gyro(&axes_gyro)) {
printf("Failed to get gyro data \r\n");
}

/* Run values through LPF of sample size */
accel_data.accel_x = imu_data_temp.ui.xl.mg[0];
accel_data.accel_y = imu_data_temp.ui.xl.mg[1];
accel_data.accel_z = imu_data_temp.ui.xl.mg[2];
gyro_data.gyro_x = imu_data_temp.ui.gy.mdps[0];
gyro_data.gyro_y = imu_data_temp.ui.gy.mdps[1];
gyro_data.gyro_z = imu_data_temp.ui.gy.mdps[2];
temperature_data.temp = imu_data_temp.ui.heat.deg_c;
accel_data.accel_x = axes_accel.x;
accel_data.accel_y = axes_accel.y;
accel_data.accel_z = axes_accel.z;
gyro_data.gyro_x = axes_gyro.x;
gyro_data.gyro_y = axes_gyro.y;
gyro_data.gyro_z = axes_gyro.z;

// Acc (Convert mg to g)
mFXInput.acc[0] = (float)(imu_data_temp.ui.xl.mg[0] / 1000.0f);
mFXInput.acc[1] = (float)(imu_data_temp.ui.xl.mg[1] / 1000.0f);
mFXInput.acc[2] = (float)(imu_data_temp.ui.xl.mg[2] / 1000.0f);
mFXInput.acc[0] = (float)(axes_accel.x / 1000.0f);
mFXInput.acc[1] = (float)(axes_accel.y / 1000.0f);
mFXInput.acc[2] = (float)(axes_accel.z / 1000.0f);

// Gyro (Convert mdps to dps)
mFXInput.gyro[0] =
(float)(imu_data_temp.ui.gy.mdps[0] * 0.001f);
mFXInput.gyro[1] =
(float)(imu_data_temp.ui.gy.mdps[1] * 0.001f);
mFXInput.gyro[2] =
(float)(imu_data_temp.ui.gy.mdps[2] * 0.001f);
mFXInput.gyro[0] = (float)(axes_gyro.x * 0.001f);
mFXInput.gyro[1] = (float)(axes_gyro.y * 0.001f);
mFXInput.gyro[2] = (float)(axes_gyro.z * 0.001f);

// Magnetometer
mFXInput.mag[0] = 0.0f;
Expand All @@ -198,6 +182,13 @@ void vIMUMonitor(void *pv_params)
orientation_data.roll);
printf("IMU Temp: %3.2f °C \r\n", temperature_data.temp);
#endif
// printf("IMU Accel x: %d y: %d z: %d \r\n", accel_data.accel_x,
// accel_data.accel_y, accel_data.accel_z);
// printf("IMU Gyro x: %d y: %d z: %d \r\n", gyro_data.gyro_x,
// gyro_data.gyro_y, gyro_data.gyro_z);
// printf("IMU Orientation Yaw: %d Pitch: %d Roll: %d \r\n",
// orientation_data.yaw, orientation_data.pitch,
// orientation_data.roll);

/* convert to big endian */
endian_swap(&accel_data.accel_x, sizeof(accel_data.accel_x));
Expand Down Expand Up @@ -297,7 +288,6 @@ void vShockpotMonitor(void *pv_params)
uint16_t raw;
} shockpot_data;


for (;;) {
shockpot_read(&shock_value);

Expand All @@ -307,8 +297,8 @@ void vShockpotMonitor(void *pv_params)
//printf("Shock value:\t%ld\r\n", shock_value);

// convert to inches, get percent and multiply by 50 mm (stroke length) then convert to inches
float in = (shock_value / 4095.0) * 54.44 * (1/25.4);
float in = (shock_value / 4095.0) * 54.44 * (1 / 25.4);

shockpot_data.in = in;
endian_swap(&shockpot_data.in, sizeof(shockpot_data.in));
shockpot_data.raw = shock_value;
Expand Down
31 changes: 20 additions & 11 deletions Core/Src/msb.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ extern device_loc_t device_loc;

osMutexId_t i2c_mutex;

// reads imu reg

// overriden functions
int32_t lsm6dso_read_reg(stmdev_ctx_t *ctx, uint8_t reg, uint8_t *data,
uint16_t len)
{
Expand Down Expand Up @@ -65,11 +64,16 @@ int8_t msb_init()
assert(!LSM6DSO_Init(&imu)); /* This is always connected */

/* Setup IMU Accelerometer - default 104Hz */
LSM6DSO_ACC_SetOutputDataRate_With_Mode(
&imu, 833.0f, LSM6DSO_ACC_HIGH_PERFORMANCE_MODE);
LSM6DSO_ACC_Enable(&imu);
// 4=div100
LSM6DSO_ACC_Set_Filter_Mode(&imu, 0, 3);
/* Setup IMU Gyroscope */
LSM6DSO_GYRO_SetOutputDataRate_With_Mode(
&imu, 104.0f, LSM6DSO_GYRO_HIGH_PERFORMANCE_MODE);
LSM6DSO_GYRO_Enable(&imu);

LSM6DSO_ACC_Set_Filter_Mode(&imu, 0, 4);
// LSM6DSO_GYRO_Set_Filter_Mode(&imu, 0, 3);

LSM6DSO_FIFO_Set_Mode(&imu, 0);
LSM6DSO_ACC_Disable_Inactivity_Detection(&imu);
Expand Down Expand Up @@ -194,18 +198,23 @@ int8_t vcc5_en_write(bool status)
}

#ifdef SENSOR_IMU
int32_t imu_data_get(stmdev_ctx_t *ctx, stmdev_ctx_t *aux_ctx,
lsm6dso_md_t *imu_md_temp, lsm6dso_data_t *imu_data_temp)
int32_t imu_data_get_accel(LSM6DSO_Axes_t *axes)
{
osStatus_t mut_stat = osMutexAcquire(i2c_mutex, osWaitForever);
if (mut_stat)
return mut_stat;
HAL_StatusTypeDef hal_stat =
lsm6dso_data_get(ctx, aux_ctx, imu_md_temp, imu_data_temp);
HAL_StatusTypeDef hal_stat = LSM6DSO_ACC_GetAxes(&imu, axes);
osMutexRelease(i2c_mutex);
if (hal_stat)
return hal_stat;
return 0;
return hal_stat;
}
int32_t imu_data_get_gyro(LSM6DSO_Axes_t *axes)
{
osStatus_t mut_stat = osMutexAcquire(i2c_mutex, osWaitForever);
if (mut_stat)
return mut_stat;
HAL_StatusTypeDef hal_stat = LSM6DSO_GYRO_GetAxes(&imu, axes);
osMutexRelease(i2c_mutex);
return hal_stat;
}

void motion_fx_init(void)
Expand Down
2 changes: 1 addition & 1 deletion MSB-FW.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CAN1.CalculateBaudRate=500000
CAN1.CalculateTimeBit=2000
CAN1.CalculateTimeQuantum=142.85714285714286
CAN1.IPParameters=CalculateTimeQuantum,CalculateTimeBit,CalculateBaudRate,Prescaler,BS1,BS2,ABOM,NART
CAN1.NART=ENABLE
CAN1.NART=DISABLE
CAN1.Prescaler=6
Dma.ADC1.0.Direction=DMA_PERIPH_TO_MEMORY
Dma.ADC1.0.FIFOMode=DMA_FIFOMODE_DISABLE
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [4.5.0-RC5] date: [Fri May 30 20:32:44 EDT 2025]
# File automatically-generated by tool: [projectgenerator] version: [4.5.0-RC5] date: [Sat Jul 26 14:06:59 EDT 2025]
##########################################################################################################################

# ------------------------------------------------
Expand Down