first commit

This commit is contained in:
yxming66 2025-10-31 18:02:02 +08:00
parent d635d709f5
commit 873d5937cb
3 changed files with 178 additions and 12 deletions

85
User/module/cmd.c Normal file
View File

@ -0,0 +1,85 @@
/*
*/
#include "module/cmd.h"
#include <string.h>
/*************************************************************************/
/*********************************仲裁器**********************************/
/*************************************************************************/
/*************************************************************************/
/**********************************RC*************************************/
/*************************************************************************/
/* Includes ----------------------------------------------------------------- */
/* Private typedef ---------------------------------------------------------- */
/* Private define ----------------------------------------------------------- */
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* Private function -------------------------------------------------------- */
/* Exported functions ------------------------------------------------------- */
#define RC_SELECT_Index 1
/* 扩展接口 */
#if RC_SELECT_Index == 0
#define FOR_EACH_RC(_) _(dr16, DR16)
#elif RC_SELECT_Index == 1
#define FOR_EACH_RC(_) _(at9s, AT9S)
#endif
#if RC_SELECT_Index == 0
#include "device/dr16.h"
#elif RC_SELECT_Index == 1
#include "device/at9s_pro.h"
#endif
#define X_FIELD(name, NAME) DEVICE_##NAME##_t name;
#define X_EXTERN(name, NAME) extern DEVICE_##NAME##_t name##_out;
#define X_COPY(name, NAME) \
static void copy_##name(rc_u *dst) { dst->name = name##_out; }
#define X_REF(name, NAME) copy_##name,
union rc_u{
FOR_EACH_RC(X_FIELD)
};
FOR_EACH_RC(X_EXTERN)
FOR_EACH_RC(X_COPY)
/*静态缓冲区,供返回使用*/
static rc_u rc_buffer;
CMD_RCInputData_t rc;
int8_t Cmd_get_rc(CMD_RCInputData_t *dst)
{
FOR_EACH_RC(X_REF)(&rc_buffer);
dst->rc = &rc_buffer;
dst->rc_type = RC_SELECT_Index;
return CMD_OK;
}
/*************************************************************************/
/**********************************PC*************************************/
/*************************************************************************/
/*************************************************************************/
/**********************************NUC*************************************/
/*************************************************************************/
/*************************************************************************/
/**********************************REF*************************************/
/*************************************************************************/
/*************************************************************************/
/*********************************分发命令*********************************/
/*************************************************************************/

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

@ -0,0 +1,81 @@
/*
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "module/chassis.h"
#include "module/gimbal.h"
#include "module/shoot.h"
/* Exported constants ------------------------------------------------------- */
#define CMD_OK (0) /* 运行正常 */
#define CMD_ERR_NULL (-1) /* 运行时发现NULL指针 */
#define CMD_ERR_ERR (-2) /* 运行时发现了其他错误 */
#define CMD_ERR_MODE (-3) /* 运行时配置了错误的Mode */
#define CMD_ERR_MOTOR (-4) /* 运行时配置了不存在的电机类型 */
#define CMD_ERR_MALLOC (-5) /* 内存分配失败 */
/* Exported macro ----------------------------------------------------------- */
/* Exported types ----------------------------------------------------------- */
typedef union rc_u rc_u;
typedef struct {
rc_u *rc;
enum { DR16, AT9S } rc_type;
} CMD_RCInputData_t;
#define CMD_REFEREE_MAX_NUM (3) /* 发送命令限定的最大数量 */
/* 输入源枚举 */
typedef enum {
CMD_SRC_RC, /* 遥控器 */
CMD_SRC_PC, /* 键盘鼠标 */
CMD_SRC_NUC, /* 上位机 */
CMD_SRC_REFEREE, /* 裁判系统 */
CMD_SRC_NUM
} CMD_InputSource_t;
typedef struct {
}CMD_PCInputData_t;
typedef struct {
}CMD_NUCInputData_t;
typedef struct {
}CMD_REFInputData_t;
/* 底盘控制命令 */
typedef struct {
} CMD_cmdForChassisCtrl_t;
/* 云台控制命令 */
typedef struct {
} CMD_cmdForGimbalCtrl_t;
/* 射击控制命令 */
typedef struct {
CMD_InputSource_t src;
Shoot_CMD_t shoot_cmd;
} CMD_Shoot_t;
typedef struct {
bool pc_ctrl; /* 是否使用键鼠控制 */
bool host_overwrite; /* 是否Host控制 */
uint16_t key_last; /* 上次按键键值 */
} CMD_t;
/* Exported functions prototypes -------------------------------------------- */
#ifdef __cplusplus
}
#endif

View File

@ -20,7 +20,7 @@
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* USER STRUCT BEGIN */
DEVICE_AT9S_t at9s_from_rc;
DEVICE_AT9S_t at9s_out;
Shoot_CMD_t cmd_for_shoot;
//Chassis_Cmd_t cmd_for_chassis;
Gimbal_CMD_t cmd_for_gimbal;
@ -45,9 +45,9 @@ void Task_cmd(void *argument) {
while (1) {
tick += delay_tick; /* 计算下一个唤醒时刻 */
/* USER CODE BEGIN */
osMessageQueueGet(task_runtime.msgq.cmd.rc, &at9s_from_rc, NULL, 0);
osMessageQueueGet(task_runtime.msgq.cmd.rc, &at9s_out, NULL, 0);
switch (at9s_from_rc.data.key_G) {
switch (at9s_out.data.key_G) {
case AT9S_CMD_SW_DOWN:
cmd_for_gimbal.mode = GIMBAL_MODE_RELAX;
cmd_for_gimbal.delta_yaw = 0.0f;
@ -55,13 +55,13 @@ void Task_cmd(void *argument) {
break;
case AT9S_CMD_SW_MID:
cmd_for_gimbal.mode = GIMBAL_MODE_ABSOLUTE;
cmd_for_gimbal.delta_yaw = -at9s_from_rc.data.ch_l_x * 2.0f;
cmd_for_gimbal.delta_pit = -at9s_from_rc.data.ch_l_y * 1.5f;
cmd_for_gimbal.delta_yaw = -at9s_out.data.ch_l_x * 2.0f;
cmd_for_gimbal.delta_pit = -at9s_out.data.ch_l_y * 1.5f;
break;
case AT9S_CMD_SW_UP:
cmd_for_gimbal.mode = GIMBAL_MODE_ABSOLUTE;
cmd_for_gimbal.delta_yaw = -at9s_from_rc.data.ch_l_x * 2.0f;
cmd_for_gimbal.delta_pit = -at9s_from_rc.data.ch_l_y * 1.5f;
cmd_for_gimbal.delta_yaw = -at9s_out.data.ch_l_x * 2.0f;
cmd_for_gimbal.delta_pit = -at9s_out.data.ch_l_y * 1.5f;
break;
default:
cmd_for_gimbal.mode = GIMBAL_MODE_RELAX;
@ -70,24 +70,24 @@ void Task_cmd(void *argument) {
break;
}
switch (at9s_from_rc.data.key_C) {
switch (at9s_out.data.key_C) {
case AT9S_CMD_SW_DOWN:
cmd_for_shoot.online = at9s_from_rc.online;
cmd_for_shoot.online = at9s_out.online;
cmd_for_shoot.ready = true;
cmd_for_shoot.firecmd = true;
break;
case AT9S_CMD_SW_MID:
cmd_for_shoot.online = at9s_from_rc.online;
cmd_for_shoot.online = at9s_out.online;
cmd_for_shoot.ready = true;
cmd_for_shoot.firecmd = false;
break;
case AT9S_CMD_SW_UP:
cmd_for_shoot.online = at9s_from_rc.online;
cmd_for_shoot.online = at9s_out.online;
cmd_for_shoot.ready = false;
cmd_for_shoot.firecmd = false;
break;
default:
cmd_for_shoot.online = at9s_from_rc.online;
cmd_for_shoot.online = at9s_out.online;
cmd_for_shoot.ready = false;
cmd_for_shoot.firecmd = false;
break;