100 lines
1.8 KiB
C
100 lines
1.8 KiB
C
/*
|
||
* 自瞄模组
|
||
*/
|
||
|
||
#pragma once
|
||
|
||
#include "component\user_math.h"
|
||
#include "bsp\fdcan.h"
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
/* Includes ----------------------------------------------------------------- */
|
||
|
||
struct __attribute__((packed)) AI_ToHost
|
||
{
|
||
uint8_t head[2];
|
||
uint8_t mode; // 0: 空闲, 1: 自瞄, 2: 小符, 3: 大符
|
||
float q[4]; // wxyz顺序 /q4,q0,q1,q2/
|
||
float yaw;
|
||
float yaw_vel;
|
||
float pitch;
|
||
float pitch_vel;
|
||
float bullet_speed;
|
||
uint16_t bullet_count; // 子弹累计发送次数
|
||
uint16_t crc16;
|
||
};
|
||
|
||
struct __attribute__((packed)) AI_FromHost
|
||
{
|
||
uint8_t head[2];
|
||
uint8_t mode; // 0: 不控制, 1: 控制云台但不开火,2: 控制云台且开火
|
||
float yaw;
|
||
float yaw_vel;
|
||
float yaw_acc;
|
||
float pitch;
|
||
float pitch_vel;
|
||
float pitch_acc;
|
||
uint16_t crc16;
|
||
};
|
||
|
||
typedef struct {
|
||
uint8_t mode;
|
||
struct{
|
||
struct{
|
||
float yaw;
|
||
float pit;
|
||
}setpoint;
|
||
struct{
|
||
float pit;
|
||
float yaw;
|
||
}accl;
|
||
struct{
|
||
float pit;
|
||
float yaw;
|
||
}vel;
|
||
}gimbal;
|
||
|
||
}AI_cmd_t;
|
||
|
||
typedef struct {
|
||
uint8_t mode; // 0: 空闲, 1: 自瞄, 2: 小符, 3: 大符
|
||
float q[4]; // wxyz顺序 /q4,q0,q1,q2/
|
||
float yaw;
|
||
float yaw_vel;
|
||
float pitch;
|
||
float pitch_vel;
|
||
float bullet_speed;
|
||
uint16_t bullet_count; // 子弹累计发送次数
|
||
}AI_RawData_t;
|
||
|
||
typedef struct {
|
||
BSP_FDCAN_t can;
|
||
uint16_t vision_id;
|
||
}AI_Param_t;
|
||
|
||
typedef struct __attribute__((packed)) {
|
||
struct AI_ToHost tohost;
|
||
struct AI_FromHost fromhost;
|
||
AI_Param_t *param;
|
||
}AI_t;
|
||
|
||
|
||
int8_t AI_Init(AI_t *ai, AI_Param_t *param);
|
||
|
||
int8_t AI_StartReceiving(AI_t *ai);
|
||
|
||
int8_t AI_Get(AI_t *ai, AI_cmd_t* ai_cmd);
|
||
|
||
int8_t AI_ParseForHost(AI_t* ai, AI_RawData_t* raw_data);
|
||
|
||
int8_t AI_StartSend(AI_t *ai);
|
||
|
||
void AI_SendCmdOnCan(AI_t *ai, const AI_cmd_t *cmd);
|
||
|
||
void AI_ParseCmdFromCan(AI_t *ai, AI_cmd_t *cmd);
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|