小自瞄
This commit is contained in:
parent
9e763bae27
commit
6c7e02f5c7
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"user_math.h": "c"
|
||||||
|
}
|
||||||
|
}
|
@ -407,6 +407,11 @@
|
|||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>rc</ItemText>
|
<ItemText>rc</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>10</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>cmd_host</ItemText>
|
||||||
|
</Ww>
|
||||||
</WatchWindow1>
|
</WatchWindow1>
|
||||||
<Tracepoint>
|
<Tracepoint>
|
||||||
<THDelay>0</THDelay>
|
<THDelay>0</THDelay>
|
||||||
@ -658,7 +663,7 @@
|
|||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
<GroupName>Application/User/USB_DEVICE/App</GroupName>
|
<GroupName>Application/User/USB_DEVICE/App</GroupName>
|
||||||
<tvExp>1</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<cbSel>0</cbSel>
|
<cbSel>0</cbSel>
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
@ -1214,7 +1219,7 @@
|
|||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
<GroupName>Middlewares/USB_Device_Library</GroupName>
|
<GroupName>Middlewares/USB_Device_Library</GroupName>
|
||||||
<tvExp>1</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<cbSel>0</cbSel>
|
<cbSel>0</cbSel>
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
@ -1494,7 +1499,7 @@
|
|||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
<GroupName>User/component</GroupName>
|
<GroupName>User/component</GroupName>
|
||||||
<tvExp>1</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<cbSel>0</cbSel>
|
<cbSel>0</cbSel>
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
@ -1670,7 +1675,7 @@
|
|||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
<GroupName>User/device</GroupName>
|
<GroupName>User/device</GroupName>
|
||||||
<tvExp>1</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<cbSel>0</cbSel>
|
<cbSel>0</cbSel>
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
@ -1750,7 +1755,7 @@
|
|||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
<GroupName>User/module</GroupName>
|
<GroupName>User/module</GroupName>
|
||||||
<tvExp>1</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<cbSel>0</cbSel>
|
<cbSel>0</cbSel>
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
|
Binary file not shown.
18492
MDK-ARM/DevC/DevC.hex
18492
MDK-ARM/DevC/DevC.hex
File diff suppressed because it is too large
Load Diff
4
Middlewares/Third_Party/Protocol/protocol.h
vendored
4
Middlewares/Third_Party/Protocol/protocol.h
vendored
@ -14,6 +14,7 @@ extern "C" {
|
|||||||
#define AI_NOTICE_HITBUFF (1 << 1)
|
#define AI_NOTICE_HITBUFF (1 << 1)
|
||||||
#define AI_NOTICE_AUTOMATIC (1 << 2)
|
#define AI_NOTICE_AUTOMATIC (1 << 2)
|
||||||
#define AI_NOTICE_FIRE (1 << 3)
|
#define AI_NOTICE_FIRE (1 << 3)
|
||||||
|
#define AI_NOTICE_TRACKING (1 << 4)
|
||||||
|
|
||||||
#define AI_ID_MCU (0xC4)
|
#define AI_ID_MCU (0xC4)
|
||||||
#define AI_ID_REF (0xA8)
|
#define AI_ID_REF (0xA8)
|
||||||
@ -53,13 +54,14 @@ typedef struct __attribute__((packed)) {
|
|||||||
|
|
||||||
/* 视觉 -> 电控 数据结构体*/
|
/* 视觉 -> 电控 数据结构体*/
|
||||||
typedef struct __attribute__((packed)) {
|
typedef struct __attribute__((packed)) {
|
||||||
|
|
||||||
struct __attribute__((packed)) {
|
struct __attribute__((packed)) {
|
||||||
float yaw; /* 偏航角(Yaw angle) */
|
float yaw; /* 偏航角(Yaw angle) */
|
||||||
float pit; /* 俯仰角(Pitch angle) */
|
float pit; /* 俯仰角(Pitch angle) */
|
||||||
float rol; /* 翻滚角(Roll angle) */
|
float rol; /* 翻滚角(Roll angle) */
|
||||||
} gimbal; /* 欧拉角 */
|
} gimbal; /* 欧拉角 */
|
||||||
|
|
||||||
float distance; /* 距离 */
|
float distance; /*目标距离*/
|
||||||
uint8_t notice; /* 控制命令 */
|
uint8_t notice; /* 控制命令 */
|
||||||
|
|
||||||
struct __attribute__((packed)) {
|
struct __attribute__((packed)) {
|
||||||
|
@ -10,3 +10,4 @@ void Ballistics_Apply(Ballistics_t *b, float bullet_speed) {
|
|||||||
(void)bullet_speed;
|
(void)bullet_speed;
|
||||||
}
|
}
|
||||||
void Ballistics_Reset(Ballistics_t *b) { (void)b; }
|
void Ballistics_Reset(Ballistics_t *b) { (void)b; }
|
||||||
|
|
||||||
|
@ -192,12 +192,14 @@ static void CMD_RcLogic(const CMD_RC_t *rc, CMD_t *cmd, float dt_sec) {
|
|||||||
cmd->chassis.mode = CHASSIS_MODE_BREAK;
|
cmd->chassis.mode = CHASSIS_MODE_BREAK;
|
||||||
cmd->host_overwrite = false;
|
cmd->host_overwrite = false;
|
||||||
cmd->shoot.ai_fire = false;
|
cmd->shoot.ai_fire = false;
|
||||||
|
cmd->ai_status = AI_STATUS_STOP;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_SW_MID:
|
case CMD_SW_MID:
|
||||||
cmd->chassis.mode = CHASSIS_MODE_FOLLOW_GIMBAL;
|
cmd->chassis.mode = CHASSIS_MODE_FOLLOW_GIMBAL;
|
||||||
cmd->host_overwrite = true;
|
cmd->host_overwrite = true;
|
||||||
cmd->shoot.ai_fire = false;
|
cmd->shoot.ai_fire = false;
|
||||||
|
cmd->ai_status = AI_STATUS_AUTOMATIC;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_SW_DOWN:
|
case CMD_SW_DOWN:
|
||||||
@ -205,12 +207,14 @@ static void CMD_RcLogic(const CMD_RC_t *rc, CMD_t *cmd, float dt_sec) {
|
|||||||
cmd->chassis.mode_rotor = ROTOR_MODE_CW;
|
cmd->chassis.mode_rotor = ROTOR_MODE_CW;
|
||||||
cmd->host_overwrite = true;
|
cmd->host_overwrite = true;
|
||||||
cmd->shoot.ai_fire = true;
|
cmd->shoot.ai_fire = true;
|
||||||
|
cmd->ai_status = AI_STATUS_AUTOMATIC;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_SW_ERR:
|
case CMD_SW_ERR:
|
||||||
cmd->chassis.mode = CHASSIS_MODE_RELAX;
|
cmd->chassis.mode = CHASSIS_MODE_RELAX;
|
||||||
cmd->host_overwrite = false;
|
cmd->host_overwrite = false;
|
||||||
cmd->shoot.ai_fire = false;
|
cmd->shoot.ai_fire = false;
|
||||||
|
cmd->ai_status = AI_STATUS_STOP;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (rc->sw_r) {
|
switch (rc->sw_r) {
|
||||||
@ -221,7 +225,7 @@ static void CMD_RcLogic(const CMD_RC_t *rc, CMD_t *cmd, float dt_sec) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_SW_MID:
|
case CMD_SW_MID:
|
||||||
cmd->gimbal.mode = GIMBAL_MODE_SEARCH;
|
cmd->gimbal.mode = GIMBAL_MODE_ABSOLUTE;
|
||||||
cmd->shoot.fire = false;
|
cmd->shoot.fire = false;
|
||||||
cmd->shoot.mode = SHOOT_MODE_LOADED;
|
cmd->shoot.mode = SHOOT_MODE_LOADED;
|
||||||
break;
|
break;
|
||||||
@ -360,7 +364,7 @@ int8_t CMD_ParseHost(const CMD_Host_t *host, CMD_t *cmd, float dt_sec) {
|
|||||||
if (host->fire && cmd->shoot.ai_fire) {
|
if (host->fire && cmd->shoot.ai_fire) {
|
||||||
cmd->shoot.fire = true;
|
cmd->shoot.fire = true;
|
||||||
} else {
|
} else {
|
||||||
cmd->shoot.fire = false;
|
cmd->shoot.fire = true;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -112,3 +112,17 @@ inline float CalculateRpm(float bullet_speed, float fric_radius, bool is17mm) {
|
|||||||
/* 不为裁判系统设定值时,计算转速 */
|
/* 不为裁判系统设定值时,计算转速 */
|
||||||
return 60.0f * (float)bullet_speed / (M_2PI * fric_radius);
|
return 60.0f * (float)bullet_speed / (M_2PI * fric_radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 断言失败处理
|
||||||
|
*
|
||||||
|
* @param file 文件名
|
||||||
|
* @param line 行号
|
||||||
|
*/
|
||||||
|
void VerifyFailed(const char *file, uint32_t line) {
|
||||||
|
UNUSED(file);
|
||||||
|
UNUSED(line);
|
||||||
|
while (1) {
|
||||||
|
__NOP();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -104,3 +104,53 @@ float CalculateRpm(float bullet_speed, float fric_radius, bool is17mm);
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 如果表达式的值为假则运行处理函数
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define ASSERT(expr) \
|
||||||
|
do { \
|
||||||
|
if (!(expr)) { \
|
||||||
|
VerifyFailed(__FILE__, __LINE__); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#else
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 未定DEBUG,表达式不会运行,断言被忽略
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define ASSERT(expr) ((void)(0))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 如果表达式的值为假则运行处理函数
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define VERIFY(expr) \
|
||||||
|
do { \
|
||||||
|
if (!(expr)) { \
|
||||||
|
VerifyFailed(__FILE__, __LINE__); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#else
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 表达式会运行,忽略表达式结果
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define VERIFY(expr) ((void)(expr))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 断言失败处理
|
||||||
|
*
|
||||||
|
* @param file 文件名
|
||||||
|
* @param line 行号
|
||||||
|
*/
|
||||||
|
void VerifyFailed(const char *file, uint32_t line);
|
||||||
|
@ -12,34 +12,51 @@
|
|||||||
#include "component\crc16.h"
|
#include "component\crc16.h"
|
||||||
#include "component\crc8.h"
|
#include "component\crc8.h"
|
||||||
#include "component\user_math.h"
|
#include "component\user_math.h"
|
||||||
|
#include "component\filter.h"
|
||||||
|
|
||||||
|
|
||||||
/* Private define ----------------------------------------------------------- */
|
/* Private define ----------------------------------------------------------- */
|
||||||
|
#define AI_HOST_MAX_CONTROL_VALUE (0.001f)
|
||||||
|
|
||||||
|
#define AI_LEN_RX_BUFF (sizeof(Protocol_DownPackage_t))
|
||||||
|
|
||||||
/* Private macro ------------------------------------------------------------ */
|
/* Private macro ------------------------------------------------------------ */
|
||||||
/* Private typedef ---------------------------------------------------------- */
|
/* Private typedef ---------------------------------------------------------- */
|
||||||
/* Private variables -------------------------------------------------------- */
|
/* Private variables -------------------------------------------------------- */
|
||||||
static volatile uint32_t drop_message = 0;
|
static volatile uint32_t drop_message = 0;
|
||||||
|
|
||||||
|
static uint8_t rxbuf[AI_LEN_RX_BUFF];
|
||||||
|
|
||||||
static osThreadId_t thread_alert;
|
static osThreadId_t thread_alert;
|
||||||
|
|
||||||
static bool inited = false;
|
static bool inited = false;
|
||||||
|
|
||||||
|
static LowPassFilter2p_t low_pass_filter;
|
||||||
|
|
||||||
/* Private function -------------------------------------------------------- */
|
/* Private function -------------------------------------------------------- */
|
||||||
|
|
||||||
static void Ai_RxCpltCallback(void) {
|
static void Ai_RxCpltCallback(void) {
|
||||||
osThreadFlagsSet(thread_alert, SIGNAL_AI_RAW_REDY);
|
osThreadFlagsSet(thread_alert, SIGNAL_AI_RAW_REDY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void Ai_IdleLineCallback(void) {
|
||||||
|
osThreadFlagsSet(thread_alert, SIGNAL_AI_RAW_REDY);
|
||||||
|
}
|
||||||
|
|
||||||
/* Exported functions ------------------------------------------------------- */
|
/* Exported functions ------------------------------------------------------- */
|
||||||
int8_t AI_Init(AI_t *ai) {
|
int8_t AI_Init(AI_t *ai) {
|
||||||
if (ai == NULL) return DEVICE_ERR_NULL;
|
UNUSED(ai);
|
||||||
|
ASSERT(ai);
|
||||||
if (inited) return DEVICE_ERR_INITED;
|
if (inited) return DEVICE_ERR_INITED;
|
||||||
if ((thread_alert = osThreadGetId()) == NULL) return DEVICE_ERR_NULL;
|
VERIFY((thread_alert = osThreadGetId()) != NULL);
|
||||||
|
|
||||||
BSP_UART_RegisterCallback(BSP_UART_AI, BSP_UART_RX_CPLT_CB,
|
BSP_UART_RegisterCallback(BSP_UART_AI, BSP_UART_RX_CPLT_CB,
|
||||||
Ai_RxCpltCallback);
|
Ai_RxCpltCallback);
|
||||||
inited = true;
|
BSP_UART_RegisterCallback(BSP_UART_AI, BSP_UART_IDLE_LINE_CB,
|
||||||
|
Ai_IdleLineCallback);
|
||||||
|
LowPassFilter2p_Init(&low_pass_filter, 1000.0f, 5.0f); // 示例参数
|
||||||
|
|
||||||
ai->ai_online = false;
|
inited = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,9 +67,9 @@ int8_t AI_Restart(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int8_t AI_StartReceiving(AI_t *ai) {
|
int8_t AI_StartReceiving(AI_t *ai) {
|
||||||
if (HAL_UART_Receive_DMA(BSP_UART_GetHandle(BSP_UART_AI),
|
UNUSED(ai);
|
||||||
ai->form_host.rx_buffer,
|
if (HAL_UART_Receive_DMA(BSP_UART_GetHandle(BSP_UART_AI), rxbuf,
|
||||||
sizeof(ai->form_host.rx_buffer)) == HAL_OK)
|
AI_LEN_RX_BUFF) == HAL_OK)
|
||||||
return DEVICE_OK;
|
return DEVICE_OK;
|
||||||
return DEVICE_ERR;
|
return DEVICE_ERR;
|
||||||
}
|
}
|
||||||
@ -62,31 +79,19 @@ bool AI_WaitDmaCplt(void) {
|
|||||||
SIGNAL_AI_RAW_REDY);
|
SIGNAL_AI_RAW_REDY);
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t AI_ParseHost(AI_t *ai, CMD_Host_t *cmd_host) {
|
int8_t AI_ParseHost(AI_t *ai) {
|
||||||
(void)cmd_host;
|
if (!CRC16_Verify((const uint8_t *)&(rxbuf), sizeof(ai->form_host)))
|
||||||
ai->ai_online = true;
|
|
||||||
if (!CRC16_Verify(ai->form_host.rx_buffer, sizeof(ai->form_host.rx_buffer)))
|
|
||||||
goto error;
|
goto error;
|
||||||
memcpy(&(ai->form_host.DownPackage), ai->form_host.rx_buffer, sizeof(ai->form_host.DownPackage));
|
ai->ai_online = true;
|
||||||
// cmd_host->gimbal_delta.pit = ai->form_host.data.gimbal.pit;
|
|
||||||
// cmd_host->gimbal_delta.yaw = ai->form_host.data.gimbal.yaw;
|
|
||||||
// cmd_host->gimbal_delta.rol = ai->form_host.data.gimbal.rol;
|
|
||||||
// cmd_host->fire = (ai->form_host.data.notice & AI_NOTICE_FIRE);
|
|
||||||
// cmd_host->chassis_move_vec.vx = ai->form_host.data.chassis_move_vec.vx;
|
|
||||||
// cmd_host->chassis_move_vec.vy = ai->form_host.data.chassis_move_vec.vy;
|
|
||||||
// cmd_host->chassis_move_vec.wz = ai->form_host.data.chassis_move_vec.wz;
|
|
||||||
// float yaw_out = PID_Calc(&ai->pid[0], 0.0f, ai->form_host.DownPackage.data.gimbal.yaw, 0.0f , 1.0/10.0f);
|
|
||||||
// float pit_out = PID_Calc(&ai->pid[1], 0.0f, ai->form_host.DownPackage.data.gimbal.pit, 0.0f , 1.0/10.0f);
|
|
||||||
cmd_host->gimbal_delta.pit = ai->form_host.DownPackage.data.gimbal.pit;
|
|
||||||
cmd_host->gimbal_delta.yaw = ai->form_host.DownPackage.data.gimbal.yaw;
|
|
||||||
// cmd_host->gimbal_delta.pit = pit_out;
|
|
||||||
// cmd_host->gimbal_delta.yaw = yaw_out;
|
|
||||||
cmd_host->gimbal_delta.rol = ai->form_host.DownPackage.data.gimbal.rol;
|
|
||||||
cmd_host->fire = (ai->form_host.DownPackage.data.notice & AI_NOTICE_FIRE);
|
|
||||||
cmd_host->chassis_move_vec.vx = ai->form_host.DownPackage.data.chassis_move_vec.vx;
|
|
||||||
cmd_host->chassis_move_vec.vy = ai->form_host.DownPackage.data.chassis_move_vec.vy;
|
|
||||||
cmd_host->chassis_move_vec.wz = ai->form_host.DownPackage.data.chassis_move_vec.wz;
|
|
||||||
|
|
||||||
|
// 对接收到的数据进行滤波处理
|
||||||
|
for (size_t i = 0; i < sizeof(ai->form_host.data.gimbal); ++i) {
|
||||||
|
((float*)&ai->form_host.data.gimbal)[i] =
|
||||||
|
LowPassFilter2p_Apply(&low_pass_filter, ((float*)&ai->form_host.data.gimbal)[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(&(ai->form_host), rxbuf, sizeof(ai->form_host));
|
||||||
|
memset(rxbuf, 0, AI_LEN_RX_BUFF);
|
||||||
return DEVICE_OK;
|
return DEVICE_OK;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
@ -94,12 +99,27 @@ error:
|
|||||||
return DEVICE_ERR;
|
return DEVICE_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AI_PackCmd(AI_t *ai, CMD_Host_t *cmd_host) {
|
||||||
|
cmd_host->gimbal_delta.yaw = -ai->form_host.data.gimbal.yaw;
|
||||||
|
// cmd_host->gimbal_delta.yaw = cmd_host->gimbal_delta.yaw - 0.00015;
|
||||||
|
cmd_host->gimbal_delta.pit = -ai->form_host.data.gimbal.pit;
|
||||||
|
cmd_host->gimbal_delta.pit = cmd_host->gimbal_delta.pit + 0.0002;
|
||||||
|
Clip(&(cmd_host->gimbal_delta.yaw), -AI_HOST_MAX_CONTROL_VALUE,
|
||||||
|
AI_HOST_MAX_CONTROL_VALUE);
|
||||||
|
Clip(&(cmd_host->gimbal_delta.pit), -AI_HOST_MAX_CONTROL_VALUE,
|
||||||
|
AI_HOST_MAX_CONTROL_VALUE);
|
||||||
|
|
||||||
|
cmd_host->fire = (ai->form_host.data.notice & AI_NOTICE_FIRE);
|
||||||
|
cmd_host->chassis_move_vec.vx = ai->form_host.data.chassis_move_vec.vx;
|
||||||
|
cmd_host->chassis_move_vec.vy = ai->form_host.data.chassis_move_vec.vy;
|
||||||
|
cmd_host->chassis_move_vec.wz = ai->form_host.data.chassis_move_vec.wz;
|
||||||
|
}
|
||||||
|
|
||||||
int8_t AI_HandleOffline(AI_t *ai, CMD_Host_t *cmd_host) {
|
int8_t AI_HandleOffline(AI_t *ai, CMD_Host_t *cmd_host) {
|
||||||
if (ai == NULL) return DEVICE_ERR_NULL;
|
if (ai == NULL) return DEVICE_ERR_NULL;
|
||||||
if (cmd_host == NULL) return DEVICE_ERR_NULL;
|
if (cmd_host == NULL) return DEVICE_ERR_NULL;
|
||||||
ai->ai_online = false;
|
ai->ai_online = false;
|
||||||
memset(ai->form_host.rx_buffer, 0, sizeof(ai->form_host.rx_buffer));
|
memset(&(ai->form_host), 0, sizeof(ai->form_host));
|
||||||
memset(&(ai->form_host.DownPackage), 0, sizeof(ai->form_host.DownPackage));
|
|
||||||
memset(cmd_host, 0, sizeof(*cmd_host));
|
memset(cmd_host, 0, sizeof(*cmd_host));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ extern "C" {
|
|||||||
#include "component\ahrs.h"
|
#include "component\ahrs.h"
|
||||||
#include "component\cmd.h"
|
#include "component\cmd.h"
|
||||||
#include "component\user_math.h"
|
#include "component\user_math.h"
|
||||||
|
#include "component\filter.h"
|
||||||
#include "device\device.h"
|
#include "device\device.h"
|
||||||
#include "device\referee.h"
|
#include "device\referee.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
@ -36,10 +37,8 @@ typedef struct __packed {
|
|||||||
|
|
||||||
typedef struct __packed {
|
typedef struct __packed {
|
||||||
osThreadId_t thread_alert;
|
osThreadId_t thread_alert;
|
||||||
struct {
|
|
||||||
uint8_t rx_buffer[sizeof(Protocol_DownPackage_t)];
|
Protocol_DownPackage_t form_host;
|
||||||
Protocol_DownPackage_t DownPackage;
|
|
||||||
}form_host;
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
AI_UpPackageReferee_t ref;
|
AI_UpPackageReferee_t ref;
|
||||||
@ -47,7 +46,6 @@ typedef struct __packed {
|
|||||||
} to_host;
|
} to_host;
|
||||||
|
|
||||||
CMD_AI_Status_t status;
|
CMD_AI_Status_t status;
|
||||||
|
|
||||||
bool ai_online;
|
bool ai_online;
|
||||||
} AI_t;
|
} AI_t;
|
||||||
|
|
||||||
@ -57,11 +55,12 @@ int8_t AI_Restart(void);
|
|||||||
|
|
||||||
int8_t AI_StartReceiving(AI_t *ai);
|
int8_t AI_StartReceiving(AI_t *ai);
|
||||||
bool AI_WaitDmaCplt(void);
|
bool AI_WaitDmaCplt(void);
|
||||||
int8_t AI_ParseHost(AI_t *ai, CMD_Host_t *cmd_host);
|
int8_t AI_ParseHost(AI_t *ai);
|
||||||
int8_t AI_HandleOffline(AI_t *ai, CMD_Host_t *cmd_host);
|
int8_t AI_HandleOffline(AI_t *ai, CMD_Host_t *cmd_host);
|
||||||
int8_t AI_PackMCU(AI_t *ai, const AHRS_Quaternion_t *quat);
|
int8_t AI_PackMCU(AI_t *ai, const AHRS_Quaternion_t *quat);
|
||||||
int8_t AI_PackRef(AI_t *ai, const Referee_ForAI_t *ref);
|
int8_t AI_PackRef(AI_t *ai, const Referee_ForAI_t *ref);
|
||||||
int8_t AI_StartSend(AI_t *ai, bool option);
|
int8_t AI_StartSend(AI_t *ai, bool option);
|
||||||
|
void AI_PackCmd(AI_t *ai, CMD_Host_t *cmd_host);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -191,7 +191,7 @@ static const Config_RobotParam_t param_default = {
|
|||||||
.cover_close_duty = 0.050f,
|
.cover_close_duty = 0.050f,
|
||||||
.model = SHOOT_MODEL_17MM,
|
.model = SHOOT_MODEL_17MM,
|
||||||
.bullet_speed = 30.f,
|
.bullet_speed = 30.f,
|
||||||
.min_shoot_delay = (uint32_t)(1000.0f / 10.0f),
|
.min_shoot_delay = (uint32_t)(1000.0f / 5.0f),
|
||||||
}, /* shoot */
|
}, /* shoot */
|
||||||
|
|
||||||
.can = {
|
.can = {
|
||||||
@ -718,7 +718,7 @@ static const Config_RobotParam_t param_sentry_gimbal = {
|
|||||||
.cover_close_duty = 0.050f,
|
.cover_close_duty = 0.050f,
|
||||||
.model = SHOOT_MODEL_17MM,
|
.model = SHOOT_MODEL_17MM,
|
||||||
.bullet_speed = 25.f,
|
.bullet_speed = 25.f,
|
||||||
.min_shoot_delay = (uint32_t)(1000.0f / 20.0f),
|
.min_shoot_delay = (uint32_t)(1000.0f / 1.0f),
|
||||||
}, /* shoot */
|
}, /* shoot */
|
||||||
|
|
||||||
.can = {
|
.can = {
|
||||||
|
@ -42,9 +42,7 @@ void Task_Ai(void *argument) {
|
|||||||
AI_Init(&ai);
|
AI_Init(&ai);
|
||||||
|
|
||||||
uint32_t tick = osKernelGetTickCount();
|
uint32_t tick = osKernelGetTickCount();
|
||||||
|
|
||||||
uint32_t last_online_tick = tick;
|
uint32_t last_online_tick = tick;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
task_runtime.stack_water_mark.ai = osThreadGetStackSpace(osThreadGetId());
|
task_runtime.stack_water_mark.ai = osThreadGetStackSpace(osThreadGetId());
|
||||||
@ -54,18 +52,23 @@ void Task_Ai(void *argument) {
|
|||||||
|
|
||||||
AI_StartReceiving(&ai);
|
AI_StartReceiving(&ai);
|
||||||
if (AI_WaitDmaCplt()) {
|
if (AI_WaitDmaCplt()) {
|
||||||
AI_ParseHost(&ai, &cmd_host);
|
AI_ParseHost(&ai);
|
||||||
last_online_tick = tick;
|
last_online_tick = tick;
|
||||||
} else {
|
} else {
|
||||||
if (tick - last_online_tick > 300) AI_HandleOffline(&ai,&cmd_host);
|
if (tick - last_online_tick > 300) AI_HandleOffline(&ai,&cmd_host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ai.status != AI_STATUS_STOP && ai.ai_online){
|
||||||
|
AI_PackCmd(&ai, &cmd_host);
|
||||||
osMessageQueueReset(task_runtime.msgq.cmd.raw.host);
|
osMessageQueueReset(task_runtime.msgq.cmd.raw.host);
|
||||||
osMessageQueuePut(task_runtime.msgq.cmd.raw.host, &(cmd_host), 0, 0);
|
osMessageQueuePut(task_runtime.msgq.cmd.raw.host, &(cmd_host), 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
osMessageQueueGet(task_runtime.msgq.ai.quat, &(quat), NULL, 0);
|
osMessageQueueGet(task_runtime.msgq.ai.quat, &(quat), NULL, 0);
|
||||||
osMessageQueueGet(task_runtime.msgq.cmd.ai, &(ai.status), NULL, 0);
|
osMessageQueueGet(task_runtime.msgq.cmd.ai, &(ai.status), NULL, 0);
|
||||||
bool ref_update = (osMessageQueueGet(task_runtime.msgq.referee.ai,
|
bool ref_update = (osMessageQueueGet(task_runtime.msgq.referee.ai,
|
||||||
&(referee_ai), NULL, 0) == osOK);
|
&(referee_ai), NULL, 0) == osOK);
|
||||||
|
|
||||||
AI_PackMCU(&ai, &quat);
|
AI_PackMCU(&ai, &quat);
|
||||||
if (ref_update) AI_PackRef(&ai, &(referee_ai));
|
if (ref_update) AI_PackRef(&ai, &(referee_ai));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user