/* * @file virtual_chassis_protocol.h * @brief 虚拟底盘通信协议定义 * @details 定义虚拟底盘与平衡底盘模块的CAN通信协议 */ #pragma once #ifdef __cplusplus extern "C" { #endif /* CAN通信协议定义 --------------------------------------------------------- */ /** * 控制命令CAN ID定义(控制端→底盘端) */ #define VIRTUAL_CHASSIS_CAN_CMD_ENABLE 121 // 关节电机使能命令 #define VIRTUAL_CHASSIS_CAN_CMD_JOINT 122 // 关节力矩控制命令 #define VIRTUAL_CHASSIS_CAN_CMD_WHEEL_LEFT 128 // 左轮控制命令 #define VIRTUAL_CHASSIS_CAN_CMD_WHEEL_RIGHT 129 // 右轮控制命令 /** * 反馈数据CAN ID定义(底盘端→控制端) */ #define VIRTUAL_CHASSIS_CAN_FEEDBACK_JOINT_0 124 // 关节电机0反馈 #define VIRTUAL_CHASSIS_CAN_FEEDBACK_JOINT_1 125 // 关节电机1反馈 #define VIRTUAL_CHASSIS_CAN_FEEDBACK_JOINT_2 126 // 关节电机2反馈 #define VIRTUAL_CHASSIS_CAN_FEEDBACK_JOINT_3 127 // 关节电机3反馈 #define VIRTUAL_CHASSIS_CAN_FEEDBACK_WHEEL_LEFT 130 // 左轮电机反馈 #define VIRTUAL_CHASSIS_CAN_FEEDBACK_WHEEL_RIGHT 131 // 右轮电机反馈 /** * IMU数据CAN ID定义(底盘端→控制端) */ #define VIRTUAL_CHASSIS_CAN_IMU_ACCL 0x301 // 加速度计数据 (769) #define VIRTUAL_CHASSIS_CAN_IMU_GYRO 0x302 // 陀螺仪数据 (770) #define VIRTUAL_CHASSIS_CAN_IMU_EULER 0x303 // 欧拉角数据 (771) #define VIRTUAL_CHASSIS_CAN_IMU_QUAT 0x304 // 四元数数据 (772) /* 数据格式定义 ----------------------------------------------------------- */ /** * 关节电机控制命令数据格式 (ID: 122) * 数据长度:8字节 * 格式:4个电机的力矩值,每个电机2字节有符号整数 * 精度:0.01 Nm * 范围:-327.68 ~ +327.67 Nm */ typedef struct { int16_t joint_torque[4]; // 关节电机目标力矩 * 100 } Virtual_Chassis_JointCommand_t; /** * 关节电机反馈数据格式 (ID: 124-127) * 数据长度:8字节 * 字节0-1:转矩电流 (精度0.01 Nm) * 字节2-4:位置 (精度0.0001 rad,24位有符号) * 字节5-7:速度 (精度0.001 rad/s,24位有符号) */ typedef struct { int16_t torque_current; // 转矩电流 * 100 int32_t position; // 位置 * 10000 (仅使用低24位) int32_t velocity; // 速度 * 1000 (仅使用低24位) } Virtual_Chassis_JointFeedback_t; /** * 轮子电机反馈数据格式 (ID: 130-131) * 数据长度:8字节 * 字节0-1:角度 (精度0.01度) * 字节2-3:速度 (精度1dps) * 字节4-5:力矩电流 * 字节6-7:编码器值 */ typedef struct { int16_t angle_deg; // 角度 * 100 (度) int16_t velocity_dps; // 速度 (度/秒) int16_t torque_current; // 力矩电流 uint16_t encoder; // 编码器值 } Virtual_Chassis_WheelFeedback_t; /** * 加速度计数据格式 (ID: 0x301) * 数据长度:6字节 * 精度:0.01g */ typedef struct { int16_t x; // X轴加速度 * 100 int16_t y; // Y轴加速度 * 100 int16_t z; // Z轴加速度 * 100 } Virtual_Chassis_AcclData_t; /** * 陀螺仪数据格式 (ID: 0x302) * 数据长度:6字节 * 精度:0.01°/s */ typedef struct { int16_t x; // X轴角速度 * 100 (°/s) int16_t y; // Y轴角速度 * 100 (°/s) int16_t z; // Z轴角速度 * 100 (°/s) } Virtual_Chassis_GyroData_t; /** * 欧拉角数据格式 (ID: 0x303) * 数据长度:6字节 * 精度:0.01° */ typedef struct { int16_t yaw; // 偏航角 * 100 (°) int16_t pitch; // 俯仰角 * 100 (°) int16_t roll; // 横滚角 * 100 (°) } Virtual_Chassis_EulerData_t; /** * 四元数数据格式 (ID: 0x304) * 数据长度:8字节 * 精度:1/32000 */ typedef struct { int16_t q0; // q0 * 32000 int16_t q1; // q1 * 32000 int16_t q2; // q2 * 32000 int16_t q3; // q3 * 32000 } Virtual_Chassis_QuatData_t; #ifdef __cplusplus } #endif