rm_balance/User/device/gimbal_imu.h
2026-01-11 23:22:12 +08:00

89 lines
2.4 KiB
C

/*
* Gimbal IMU Device - 接收来自云台的CAN IMU数据
*/
#pragma once
#include <math.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ----------------------------------------------------------------- */
#include <stdbool.h>
#include <stdint.h>
#include "bsp/can.h"
#include "component/ahrs.h"
#include "device/device.h"
/* Exported constants ------------------------------------------------------- */
/* 数据范围定义(与发送端保持一致) */
#define GIMBAL_IMU_ACCEL_MAX (58.8f)
#define GIMBAL_IMU_ACCEL_MIN (-58.8f)
#define GIMBAL_IMU_GYRO_MAX (34.88f)
#define GIMBAL_IMU_GYRO_MIN (-34.88f)
#define GIMBAL_IMU_PITCH_MAX (90.0f)
#define GIMBAL_IMU_PITCH_MIN (-90.0f)
#define GIMBAL_IMU_ROLL_MAX (180.0f)
#define GIMBAL_IMU_ROLL_MIN (-180.0f)
#define GIMBAL_IMU_YAW_MAX (180.0f)
#define GIMBAL_IMU_YAW_MIN (-180.0f)
#define GIMBAL_IMU_QUAT_MIN (-1.0f)
#define GIMBAL_IMU_QUAT_MAX (1.0f)
/* Exported macro ----------------------------------------------------------- */
/* Exported types ----------------------------------------------------------- */
/* Gimbal IMU参数配置 */
typedef struct {
BSP_CAN_t can; /* 使用的CAN总线 */
uint16_t accl_id;
uint16_t gyro_id;
uint16_t eulr_id;
uint16_t quat_id;
} GIMBAL_IMU_Param_t;
typedef struct {
AHRS_Accl_t accl; /* 加速度计数据 */
AHRS_Gyro_t gyro; /* 陀螺仪数据 */
AHRS_Eulr_t eulr; /* 欧拉角数据 */
AHRS_Quaternion_t quat; /* 四元数数据 */
float temp; /* 温度数据 (摄氏度) */
} GIMBAL_IMU_Data_t;
/* Gimbal IMU完整数据结构 */
typedef struct {
DEVICE_Header_t header;
GIMBAL_IMU_Param_t param; /* 参数配置 */
GIMBAL_IMU_Data_t data; /* IMU数据 */
} GIMBAL_IMU_t;
/* Exported functions prototypes -------------------------------------------- */
/**
* @brief 初始化Gimbal IMU设备
* @param gimbal_imu Gimbal IMU结构体指针
* @param param 参数配置
* @return 初始化结果
* - DEVICE_OK: 成功
* - DEVICE_ERR_NULL: 参数为空
*/
int8_t GIMBAL_IMU_Init(GIMBAL_IMU_t *gimbal_imu, const GIMBAL_IMU_Param_t *param);
/**
* @brief 更新Gimbal IMU设备状态
* @param gimbal_imu Gimbal IMU结构体指针
* @return 更新结果
* - DEVICE_OK: 成功
* - DEVICE_ERR_NULL: 参数为空
*/
int8_t GIMBAL_IMU_Update(GIMBAL_IMU_t *gimbal_imu);
#ifdef __cplusplus
}
#endif