117 lines
3.3 KiB
C
117 lines
3.3 KiB
C
|
||
#pragma once
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
/* Includes ----------------------------------------------------------------- */
|
||
#include "component/user_math.h"
|
||
#include "remote_control.h"
|
||
#include "module/gimbal.h"
|
||
#include "device/referee.h"
|
||
#include "stdint.h"
|
||
|
||
// 数据包 ID 定义
|
||
#define ID_MCU (0xC4) // MCU 数据包
|
||
#define ID_REF (0xA8) // 裁判系统数据包
|
||
#define ID_AI (0xB5) // AI 控制数据包
|
||
|
||
// MCU 数据结构(MCU -> 上位机)
|
||
typedef struct __attribute__((packed))
|
||
{
|
||
uint8_t mode; // 0: 空闲, 1: 自瞄, 2: 小符, 3: 大符
|
||
float q[4]; // 四元数 wxyz 顺序
|
||
float yaw; // 偏航角
|
||
float yaw_vel; // 偏航角速度
|
||
float pitch; // 俯仰角
|
||
float pitch_vel; // 俯仰角速度
|
||
float bullet_speed; // 弹速
|
||
uint16_t bullet_count; // 子弹累计发送次数
|
||
} DataMCU_t;
|
||
|
||
typedef struct __attribute__((packed))
|
||
{
|
||
uint8_t id; // 数据包 ID: 0xC4
|
||
DataMCU_t data;
|
||
uint16_t crc16;
|
||
} PackageMCU_t;
|
||
|
||
// 裁判系统数据结构
|
||
typedef struct __attribute__((packed))
|
||
{
|
||
uint16_t remain_hp; // 剩余血量
|
||
uint8_t game_progress : 4; // 比赛进度
|
||
uint16_t stage_remain_time; // 比赛剩余时间
|
||
} DataReferee_t;
|
||
|
||
typedef struct __attribute__((packed))
|
||
{
|
||
uint8_t id; // 数据包 ID: 0xA8
|
||
DataReferee_t data;
|
||
uint16_t crc16;
|
||
} PackageReferee_t;
|
||
|
||
// AI 控制数据结构(上位机 -> MCU)
|
||
typedef struct __attribute__((packed))
|
||
{
|
||
uint8_t mode; // 0: 不控制, 1: 控制云台但不开火, 2: 控制云台且开火
|
||
float yaw; // 目标偏航角
|
||
float yaw_vel; // 偏航角速度
|
||
float yaw_acc; // 偏航角加速度
|
||
float pitch; // 目标俯仰角
|
||
float pitch_vel; // 俯仰角速度
|
||
float pitch_acc; // 俯仰角加速度
|
||
float vx; // X 方向速度
|
||
float vy; // Y 方向速度
|
||
float wz; // Z 方向角速度
|
||
uint8_t reserved; // 预留字段
|
||
} DataAI_t;
|
||
|
||
typedef struct __attribute__((packed))
|
||
{
|
||
uint8_t id; // 数据包 ID: 0xB5
|
||
DataAI_t data;
|
||
uint16_t crc16;
|
||
} PackageAI_t;
|
||
|
||
typedef struct __attribute__((packed)) {
|
||
uint8_t mode; // 0: 不控制, 1: 控制云台但不开火, 2: 控制云台且开火
|
||
struct{
|
||
// Gimbal_CMD_t g_cmd;
|
||
struct{
|
||
float yaw; // 目标偏航角
|
||
float pit; // 目标俯仰角
|
||
}setpoint;
|
||
|
||
struct{
|
||
float pit; // 俯仰角加速度
|
||
float yaw; // 偏航角加速度
|
||
}accl;
|
||
struct{
|
||
float pit; // 俯仰角速度
|
||
float yaw; // 偏航角速度
|
||
}vel;
|
||
}gimbal_t;
|
||
|
||
struct{
|
||
float Vx; // X 方向速度
|
||
float Vy; // Y 方向速度
|
||
float Vw; // Z 方向角速度
|
||
}chassis_t;
|
||
|
||
uint8_t reserved; // 预留字段
|
||
}AI_result_t; //接收到的所有数据,来自NUC
|
||
|
||
|
||
int8_t AI_Init(void);
|
||
int8_t AI_GetLatest(AI_result_t *result);
|
||
int8_t MCU_Send(PackageMCU_t* mcu,Gimbal_feedback_t* motor,AHRS_Quaternion_t* quat);
|
||
int8_t REF_Send(PackageReferee_t *referee,Referee_RobotStatus_t* robot_status,Referee_GameStatus_t *game_status);
|
||
int8_t REF_StartSend(PackageReferee_t *referee);
|
||
int8_t MCU_StartSend(PackageMCU_t *mcu);
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|