101 lines
2.5 KiB
C
101 lines
2.5 KiB
C
/*
|
|
AI
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <sys/cdefs.h>
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* Includes ----------------------------------------------------------------- */
|
|
#include "component/ahrs.h"
|
|
#include "component/filter.h"
|
|
#include "component/user_math.h"
|
|
#include "device/device.h"
|
|
#include <cmsis_os2.h>
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
/* Exported constants ------------------------------------------------------- */
|
|
/* Exported macro ----------------------------------------------------------- */
|
|
#define AI_ID_MCU (0xC4)
|
|
#define AI_ID_REF (0xA8)
|
|
#define AI_ID_AI (0xA1)
|
|
/* Exported types ----------------------------------------------------------- */
|
|
|
|
/* 电控 -> 视觉 MCU数据结构体*/
|
|
typedef struct __packed {
|
|
AHRS_Quaternion_t quat; /* 四元数 */
|
|
uint8_t notice; /* 控制命令 */
|
|
} AI_Protucol_UpDataMCU_t;
|
|
|
|
/* 电控 -> 视觉 裁判系统数据结构体*/
|
|
typedef struct __packed {
|
|
uint16_t team; /* 本身队伍 */
|
|
uint16_t time; /* 比赛开始时间 */
|
|
} AI_Protocol_UpDataReferee_t;
|
|
|
|
/* 电控 -> 视觉 数据包结构体*/
|
|
typedef struct __packed {
|
|
AHRS_Eulr_t eulr; /* 欧拉角 */
|
|
MoveVector_t move_vec; /* 运动向量 */
|
|
uint8_t notice; /* 控制命令 */
|
|
} AI_Protocol_DownData_t;
|
|
|
|
/* 电控 -> 视觉 裁判系统数据包 */
|
|
typedef struct __packed {
|
|
uint8_t id; /* 包ID */
|
|
AI_Protocol_UpDataReferee_t package; /* 数据包 */
|
|
uint16_t crc16; /* CRC16校验 */
|
|
} AI_UpPackageReferee_t;
|
|
|
|
/* 电控 -> 视觉 MUC数据包 */
|
|
typedef struct __packed {
|
|
uint8_t id;
|
|
AI_Protucol_UpDataMCU_t package;
|
|
uint16_t crc16;
|
|
} AI_UpPackageMCU_t;
|
|
|
|
/* 视觉 -> 电控 数据包 */
|
|
typedef struct __packed {
|
|
uint8_t id; /* 包ID */
|
|
AI_Protocol_DownData_t package; /* 数据包 */
|
|
uint16_t crc16; /* CRC16校验 */
|
|
} AI_DownPackage_t;
|
|
|
|
typedef struct __packed {
|
|
DEVICE_Header_t header; /* 设备通用头部 */
|
|
AI_DownPackage_t from_host;
|
|
struct {
|
|
AI_UpPackageReferee_t ref;
|
|
AI_UpPackageMCU_t mcu;
|
|
} to_host;
|
|
} AI_t;
|
|
|
|
/* Exported functions prototypes -------------------------------------------- */
|
|
|
|
int8_t AI_Init(AI_t *ai);
|
|
|
|
int8_t AI_Restart(AI_t *ai);
|
|
|
|
int8_t AI_StartReceiving(AI_t *ai);
|
|
|
|
bool AI_WaitDmaCplt(uint32_t timeout);
|
|
|
|
int8_t AI_ParseHost(AI_t *ai);
|
|
|
|
int8_t AI_PackMCU(AI_t *ai, const AI_Protucol_UpDataMCU_t *data);
|
|
|
|
int8_t AI_PackRef(AI_t *ai, const AI_UpPackageReferee_t *data);
|
|
|
|
int8_t AI_HandleOffline(AI_t *ai);
|
|
|
|
int8_t AI_StartSend(AI_t *ai, bool ref_online);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|