84 lines
2.7 KiB
C
84 lines
2.7 KiB
C
/*
|
||
imu Task
|
||
|
||
*/
|
||
|
||
/* Includes ----------------------------------------------------------------- */
|
||
#include "task/user_task.h"
|
||
/* USER INCLUDE BEGIN */
|
||
#include "bsp/can.h"
|
||
#include "device/dm_imu.h"
|
||
#include "module/config.h"
|
||
#include <string.h>
|
||
/* USER INCLUDE END */
|
||
|
||
/* Private typedef ---------------------------------------------------------- */
|
||
/* Private define ----------------------------------------------------------- */
|
||
/* Private macro ------------------------------------------------------------ */
|
||
/* Private variables -------------------------------------------------------- */
|
||
/* USER STRUCT BEGIN */
|
||
DM_IMU_t dm_imu;
|
||
/* USER STRUCT END */
|
||
|
||
/* Private function --------------------------------------------------------- */
|
||
/* Exported functions ------------------------------------------------------- */
|
||
void Task_imu(void *argument) {
|
||
(void)argument; /* 未使用argument,消除警告 */
|
||
|
||
|
||
/* 计算任务运行到指定频率需要等待的tick数 */
|
||
const uint32_t delay_tick = osKernelGetTickFreq() / IMU_FREQ;
|
||
|
||
osDelay(IMU_INIT_DELAY); /* 延时一段时间再开启任务 */
|
||
|
||
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
|
||
/* USER CODE INIT BEGIN */
|
||
BSP_CAN_Init();
|
||
DM_IMU_Init(&dm_imu, &Config_GetRobotParam()->imu_param);
|
||
/* USER CODE INIT END */
|
||
|
||
while (1) {
|
||
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||
/* USER CODE BEGIN */
|
||
if (DM_IMU_AutoUpdateAll(&dm_imu) == DEVICE_OK) {
|
||
// 发送加速度计数据 (ID: 0x66) - 前8字节 (x, y)
|
||
BSP_CAN_StdDataFrame_t accl_frame = {
|
||
.id = 0x66,
|
||
.dlc = 8,
|
||
.data = {0}
|
||
};
|
||
memcpy(accl_frame.data, &dm_imu.data.accl, 8);
|
||
BSP_CAN_TransmitStdDataFrame(BSP_CAN_1, &accl_frame);
|
||
|
||
// 发送陀螺仪数据 (ID: 0x67) - 前8字节 (x, y)
|
||
BSP_CAN_StdDataFrame_t gyro_frame = {
|
||
.id = 0x67,
|
||
.dlc = 8,
|
||
.data = {0}
|
||
};
|
||
memcpy(gyro_frame.data, &dm_imu.data.gyro, 8);
|
||
BSP_CAN_TransmitStdDataFrame(BSP_CAN_1, &gyro_frame);
|
||
|
||
// 发送欧拉角数据 (ID: 0x68) - 前8字节 (yaw, pit)
|
||
BSP_CAN_StdDataFrame_t euler_frame = {
|
||
.id = 0x68,
|
||
.dlc = 8,
|
||
.data = {0}
|
||
};
|
||
memcpy(euler_frame.data, &dm_imu.data.euler, 8);
|
||
BSP_CAN_TransmitStdDataFrame(BSP_CAN_1, &euler_frame);
|
||
|
||
// // 发送四元数数据 (ID: 0x69) - 前8字节 (q0, q1)
|
||
// BSP_CAN_StdDataFrame_t quat_frame = {
|
||
// .id = 0x69,
|
||
// .dlc = 8,
|
||
// .data = {0}
|
||
// };
|
||
// memcpy(quat_frame.data, &dm_imu.data.quat, 8);
|
||
// BSP_CAN_TransmitStdDataFrame(BSP_CAN_1, &quat_frame);
|
||
}
|
||
/* USER CODE END */
|
||
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
||
}
|
||
|
||
} |