添加cmd

This commit is contained in:
Robofish 2025-10-10 22:02:47 +08:00
parent 22654da273
commit 85d16a1bc0
10 changed files with 45 additions and 22 deletions

View File

@ -83,6 +83,7 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
# User/module sources
User/module/balance_chassis.c
User/module/cmd.c
User/module/config.c
User/module/gimbal.c
User/module/shoot.c
@ -91,7 +92,7 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
User/task/ai.c
User/task/atti_esti.c
User/task/blink.c
User/task/command.c
User/task/cmd.c
User/task/ctrl_chassis.c
User/task/ctrl_gimbal.c
User/task/ctrl_shoot.c

19
User/module/cmd.h Normal file
View File

@ -0,0 +1,19 @@
/*
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
}
#endif

View File

View File

@ -160,6 +160,4 @@ void Task_atti_esti(void *argument) {
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
}
}
}

View File

@ -1,5 +1,5 @@
/*
command Task
cmd Task
*/
@ -19,14 +19,14 @@
/* Private function --------------------------------------------------------- */
/* Exported functions ------------------------------------------------------- */
void Task_command(void *argument) {
void Task_cmd(void *argument) {
(void)argument; /* 未使用argument消除警告 */
/* 计算任务运行到指定频率需要等待的tick数 */
const uint32_t delay_tick = osKernelGetTickFreq() / COMMAND_FREQ;
const uint32_t delay_tick = osKernelGetTickFreq() / CMD_FREQ;
osDelay(COMMAND_INIT_DELAY); /* 延时一段时间再开启任务 */
osDelay(CMD_INIT_DELAY); /* 延时一段时间再开启任务 */
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
/* USER CODE INIT BEGIN */
@ -36,7 +36,7 @@ void Task_command(void *argument) {
while (1) {
tick += delay_tick; /* 计算下一个唤醒时刻 */
/* USER CODE BEGIN */
/* USER CODE END */
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
}

View File

@ -58,6 +58,6 @@
description: ''
freq_control: true
frequency: 500.0
function: Task_command
name: command
function: Task_cmd
name: cmd
stack: 256

View File

@ -41,7 +41,7 @@ void Task_Init(void *argument) {
task_runtime.thread.ctrl_shoot = osThreadNew(Task_ctrl_shoot, NULL, &attr_ctrl_shoot);
task_runtime.thread.monitor = osThreadNew(Task_monitor, NULL, &attr_monitor);
task_runtime.thread.ai = osThreadNew(Task_ai, NULL, &attr_ai);
task_runtime.thread.command = osThreadNew(Task_command, NULL, &attr_command);
task_runtime.thread.cmd = osThreadNew(Task_cmd, NULL, &attr_cmd);
// 创建消息队列
/* USER MESSAGE BEGIN */

View File

@ -49,8 +49,8 @@ const osThreadAttr_t attr_ai = {
.priority = osPriorityNormal,
.stack_size = 256 * 4,
};
const osThreadAttr_t attr_command = {
.name = "command",
const osThreadAttr_t attr_cmd = {
.name = "cmd",
.priority = osPriorityNormal,
.stack_size = 256 * 4,
};

View File

@ -21,7 +21,7 @@ extern "C" {
#define CTRL_SHOOT_FREQ (500.0)
#define MONITOR_FREQ (500.0)
#define AI_FREQ (500.0)
#define COMMAND_FREQ (500.0)
#define CMD_FREQ (500.0)
/* 任务初始化延时ms */
#define TASK_INIT_DELAY (100u)
@ -33,7 +33,7 @@ extern "C" {
#define CTRL_SHOOT_INIT_DELAY (0)
#define MONITOR_INIT_DELAY (0)
#define AI_INIT_DELAY (0)
#define COMMAND_INIT_DELAY (0)
#define CMD_INIT_DELAY (0)
/* Exported defines --------------------------------------------------------- */
/* Exported macro ----------------------------------------------------------- */
@ -51,7 +51,7 @@ typedef struct {
osThreadId_t ctrl_shoot;
osThreadId_t monitor;
osThreadId_t ai;
osThreadId_t command;
osThreadId_t cmd;
} thread;
/* USER MESSAGE BEGIN */
@ -70,6 +70,11 @@ typedef struct {
struct {
osMessageQueueId_t shoot_cmd; /* 发射命令队列 */
}shoot;
struct {
osMessageQueueId_t rc;
osMessageQueueId_t ref;
osMessageQueueId_t ai;
}cmd;
} msgq;
/* USER MESSAGE END */
@ -94,7 +99,7 @@ typedef struct {
UBaseType_t ctrl_shoot;
UBaseType_t monitor;
UBaseType_t ai;
UBaseType_t command;
UBaseType_t cmd;
} stack_water_mark;
/* 各任务运行频率 */
@ -107,7 +112,7 @@ typedef struct {
float ctrl_shoot;
float monitor;
float ai;
float command;
float cmd;
} freq;
/* 任务最近运行时间 */
@ -120,7 +125,7 @@ typedef struct {
float ctrl_shoot;
float monitor;
float ai;
float command;
float cmd;
} last_up_time;
} Task_Runtime_t;
@ -138,7 +143,7 @@ extern const osThreadAttr_t attr_ctrl_gimbal;
extern const osThreadAttr_t attr_ctrl_shoot;
extern const osThreadAttr_t attr_monitor;
extern const osThreadAttr_t attr_ai;
extern const osThreadAttr_t attr_command;
extern const osThreadAttr_t attr_cmd;
/* 任务函数声明 */
void Task_Init(void *argument);
@ -150,7 +155,7 @@ void Task_ctrl_gimbal(void *argument);
void Task_ctrl_shoot(void *argument);
void Task_monitor(void *argument);
void Task_ai(void *argument);
void Task_command(void *argument);
void Task_cmd(void *argument);
#ifdef __cplusplus
}