140 lines
4.8 KiB
C
140 lines
4.8 KiB
C
/*
|
||
cmd Task
|
||
|
||
*/
|
||
|
||
/* Includes ----------------------------------------------------------------- */
|
||
#include "task/user_task.h"
|
||
/* USER INCLUDE BEGIN */
|
||
#include "device/dr16.h"
|
||
#include "module/config.h"
|
||
#include "module/balance_chassis.h"
|
||
#include "module/gimbal.h"
|
||
#include "module/shoot.h"
|
||
#include "module/cmd/cmd.h"
|
||
#include "bsp/fdcan.h"
|
||
#include "module/vision_bridge.h"
|
||
//#define DEAD_AREA 0.05f
|
||
/* USER INCLUDE END */
|
||
|
||
/* Private typedef ---------------------------------------------------------- */
|
||
/* Private define ----------------------------------------------------------- */
|
||
/* Private macro ------------------------------------------------------------ */
|
||
/* Private variables -----------
|
||
--------------------------------------------- */
|
||
/* USER STRUCT BEGIN */
|
||
#if CMD_RCTypeTable_Index == 0
|
||
DR16_t cmd_dr16;
|
||
#elif CMD_RCTypeTable_Index == 1
|
||
AT9S_t cmd_at9s;
|
||
#endif
|
||
// AI_cmd_t cmd_ai;
|
||
|
||
#if CMD_ENABLE_SRC_REF
|
||
CMD_RawInput_REF_t cmd_ref;
|
||
#endif
|
||
|
||
static CMD_t cmd;
|
||
|
||
// AI_t ai;
|
||
/* USER STRUCT END */
|
||
|
||
/* Private function --------------------------------------------------------- */
|
||
/* Exported functions ------------------------------------------------------- */
|
||
void Task_cmd(void *argument) {
|
||
(void)argument; /* 未使用argument,消除警告 */
|
||
|
||
|
||
/* 计算任务运行到指定频率需要等待的tick数 */
|
||
const uint32_t delay_tick = osKernelGetTickFreq() / CMD_FREQ;
|
||
|
||
osDelay(CMD_INIT_DELAY); /* 延时一段时间再开启任务 */
|
||
|
||
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
|
||
/* USER CODE INIT BEGIN */
|
||
CMD_Init(&cmd, &Config_GetRobotParam()->cmd_param);
|
||
// AI_Init(&ai, &Config_GetRobotParam()->ai_param);
|
||
/* 注册CAN接收ID */
|
||
/* USER CODE INIT END */
|
||
|
||
while (1) {
|
||
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||
/* USER CODE BEGIN */
|
||
#if CMD_RCTypeTable_Index == 0
|
||
osMessageQueueGet(task_runtime.msgq.cmd.rc, &cmd_dr16, NULL, 0);
|
||
#elif CMD_RCTypeTable_Index == 1
|
||
osMessageQueueGet(task_runtime.msgq.cmd.rc, &cmd_at9s, NULL, 0);
|
||
#endif
|
||
|
||
// /* 从CAN2接收AI命令 */
|
||
// AI_ParseCmdFromCan( &ai,&cmd_ai);
|
||
// #error "弄好自瞄之后统一改"
|
||
|
||
#if CMD_ENABLE_SRC_REF
|
||
/* 从裁判系统读取最新数据(非阻塞) */
|
||
osMessageQueueGet(task_runtime.msgq.referee.tocmd.chassis, &cmd_ref.chassis, NULL, 0);
|
||
osMessageQueueGet(task_runtime.msgq.referee.tocmd.shoot, &cmd_ref.shoot, NULL, 0);
|
||
osMessageQueueGet(task_runtime.msgq.referee.tocmd.cap, &cmd_ref.cap, NULL, 0);
|
||
osMessageQueueGet(task_runtime.msgq.referee.tocmd.ai, &cmd_ref.ai, NULL, 0);
|
||
#endif
|
||
|
||
CMD_Update(&cmd);
|
||
|
||
/* 获取命令发送到各模块 */
|
||
#if CMD_ENABLE_MODULE_CHASSIS
|
||
Chassis_CMD_t *cmd_for_chassis = CMD_GetChassisCmd(&cmd);
|
||
osMessageQueueReset(task_runtime.msgq.chassis.cmd);
|
||
osMessageQueuePut(task_runtime.msgq.chassis.cmd, cmd_for_chassis, 0, 0);
|
||
#endif
|
||
|
||
#if CMD_ENABLE_MODULE_GIMBAL
|
||
Gimbal_CMD_t *cmd_for_gimbal = CMD_GetGimbalCmd(&cmd);
|
||
osMessageQueueReset(task_runtime.msgq.gimbal.cmd);
|
||
osMessageQueuePut(task_runtime.msgq.gimbal.cmd, cmd_for_gimbal, 0, 0);
|
||
#endif
|
||
|
||
#if CMD_ENABLE_MODULE_SHOOT
|
||
Shoot_CMD_t *cmd_for_shoot = CMD_GetShootCmd(&cmd);
|
||
|
||
osMessageQueueReset(task_runtime.msgq.shoot.cmd);
|
||
osMessageQueuePut(task_runtime.msgq.shoot.cmd, cmd_for_shoot, 0, 0);
|
||
#endif
|
||
|
||
#if CMD_ENABLE_MODULE_TRACK
|
||
Track_CMD_t *cmd_for_track = CMD_GetTrackCmd(&cmd);
|
||
osMessageQueueReset(task_runtime.msgq.track.cmd);
|
||
osMessageQueuePut(task_runtime.msgq.track.cmd, cmd_for_track, 0, 0);
|
||
#endif
|
||
|
||
#if CMD_ENABLE_MODULE_REFUI
|
||
Referee_UI_CMD_t *cmd_for_ui = CMD_GetRefUICmd(&cmd);
|
||
osMessageQueueReset(task_runtime.msgq.referee.ui.frcmd);
|
||
osMessageQueuePut(task_runtime.msgq.referee.ui.frcmd, cmd_for_ui, 0, 0);
|
||
#endif
|
||
|
||
#if CMD_ENABLE_MODULE_BALANCE_CHASSIS
|
||
Chassis_CMD_t *cmd_for_balance_chassis = CMD_GetBalanceChassisCmd(&cmd);
|
||
osMessageQueueReset(task_runtime.msgq.chassis.cmd);
|
||
osMessageQueuePut(task_runtime.msgq.chassis.cmd, cmd_for_balance_chassis, 0, 0);
|
||
#endif
|
||
|
||
#if CMD_ENABLE_SRC_REF
|
||
/* 将裁判数据转发到各模块的 .ref 队列 */
|
||
{
|
||
CMD_RawInput_REF_t *ref = CMD_GetRefData(&cmd);
|
||
osMessageQueueReset(task_runtime.msgq.chassis.ref);
|
||
osMessageQueuePut(task_runtime.msgq.chassis.ref, &ref->chassis, 0, 0);
|
||
osMessageQueueReset(task_runtime.msgq.shoot.ref);
|
||
osMessageQueuePut(task_runtime.msgq.shoot.ref, &ref->shoot, 0, 0);
|
||
osMessageQueueReset(task_runtime.msgq.cap.ref);
|
||
osMessageQueuePut(task_runtime.msgq.cap.ref, &ref->cap, 0, 0);
|
||
osMessageQueueReset(task_runtime.msgq.ai.ref);
|
||
osMessageQueuePut(task_runtime.msgq.ai.ref, &ref->ai, 0, 0);
|
||
}
|
||
#endif
|
||
|
||
/* USER CODE END */
|
||
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
||
}
|
||
|
||
} |