新cmd好使了,现在开始优化input
This commit is contained in:
parent
c17f41b267
commit
f1a4099554
@ -41,7 +41,7 @@ add_subdirectory(cmake/stm32cubemx)
|
|||||||
target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE
|
target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE
|
||||||
# Add user defined library search paths
|
# Add user defined library search paths
|
||||||
)
|
)
|
||||||
|
file(GLOB SINGLE_CHAR_FILES "User/module/cmd_v2/*.c")
|
||||||
# Add sources to executable
|
# Add sources to executable
|
||||||
target_sources(${CMAKE_PROJECT_NAME} PRIVATE
|
target_sources(${CMAKE_PROJECT_NAME} PRIVATE
|
||||||
# Add user sources here
|
# Add user sources here
|
||||||
@ -77,7 +77,7 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
|
|||||||
User/module/config.c
|
User/module/config.c
|
||||||
User/module/gimbal.c
|
User/module/gimbal.c
|
||||||
User/module/shoot.c
|
User/module/shoot.c
|
||||||
User/module/cmd.c
|
${SINGLE_CHAR_FILES}
|
||||||
# User/task sources
|
# User/task sources
|
||||||
User/task/atti_esti.c
|
User/task/atti_esti.c
|
||||||
User/task/blink.c
|
User/task/blink.c
|
||||||
|
|||||||
@ -88,9 +88,8 @@ typedef struct{
|
|||||||
bool r_click; /* 右键 */
|
bool r_click; /* 右键 */
|
||||||
} mouse; /* 鼠标值 */
|
} mouse; /* 鼠标值 */
|
||||||
|
|
||||||
union {
|
struct {
|
||||||
bool key[DR16_KEY_NUM]; /* 键盘按键值 */
|
bool key[DR16_KEY_NUM]; /* 键盘按键值 */
|
||||||
uint16_t value; /* 键盘按键值的位映射 */
|
|
||||||
} keyboard;
|
} keyboard;
|
||||||
}DR16_DataPC_t;
|
}DR16_DataPC_t;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@ -100,9 +100,8 @@ typedef struct {
|
|||||||
bool r_click; /* 右键 */
|
bool r_click; /* 右键 */
|
||||||
} mouse; /* 鼠标值 */
|
} mouse; /* 鼠标值 */
|
||||||
|
|
||||||
union {
|
struct {
|
||||||
bool key[VT13_KEY_NUM]; /* 键盘按键值 */
|
bool key[VT13_KEY_NUM]; /* 键盘按键值 */
|
||||||
uint16_t value; /* 键盘按键值的位映射 */
|
|
||||||
} keyboard;
|
} keyboard;
|
||||||
|
|
||||||
uint16_t res; /* 保留,未启用 */
|
uint16_t res; /* 保留,未启用 */
|
||||||
|
|||||||
@ -1,703 +0,0 @@
|
|||||||
/*
|
|
||||||
控制命令
|
|
||||||
*/
|
|
||||||
#include "module/cmd.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "bsp/time.h"
|
|
||||||
#include "module/gimbal.h"
|
|
||||||
|
|
||||||
/*************************************************************************************************************************************/
|
|
||||||
/****************************************************************RC*******************************************************************/
|
|
||||||
/*************************************************************************************************************************************/
|
|
||||||
/* Private macro ------------------------------------------------------------ */
|
|
||||||
/* 声明外部rc数据变量 */
|
|
||||||
#define CMDMACRO_EXTERNAL_RCDATA(name, NAME) extern NAME##_t name;
|
|
||||||
|
|
||||||
#define CMDMACRO_NAME_EXPANSION_1(name, NAME) name
|
|
||||||
/* 声明CMD结构体的RC数据变量 */
|
|
||||||
#define CMDMACRO_VAR_RCDATA(name, NAME) NAME##_DataRC_t name;
|
|
||||||
/* 宏生成Cmd_RC_Get函数内容 */
|
|
||||||
#define CMDMACRO_Cmd_RC_Get(name, NAME) \
|
|
||||||
c->input.rc.name= name.data.rc; \
|
|
||||||
c->input.rc.online=name.header.online; \
|
|
||||||
c->input.rc.type=CMD_RCTypeTable_Index;
|
|
||||||
|
|
||||||
CMD_RCType_TABLE(CMDMACRO_EXTERNAL_RCDATA)
|
|
||||||
/* Private typedef ---------------------------------------------------------- */
|
|
||||||
/* Private define ----------------------------------------------------------- */
|
|
||||||
|
|
||||||
/* Private variables -------------------------------------------------------- */
|
|
||||||
/*静态缓冲区*/
|
|
||||||
|
|
||||||
/* Private function -------------------------------------------------------- */
|
|
||||||
int8_t Cmd_RC_Get(CMD_t *c, CMD_RCType_TABLE(CMDMACRO_NAME_EXPANSION)){
|
|
||||||
// bool online= dr16->header.online;
|
|
||||||
// rc_buffer.dr16=dr16->data.rc;
|
|
||||||
// c->input.rc.online=online;
|
|
||||||
// c->input.rc.type=CMD_RCTypeTable_Index;
|
|
||||||
CMD_RCType_TABLE(CMDMACRO_Cmd_RC_Get);
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int8_t Cmd_RC_BuildChassisCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
#if CMD_RCTypeTable_Index == 0
|
|
||||||
switch (c->input.rc.dr16.sw_l) {
|
|
||||||
case DR16_SW_DOWN:
|
|
||||||
c->output.chassis.cmd.mode = CHASSIS_MODE_ROTOR;
|
|
||||||
break;
|
|
||||||
case DR16_SW_MID:
|
|
||||||
c->output.chassis.cmd.mode = CHASSIS_MODE_FOLLOW_GIMBAL;
|
|
||||||
break;
|
|
||||||
case DR16_SW_UP:
|
|
||||||
c->output.chassis.cmd.mode = CHASSIS_MODE_BREAK;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
c->output.chassis.cmd.mode = CHASSIS_MODE_RELAX;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
c->output.chassis.cmd.ctrl_vec.vx = c->input.rc.dr16.ch_r_x;
|
|
||||||
c->output.chassis.cmd.ctrl_vec.vy = c->input.rc.dr16.ch_r_y;
|
|
||||||
#elif CMD_RCTypeTable_Index == 1
|
|
||||||
switch (c->input.rc.data->at9s.key_E) {
|
|
||||||
case AT9S_CMD_SW_DOWN:
|
|
||||||
c->output.chassis.cmd.mode = CHASSIS_MODE_RELAX;
|
|
||||||
break;
|
|
||||||
case AT9S_CMD_SW_MID:
|
|
||||||
c->output.chassis.cmd.mode = CHASSIS_MODE_FOLLOW_GIMBAL;
|
|
||||||
break;
|
|
||||||
case AT9S_CMD_SW_UP:
|
|
||||||
c->output.chassis.cmd.mode = CHASSIS_MODE_ROTOR;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
c->output.chassis.cmd.mode = CHASSIS_MODE_RELAX;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
c->output.chassis.cmd.ctrl_vec.vx = c->input.rc.data->at9s.ch_r_x;
|
|
||||||
c->output.chassis.cmd.ctrl_vec.vy = c->input.rc.data->at9s.ch_r_y;
|
|
||||||
#endif
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int8_t Cmd_RC_BuildGimbalCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
#if CMD_RCTypeTable_Index == 0
|
|
||||||
switch (c->input.rc.dr16.sw_l) {
|
|
||||||
case DR16_SW_DOWN:
|
|
||||||
c->output.gimbal.cmd.mode = GIMBAL_MODE_RELATIVE;
|
|
||||||
c->output.gimbal.cmd.delta_yaw = -c->input.rc.dr16.ch_l_x * 2.0f;
|
|
||||||
c->output.gimbal.cmd.delta_pit = -c->input.rc.dr16.ch_l_y * 1.5f;
|
|
||||||
break;
|
|
||||||
case DR16_SW_MID:
|
|
||||||
c->output.gimbal.cmd.mode = GIMBAL_MODE_ABSOLUTE;
|
|
||||||
c->output.gimbal.cmd.delta_yaw = -c->input.rc.dr16.ch_l_x * 2.0f;
|
|
||||||
c->output.gimbal.cmd.delta_pit = -c->input.rc.dr16.ch_l_y * 1.5f;
|
|
||||||
break;
|
|
||||||
case DR16_SW_UP:
|
|
||||||
c->output.gimbal.cmd.mode = GIMBAL_MODE_ABSOLUTE;
|
|
||||||
c->output.gimbal.cmd.delta_yaw = -c->input.rc.dr16.ch_l_x * 2.0f;
|
|
||||||
c->output.gimbal.cmd.delta_pit = -c->input.rc.dr16.ch_l_y * 1.5f;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
c->output.gimbal.cmd.mode = GIMBAL_MODE_RELAX;
|
|
||||||
c->output.gimbal.cmd.delta_yaw = 0.0f;
|
|
||||||
c->output.gimbal.cmd.delta_pit = 0.0f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#elif CMD_RCTypeTable_Index == 1
|
|
||||||
switch (c->input.rc.data->at9s.key_G) {
|
|
||||||
case AT9S_CMD_SW_DOWN:
|
|
||||||
c->output.gimbal.cmd.mode = GIMBAL_MODE_RELAX;
|
|
||||||
c->output.gimbal.cmd.delta_yaw = 0.0f;
|
|
||||||
c->output.gimbal.cmd.delta_pit = 0.0f;
|
|
||||||
break;
|
|
||||||
case AT9S_CMD_SW_MID:
|
|
||||||
c->output.gimbal.cmd.mode = GIMBAL_MODE_ABSOLUTE;
|
|
||||||
c->output.gimbal.cmd.delta_yaw = -c->input.rc.data->at9s.ch_l_x * 2.0f;
|
|
||||||
c->output.gimbal.cmd.delta_pit = -c->input.rc.data->at9s.ch_l_y * 1.5f;
|
|
||||||
break;
|
|
||||||
case AT9S_CMD_SW_UP:
|
|
||||||
c->output.gimbal.cmd.mode = GIMBAL_MODE_ABSOLUTE;
|
|
||||||
c->output.gimbal.cmd.delta_yaw = -c->input.rc.data->at9s.ch_l_x * 2.0f;
|
|
||||||
c->output.gimbal.cmd.delta_pit = -c->input.rc.data->at9s.ch_l_y * 1.5f;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
c->output.gimbal.cmd.mode = GIMBAL_MODE_RELAX;
|
|
||||||
c->output.gimbal.cmd.delta_yaw = 0.0f;
|
|
||||||
c->output.gimbal.cmd.delta_pit = 0.0f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int8_t Cmd_RC_BuildShootCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
#if CMD_RCTypeTable_Index == 0
|
|
||||||
if (c->input.rc.online) {
|
|
||||||
c->output.shoot.cmd.mode=SHOOT_MODE_SINGLE;
|
|
||||||
} else {
|
|
||||||
c->output.shoot.cmd.mode=SHOOT_MODE_SAFE;
|
|
||||||
}
|
|
||||||
switch (c->input.rc.dr16.sw_r) {
|
|
||||||
case DR16_SW_DOWN:
|
|
||||||
c->output.shoot.cmd.ready = true;
|
|
||||||
c->output.shoot.cmd.firecmd = true;
|
|
||||||
break;
|
|
||||||
case DR16_SW_MID:
|
|
||||||
c->output.shoot.cmd.ready = true;
|
|
||||||
c->output.shoot.cmd.firecmd = false;
|
|
||||||
break;
|
|
||||||
case DR16_SW_UP:
|
|
||||||
c->output.shoot.cmd.ready = false;
|
|
||||||
c->output.shoot.cmd.firecmd = false;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
c->output.shoot.cmd.ready = false;
|
|
||||||
c->output.shoot.cmd.firecmd = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#elif CMD_RCTypeTable_Index == 1
|
|
||||||
c->output.shoot.cmd.online = c->input.rc.online;
|
|
||||||
switch (c->input.rc.data->at9s.key_C) {
|
|
||||||
case AT9S_CMD_SW_DOWN:
|
|
||||||
c->output.shoot.cmd.ready = true;
|
|
||||||
c->output.shoot.cmd.firecmd = true;
|
|
||||||
break;
|
|
||||||
case AT9S_CMD_SW_MID:
|
|
||||||
c->output.shoot.cmd.ready = true;
|
|
||||||
c->output.shoot.cmd.firecmd = false;
|
|
||||||
break;
|
|
||||||
case AT9S_CMD_SW_UP:
|
|
||||||
c->output.shoot.cmd.ready = false;
|
|
||||||
c->output.shoot.cmd.firecmd = false;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
c->output.shoot.cmd.ready = false;
|
|
||||||
c->output.shoot.cmd.firecmd = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
switch (c->input.rc.data->at9s.key_D) {
|
|
||||||
case AT9S_CMD_SW_DOWN:
|
|
||||||
c->output.shoot.cmd.mode=SHOOT_MODE_SINGLE;
|
|
||||||
break;
|
|
||||||
case AT9S_CMD_SW_UP:
|
|
||||||
c->output.shoot.cmd.mode=SHOOT_MODE_BURST;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
c->output.shoot.cmd.mode=SHOOT_MODE_SAFE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
/* Exported functions ------------------------------------------------------- */
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************************************************************************/
|
|
||||||
/*****************************************************************PC******************************************************************/
|
|
||||||
/*************************************************************************************************************************************/
|
|
||||||
#ifndef CMD_NOPC_FLAG
|
|
||||||
/* Private macro ------------------------------------------------------------ */
|
|
||||||
#define CMD_PCBehavior_TABLE(X) \
|
|
||||||
X(FORE, CMD_MODULE_CHASSIS) \
|
|
||||||
X(BACK, CMD_MODULE_CHASSIS) \
|
|
||||||
X(LEFT, CMD_MODULE_CHASSIS) \
|
|
||||||
X(RIGHT, CMD_MODULE_CHASSIS) \
|
|
||||||
X(ACCELERATE, CMD_MODULE_CHASSIS) \
|
|
||||||
X(DECELEBRATE, CMD_MODULE_CHASSIS) \
|
|
||||||
X(FIRE, CMD_MODULE_SHOOT) \
|
|
||||||
X(FIRE_MODE, CMD_MODULE_SHOOT) \
|
|
||||||
X(BUFF, CMD_MODULE_SHOOT) \
|
|
||||||
X(AUTOAIM, CMD_MODULE_GIMBAL | CMD_MODULE_SHOOT) \
|
|
||||||
X(OPENCOVER, CMD_MODULE_SHOOT) \
|
|
||||||
X(ROTOR, CMD_MODULE_CHASSIS) \
|
|
||||||
X(REVTRIG, CMD_MODULE_SHOOT) \
|
|
||||||
X(FOLLOWGIMBAL35, CMD_MODULE_CHASSIS) \
|
|
||||||
X(GIMBAL_MODE, CMD_MODULE_GIMBAL)
|
|
||||||
|
|
||||||
/* 行为处理函数声明宏 */
|
|
||||||
#define CMDMACRO_FOR_DECLARE_BEHAVIOR_HANDLER_FUNCTION(BEHAVIOR, MODULE_MASK) \
|
|
||||||
static int8_t Cmd_PC_HandleBehavior##BEHAVIOR(CMD_t *c);
|
|
||||||
/* 行为处理函数指针数组构建宏 */
|
|
||||||
#define CMDMACRO_FOR_BUILD_BEHAVIOR_HANDLER_ARRAY(BEHAVIOR, MODULE_MASK) \
|
|
||||||
{CMD_BEHAVIOR_##BEHAVIOR, Cmd_PC_HandleBehavior##BEHAVIOR},
|
|
||||||
/* 行为模块映射表构建宏 */
|
|
||||||
#define CMDMACRO_FOR_BUILD_MODULE_TABLE(BEHAVIOR, MODULE_MASK) \
|
|
||||||
[CMD_BEHAVIOR_##BEHAVIOR] = MODULE_MASK,
|
|
||||||
/* 行为处理函数声明 */
|
|
||||||
CMD_PCBehavior_TABLE(CMDMACRO_FOR_DECLARE_BEHAVIOR_HANDLER_FUNCTION)
|
|
||||||
|
|
||||||
/* 宏展开函数内容 */
|
|
||||||
#define CMDMACRO_Cmd_PC_Get(name, NAME) \
|
|
||||||
c->input.pc.online=name.header.online;\
|
|
||||||
c->input.pc.name= name.data.pc;
|
|
||||||
#define CMDMACRO_PC_IsBehaviorTriggered(name, NAME) \
|
|
||||||
CMD_PCValue_t value = CMD_PC_BehaviorToValue(c, behavior); \
|
|
||||||
CMD_TriggerType_t active = CMD_PC_BehaviorToActive(c, behavior); \
|
|
||||||
bool now_key_pressed, last_key_pressed; \
|
|
||||||
/* 按下按键为鼠标左、右键 */ \
|
|
||||||
if (value == CMD_L_CLICK) { \
|
|
||||||
now_key_pressed = c->input.pc.name.mouse.l_click; \
|
|
||||||
last_key_pressed = c->input.pc.last##name.mouse.l_click; \
|
|
||||||
} else if (value == CMD_R_CLICK) { \
|
|
||||||
now_key_pressed = c->input.pc.name.mouse.r_click; \
|
|
||||||
last_key_pressed = c->input.pc.last##name.mouse.r_click; \
|
|
||||||
} else { \
|
|
||||||
now_key_pressed = c->input.pc.name.keyboard.key[value]; \
|
|
||||||
last_key_pressed = c->input.pc.last##name.keyboard.key[value]; \
|
|
||||||
} \
|
|
||||||
switch (active) { \
|
|
||||||
case CMD_ACTIVE_RISING_EDGE: \
|
|
||||||
return !now_key_pressed && last_key_pressed; \
|
|
||||||
case CMD_ACTIVE_FALLING_EDGE: \
|
|
||||||
return now_key_pressed && !last_key_pressed; \
|
|
||||||
case CMD_ACTIVE_PRESSED: \
|
|
||||||
return now_key_pressed; \
|
|
||||||
} \
|
|
||||||
return false;
|
|
||||||
#define CMDMACRO_PC_BuildChassisCommandFromInput(name, NAME) \
|
|
||||||
if (c->input.pc.online) {c->output.chassis.cmd.mode = CHASSIS_MODE_FOLLOW_GIMBAL;} \
|
|
||||||
else {c->output.chassis.cmd.mode = CHASSIS_MODE_RELAX;} \
|
|
||||||
c->output.chassis.cmd.ctrl_vec.vx = 0.0f; \
|
|
||||||
c->output.chassis.cmd.ctrl_vec.vy = 0.0f; \
|
|
||||||
for (size_t i = 0; i < CMD_BEHAVIOR_NUM; i++) { \
|
|
||||||
CMD_ModuleMask_t moduleMask = behaviorModuleTable[i]; \
|
|
||||||
if (CMD_PC_IsMaskMatch(c, moduleMask)) { \
|
|
||||||
if (CMD_PC_IsBehaviorTriggered(c, i)) { \
|
|
||||||
behaviorHandlerFuncTable[i].func(c); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
}\
|
|
||||||
return CMD_OK;
|
|
||||||
#define CMDMACRO_PC_BuildGimbalCommandFromInput(name, NAME) \
|
|
||||||
static bool init = false; \
|
|
||||||
if (!init) {c->output.gimbal.cmd.mode = GIMBAL_MODE_ABSOLUTE;init=!init;}\
|
|
||||||
if(!c->input.pc.online) {c->output.gimbal.cmd.mode = GIMBAL_MODE_RELAX;} \
|
|
||||||
c->output.gimbal.cmd.delta_yaw = (float)-c->input.pc.name.mouse.x * c->timer.dt * c->params->pc.sensitivity.sens_mouse; \
|
|
||||||
c->output.gimbal.cmd.delta_pit = (float)1.5f*c->input.pc.name.mouse.y * c->timer.dt * c->params->pc.sensitivity.sens_mouse; \
|
|
||||||
for (size_t i = 0; i < CMD_BEHAVIOR_NUM; i++) { \
|
|
||||||
CMD_ModuleMask_t moduleMask = behaviorModuleTable[i]; \
|
|
||||||
if (CMD_PC_IsMaskMatch(c, moduleMask)) { \
|
|
||||||
if (CMD_PC_IsBehaviorTriggered(c, i)) { \
|
|
||||||
behaviorHandlerFuncTable[i].func(c); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
}\
|
|
||||||
return CMD_OK;
|
|
||||||
#define CMDMACRO_PC_BuildShootCommandFromInput(name, NAME) \
|
|
||||||
if (!c->input.pc.online) {c->output.shoot.cmd.mode = SHOOT_MODE_SAFE;} \
|
|
||||||
c->output.shoot.cmd.ready = true; \
|
|
||||||
c->output.shoot.cmd.firecmd = false; \
|
|
||||||
for (size_t i = 0; i < CMD_BEHAVIOR_NUM; i++) { \
|
|
||||||
CMD_ModuleMask_t moduleMask = behaviorModuleTable[i]; \
|
|
||||||
if (CMD_PC_IsMaskMatch(c, moduleMask)) { \
|
|
||||||
if (CMD_PC_IsBehaviorTriggered(c, i)) { \
|
|
||||||
behaviorHandlerFuncTable[i].func(c); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
return CMD_OK;\
|
|
||||||
memcpy(c->input.pc.last##name.keyboard.key, c->input.pc.name.keyboard.key, sizeof(c->input.pc.name.keyboard.key)); \
|
|
||||||
c->input.pc.last##name.mouse.l_click = c->input.pc.name.mouse.l_click; \
|
|
||||||
c->input.pc.last##name.mouse.r_click = c->input.pc.name.mouse.r_click;
|
|
||||||
/* Private typedef ---------------------------------------------------------- */
|
|
||||||
typedef int8_t (*CMD_BehaviorFunc)(CMD_t *c);
|
|
||||||
typedef struct {
|
|
||||||
CMD_Behavior_t behavior;
|
|
||||||
CMD_BehaviorFunc func;
|
|
||||||
} CMD_BehaviorHandlerFunc_t;
|
|
||||||
|
|
||||||
/* Private variables -------------------------------------------------------- */
|
|
||||||
/* 行为处理函数指针数组 */
|
|
||||||
CMD_BehaviorHandlerFunc_t behaviorHandlerFuncTable[CMD_BEHAVIOR_NUM] = {
|
|
||||||
CMD_PCBehavior_TABLE(CMDMACRO_FOR_BUILD_BEHAVIOR_HANDLER_ARRAY)
|
|
||||||
};
|
|
||||||
/* 行为模块映射表 */
|
|
||||||
static const CMD_ModuleMask_t behaviorModuleTable[CMD_BEHAVIOR_NUM] = {
|
|
||||||
CMD_PCBehavior_TABLE(CMDMACRO_FOR_BUILD_MODULE_TABLE)
|
|
||||||
};
|
|
||||||
/* Private function -------------------------------------------------------- */
|
|
||||||
int8_t Cmd_PC_Get(CMD_t *c, CMD_RCType_TABLE(CMDMACRO_NAME_EXPANSION)){
|
|
||||||
CMD_RCType_TABLE(CMDMACRO_Cmd_PC_Get);
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorFORE(CMD_t *c){
|
|
||||||
c->output.chassis.cmd.ctrl_vec.vy += c->params->pc.sensitivity.move_sense;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorBACK(CMD_t *c){
|
|
||||||
c->output.chassis.cmd.ctrl_vec.vy -= c->params->pc.sensitivity.move_sense;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorLEFT(CMD_t *c){
|
|
||||||
c->output.chassis.cmd.ctrl_vec.vx -= c->params->pc.sensitivity.move_sense;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorRIGHT(CMD_t *c){
|
|
||||||
c->output.chassis.cmd.ctrl_vec.vx += c->params->pc.sensitivity.move_sense;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorACCELERATE(CMD_t *c){
|
|
||||||
c->output.chassis.cmd.ctrl_vec.vx *= c->params->pc.sensitivity.move_fast_sense;
|
|
||||||
c->output.chassis.cmd.ctrl_vec.vy *= c->params->pc.sensitivity.move_fast_sense;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorDECELEBRATE(CMD_t *c){
|
|
||||||
c->output.chassis.cmd.ctrl_vec.vx *= c->params->pc.sensitivity.move_slow_sense;
|
|
||||||
c->output.chassis.cmd.ctrl_vec.vy *= c->params->pc.sensitivity.move_slow_sense;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorFIRE(CMD_t *c){
|
|
||||||
c->output.shoot.cmd.firecmd = true;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorFIRE_MODE(CMD_t *c){
|
|
||||||
c->output.shoot.cmd.mode++;
|
|
||||||
c->output.shoot.cmd.mode %= SHOOT_MODE_NUM;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorBUFF(CMD_t *c){
|
|
||||||
// if (cmd->ai_status == AI_STATUS_HITSWITCH) {
|
|
||||||
// CMD_RefereeAdd(&(cmd->referee), CMD_UI_HIT_SWITCH_STOP);
|
|
||||||
// cmd->host_overwrite = false;
|
|
||||||
// cmd->ai_status = AI_STATUS_STOP;
|
|
||||||
// } else if (cmd->ai_status == AI_STATUS_AUTOAIM) {
|
|
||||||
// // 自瞄模式中切换失败提醒
|
|
||||||
// } else {
|
|
||||||
// CMD_RefereeAdd(&(cmd->referee), CMD_UI_HIT_SWITCH_START);
|
|
||||||
// cmd->ai_status = AI_STATUS_HITSWITCH;
|
|
||||||
// cmd->host_overwrite = true;
|
|
||||||
// }
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorAUTOAIM(CMD_t *c){
|
|
||||||
// if (cmd->ai_status == AI_STATUS_AUTOAIM) {
|
|
||||||
// cmd->host_overwrite = false;
|
|
||||||
// cmd->ai_status = AI_STATUS_STOP;
|
|
||||||
// CMD_RefereeAdd(&(cmd->referee), CMD_UI_AUTO_AIM_STOP);
|
|
||||||
// } else {
|
|
||||||
// cmd->ai_status = AI_STATUS_AUTOAIM;
|
|
||||||
// cmd->host_overwrite = true;
|
|
||||||
// CMD_RefereeAdd(&(cmd->referee), CMD_UI_AUTO_AIM_START);
|
|
||||||
// }
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorOPENCOVER(CMD_t *c){
|
|
||||||
// c->shoot.cover_open = !c->shoot.cover_open;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorROTOR(CMD_t *c){
|
|
||||||
c->output.chassis.cmd.mode = CHASSIS_MODE_ROTOR;
|
|
||||||
c->output.chassis.cmd.mode_rotor = ROTOR_MODE_RAND;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorREVTRIG(CMD_t *c){
|
|
||||||
// c->output.shoot.cmd.reverse_trig = true;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorFOLLOWGIMBAL35(CMD_t *c){
|
|
||||||
c->output.chassis.cmd.mode = CHASSIS_MODE_FOLLOW_GIMBAL_35;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_HandleBehaviorGIMBAL_MODE(CMD_t *c){
|
|
||||||
|
|
||||||
c->output.gimbal.cmd.mode++;
|
|
||||||
c->output.gimbal.cmd.mode %= GIMBAL_MODE_NUM;
|
|
||||||
while (c->output.gimbal.cmd.mode<=0) {c->output.gimbal.cmd.mode++;}
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline CMD_PCValue_t CMD_PC_BehaviorToValue(CMD_t *c,
|
|
||||||
CMD_Behavior_t behavior) {
|
|
||||||
return c->params->pc.map.key_map[behavior].key;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline CMD_TriggerType_t CMD_PC_BehaviorToActive(CMD_t *c,
|
|
||||||
CMD_Behavior_t behavior) {
|
|
||||||
return c->params->pc.map.key_map[behavior].trigger_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool CMD_PC_IsMaskMatch(CMD_t *c, CMD_ModuleMask_t module_mask) {
|
|
||||||
/* 构建当前各模块输入源状态的掩码 */
|
|
||||||
CMD_ModuleMask_t current_pc_mask = 0;
|
|
||||||
if (c->output.chassis.source == CMD_SRC_PC) current_pc_mask |= CMD_MODULE_CHASSIS;
|
|
||||||
if (c->output.gimbal.source == CMD_SRC_PC) current_pc_mask |= CMD_MODULE_GIMBAL;
|
|
||||||
if (c->output.shoot.source == CMD_SRC_PC) current_pc_mask |= CMD_MODULE_SHOOT;
|
|
||||||
|
|
||||||
/* 检测并集 */
|
|
||||||
return (module_mask & current_pc_mask) == module_mask;
|
|
||||||
/* 检测交集 */
|
|
||||||
// return (module_mask & current_pc_mask) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool CMD_PC_IsBehaviorTriggered(CMD_t *c, CMD_Behavior_t behavior) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
CMD_RCType_TABLE(CMDMACRO_PC_IsBehaviorTriggered);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int8_t Cmd_PC_BuildChassisCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
CMD_RCType_TABLE(CMDMACRO_PC_BuildChassisCommandFromInput);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int8_t Cmd_PC_BuildGimbalCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
CMD_RCType_TABLE(CMDMACRO_PC_BuildGimbalCommandFromInput);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int8_t Cmd_PC_BuildShootCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
CMD_RCType_TABLE(CMDMACRO_PC_BuildShootCommandFromInput);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static int8_t Cmd_PC_Get(CMD_Input_PC_t *pc) {
|
|
||||||
pc->online=false;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_BuildChassisCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_BuildGimbalCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
static int8_t Cmd_PC_BuildShootCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*************************************************************************************************************************************/
|
|
||||||
/****************************************************************NUC******************************************************************/
|
|
||||||
/*************************************************************************************************************************************/
|
|
||||||
|
|
||||||
/* Includes ----------------------------------------------------------------- */
|
|
||||||
/* Private typedef ---------------------------------------------------------- */
|
|
||||||
/* Private define ----------------------------------------------------------- */
|
|
||||||
/* Private macro ------------------------------------------------------------ */
|
|
||||||
/* Private variables -------------------------------------------------------- */
|
|
||||||
/* Private function -------------------------------------------------------- */
|
|
||||||
int8_t Cmd_NUC_Get(CMD_Input_NUC_t *nuc) {
|
|
||||||
nuc->online=0;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
/* Exported functions ------------------------------------------------------- */
|
|
||||||
|
|
||||||
int8_t Cmd_NUC_BuildChassisCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int8_t Cmd_NUC_BuildGimbalCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
int8_t Cmd_NUC_BuildShootCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************************************************************************/
|
|
||||||
/***************************************************************REF*******************************************************************/
|
|
||||||
/*************************************************************************************************************************************/
|
|
||||||
|
|
||||||
/* Includes ----------------------------------------------------------------- */
|
|
||||||
/* Private typedef ---------------------------------------------------------- */
|
|
||||||
/* Private define ----------------------------------------------------------- */
|
|
||||||
/* Private macro ------------------------------------------------------------ */
|
|
||||||
/* Private variables -------------------------------------------------------- */
|
|
||||||
/* Private function -------------------------------------------------------- */
|
|
||||||
int8_t Cmd_REF_Get(CMD_Input_REF_t *nuc) {
|
|
||||||
nuc->online=0;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
/* Exported functions ------------------------------------------------------- */
|
|
||||||
|
|
||||||
int8_t Cmd_REF_BuildChassisCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int8_t Cmd_REF_BuildGimbalCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
int8_t Cmd_REF_BuildShootCommandFromInput(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
/*************************************************************************************************************************************/
|
|
||||||
/***************************************************************仲裁器****************************************************************/
|
|
||||||
/*************************************************************************************************************************************/
|
|
||||||
|
|
||||||
/* Includes ----------------------------------------------------------------- */
|
|
||||||
/* Private typedef ---------------------------------------------------------- */
|
|
||||||
/* Private define ----------------------------------------------------------- */
|
|
||||||
/* Private macro ------------------------------------------------------------ */
|
|
||||||
/* Private variables -------------------------------------------------------- */
|
|
||||||
/* Private function -------------------------------------------------------- */
|
|
||||||
static inline bool Cmd_isREFOnline(CMD_t *c){return c->input.ref.online;}
|
|
||||||
static inline bool Cmd_isNUCOnline(CMD_t *c){return c->input.nuc.online;}
|
|
||||||
static inline bool Cmd_isRCOnline(CMD_t *c){return c->input.rc.online;}
|
|
||||||
static inline bool Cmd_isPCOnline(CMD_t *c){return c->input.pc.online;}
|
|
||||||
CMD_InputSource_t Cmd_GetHighestPrioritySource(CMD_t *c) {
|
|
||||||
for (int i = 0; i < CMD_SRC_NUM; i++) {
|
|
||||||
CMD_InputSource_t source = c->params->sourcePriorityConfigs[i];
|
|
||||||
switch (source) {
|
|
||||||
case CMD_SRC_REF:
|
|
||||||
if (Cmd_isREFOnline(c)) {
|
|
||||||
return CMD_SRC_REF;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CMD_SRC_NUC:
|
|
||||||
if (Cmd_isNUCOnline(c)) {
|
|
||||||
return CMD_SRC_NUC;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CMD_SRC_RC:
|
|
||||||
if (Cmd_isRCOnline(c)) {
|
|
||||||
return CMD_SRC_RC;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CMD_SRC_PC:
|
|
||||||
if (Cmd_isPCOnline(c)) {
|
|
||||||
return CMD_SRC_PC;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CMD_SRC_NUM:
|
|
||||||
return CMD_ERR_SOURCE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return CMD_ERR_SOURCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
int8_t Cmd_Arbiter(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
CMD_InputSource_t source = Cmd_GetHighestPrioritySource(c);
|
|
||||||
c->output.chassis.source = source;
|
|
||||||
c->output.gimbal.source = source;
|
|
||||||
c->output.shoot.source = source;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int8_t Cmd_Switch_RCorPC(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************************************************************************/
|
|
||||||
/***************************************************************主结构*****************************************************************/
|
|
||||||
/*************************************************************************************************************************************/
|
|
||||||
|
|
||||||
/* Includes ----------------------------------------------------------------- */
|
|
||||||
/* Private typedef ---------------------------------------------------------- */
|
|
||||||
typedef int8_t (*CMD_BuildCommandFunc)(CMD_t *c);
|
|
||||||
typedef struct {
|
|
||||||
CMD_InputSource_t source;
|
|
||||||
CMD_BuildCommandFunc chassisFunc;
|
|
||||||
CMD_BuildCommandFunc gimbalFunc;
|
|
||||||
CMD_BuildCommandFunc shootFunc;
|
|
||||||
} CMD_SourceHandler_t;
|
|
||||||
/* Private macro ------------------------------------------------------------ */
|
|
||||||
/* Private variables -------------------------------------------------------- */
|
|
||||||
CMD_SourceHandler_t sourceHandlers[CMD_SRC_NUM] = {
|
|
||||||
{CMD_SRC_RC, Cmd_RC_BuildChassisCommandFromInput, Cmd_RC_BuildGimbalCommandFromInput, Cmd_RC_BuildShootCommandFromInput},
|
|
||||||
{CMD_SRC_PC, Cmd_PC_BuildChassisCommandFromInput, Cmd_PC_BuildGimbalCommandFromInput, Cmd_PC_BuildShootCommandFromInput},
|
|
||||||
{CMD_SRC_NUC, Cmd_NUC_BuildChassisCommandFromInput, Cmd_NUC_BuildGimbalCommandFromInput, Cmd_NUC_BuildShootCommandFromInput},
|
|
||||||
{CMD_SRC_REF, Cmd_REF_BuildChassisCommandFromInput, Cmd_REF_BuildGimbalCommandFromInput, Cmd_REF_BuildShootCommandFromInput},
|
|
||||||
};
|
|
||||||
/* Private function -------------------------------------------------------- */
|
|
||||||
int8_t Cmd_OFFLINE(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
c->output.chassis.cmd.mode =CHASSIS_MODE_RELAX;
|
|
||||||
c->output.gimbal.cmd.mode =GIMBAL_MODE_RELAX;
|
|
||||||
c->output.shoot.cmd.mode =SHOOT_MODE_SAFE;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
/* Exported functions ------------------------------------------------------- */
|
|
||||||
int8_t Cmd_Init(CMD_t *c, CMD_Params_t *params) {
|
|
||||||
if (c == NULL || params == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
c->params = params;
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int8_t Cmd_Get(CMD_t *c,
|
|
||||||
CMD_RCType_TABLE(CMDMACRO_NAME_EXPANSION)){
|
|
||||||
// CMD_Input_NUC_t *nuc,
|
|
||||||
// CMD_Input_REF_t *ref) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
Cmd_RC_Get(c,CMD_RCType_TABLE(CMDMACRO_NAME_EXPANSION_1));
|
|
||||||
Cmd_PC_Get(c,CMD_RCType_TABLE(CMDMACRO_NAME_EXPANSION_1));
|
|
||||||
// Cmd_NUC_Get(&c->input.nuc);
|
|
||||||
// Cmd_REF_Get(&c->input.ref);
|
|
||||||
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int8_t Cmd_GenerateCommand(CMD_t *c) {
|
|
||||||
if (c == NULL) {
|
|
||||||
return CMD_ERR_NULL; // 参数错误
|
|
||||||
}
|
|
||||||
Cmd_Arbiter(c);
|
|
||||||
|
|
||||||
c->timer.now =BSP_TIME_Get_us() / 1000000.0f;
|
|
||||||
c->timer.dt =(BSP_TIME_Get_us() - c->timer.last) / 1000000.0f;
|
|
||||||
c->timer.last =BSP_TIME_Get_us();
|
|
||||||
if (c->output.chassis.source >= CMD_SRC_NUM || c->output.gimbal.source >= CMD_SRC_NUM || c->output.shoot.source >= CMD_SRC_NUM) {
|
|
||||||
Cmd_OFFLINE(c);
|
|
||||||
return CMD_ERR_SOURCE; // 输入源错误
|
|
||||||
}
|
|
||||||
sourceHandlers[c->output.chassis.source].chassisFunc(c);
|
|
||||||
sourceHandlers[c->output.gimbal.source].gimbalFunc(c);
|
|
||||||
sourceHandlers[c->output.shoot.source].shootFunc(c);
|
|
||||||
return CMD_OK;
|
|
||||||
}
|
|
||||||
@ -1,236 +0,0 @@
|
|||||||
/*
|
|
||||||
控制命令
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
/* Includes ----------------------------------------------------------------- */
|
|
||||||
#include "module/chassis.h"
|
|
||||||
#include "module/gimbal.h"
|
|
||||||
#include "module/shoot.h"
|
|
||||||
#if CMD_RCTypeTable_Index == 0
|
|
||||||
#include "device/dr16.h"
|
|
||||||
#elif CMD_RCTypeTable_Index == 1
|
|
||||||
#include "device/at9s_pro.h"
|
|
||||||
#elif CMD_RCTypeTable_Index == 2
|
|
||||||
#include "device/vt13.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Exported constants ------------------------------------------------------- */
|
|
||||||
#define CMD_OK (0) /* 运行正常 */
|
|
||||||
#define CMD_ERR_NULL (-1) /* 运行时发现NULL指针 */
|
|
||||||
#define CMD_ERR_ERR (-2) /* 运行时发现了其他错误 */
|
|
||||||
#define CMD_ERR_SOURCE (-3) /* 运行时配置了不存在的输入源 */
|
|
||||||
|
|
||||||
/* Exported macro ----------------------------------------------------------- */
|
|
||||||
#define CMD_RCTypeTable_Index 0 /* 0:DR16 1:AT9S 2:VT13 */
|
|
||||||
|
|
||||||
#if CMD_RCTypeTable_Index == 0
|
|
||||||
#define CMD_RCType_TABLE(X) X(dr16, DR16)
|
|
||||||
#elif CMD_RCTypeTable_Index == 1
|
|
||||||
#define CMD_RCType_TABLE(X) X(at9s, AT9S)
|
|
||||||
#elif CMD_RCTypeTable_Index == 2
|
|
||||||
#define CMD_RCType_TABLE(X) X(vt13, VT13)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if CMD_RCTypeTable_Index == 1
|
|
||||||
#define CMD_NOPC_FLAG
|
|
||||||
#endif
|
|
||||||
#define CMDMACRO_NAME_EXPANSION(name, NAME) NAME##_t name
|
|
||||||
#define CMDMACRO_VAR_RCDATA(name, NAME) NAME##_DataRC_t name;
|
|
||||||
#define CMDMACRO_VAR_PCDATA(name, NAME) NAME##_DataPC_t name;
|
|
||||||
#define CMDMACRO_VAR_LASTPCDATA(name, NAME) NAME##_DataPC_t last##name;
|
|
||||||
/* Exported types ----------------------------------------------------------- */
|
|
||||||
#define CMD_REFEREE_MAX_NUM (3) /* 发送命令限定的最大数量 */
|
|
||||||
/* 输入源枚举 */
|
|
||||||
typedef enum {
|
|
||||||
CMD_SRC_RC=0, /* 遥控器 */
|
|
||||||
CMD_SRC_PC, /* 键盘鼠标 */
|
|
||||||
CMD_SRC_NUC, /* 上位机 */
|
|
||||||
CMD_SRC_REF, /* 裁判系统 */
|
|
||||||
CMD_SRC_NUM
|
|
||||||
} CMD_InputSource_t;
|
|
||||||
|
|
||||||
/* RC part begin-------------------------------------- */
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool online;
|
|
||||||
enum {DR16=0, AT9S} type;
|
|
||||||
CMD_RCType_TABLE(CMDMACRO_VAR_RCDATA)
|
|
||||||
#undef CMDMACRO_VAR_RCDATA
|
|
||||||
} CMD_Input_RC_t;//或者这里直接把CMD_Input_RC_t前向声明了,看哪个好看
|
|
||||||
|
|
||||||
/* RC part end---------------------------------------- */
|
|
||||||
|
|
||||||
/* PC part begin-------------------------------------- */
|
|
||||||
typedef enum {
|
|
||||||
CMD_MODULE_NONE = 0,
|
|
||||||
CMD_MODULE_CHASSIS = (1 << 0),
|
|
||||||
CMD_MODULE_GIMBAL = (1 << 1),
|
|
||||||
CMD_MODULE_SHOOT = (1 << 2),
|
|
||||||
CMD_MODULE_ALL = (CMD_MODULE_CHASSIS | CMD_MODULE_GIMBAL | CMD_MODULE_SHOOT)
|
|
||||||
} CMD_ModuleMask_t;
|
|
||||||
/* 键盘按键值 */
|
|
||||||
typedef enum {
|
|
||||||
CMD_KEY_W = 0,
|
|
||||||
CMD_KEY_S,
|
|
||||||
CMD_KEY_A,
|
|
||||||
CMD_KEY_D,
|
|
||||||
CMD_KEY_SHIFT,
|
|
||||||
CMD_KEY_CTRL,
|
|
||||||
CMD_KEY_Q,
|
|
||||||
CMD_KEY_E,
|
|
||||||
CMD_KEY_R,
|
|
||||||
CMD_KEY_F,
|
|
||||||
CMD_KEY_G,
|
|
||||||
CMD_KEY_Z,
|
|
||||||
CMD_KEY_X,
|
|
||||||
CMD_KEY_C,
|
|
||||||
CMD_KEY_V,
|
|
||||||
CMD_KEY_B,
|
|
||||||
CMD_L_CLICK,
|
|
||||||
CMD_R_CLICK,
|
|
||||||
CMD_M_CLICK,
|
|
||||||
CMD_KEY_NUM,
|
|
||||||
} CMD_PCValue_t;
|
|
||||||
typedef enum {
|
|
||||||
CMD_ACTIVE_RISING_EDGE, /* 按下时触发 */
|
|
||||||
CMD_ACTIVE_FALLING_EDGE, /* 抬起时触发 */
|
|
||||||
CMD_ACTIVE_PRESSED, /* 按住时触发 */
|
|
||||||
} CMD_TriggerType_t;
|
|
||||||
|
|
||||||
/* 行为值序列 */
|
|
||||||
typedef enum {
|
|
||||||
CMD_BEHAVIOR_FORE = 0, /* 向前 */
|
|
||||||
CMD_BEHAVIOR_BACK, /* 向后 */
|
|
||||||
CMD_BEHAVIOR_LEFT, /* 向左 */
|
|
||||||
CMD_BEHAVIOR_RIGHT, /* 向右 */
|
|
||||||
CMD_BEHAVIOR_ACCELERATE, /* 加速 */
|
|
||||||
CMD_BEHAVIOR_DECELEBRATE, /* 减速 */
|
|
||||||
CMD_BEHAVIOR_FIRE, /* 开火 */
|
|
||||||
CMD_BEHAVIOR_FIRE_MODE, /* 切换开火模式 */
|
|
||||||
CMD_BEHAVIOR_BUFF, /* 打符模式 */
|
|
||||||
CMD_BEHAVIOR_AUTOAIM, /* 自瞄模式 */
|
|
||||||
CMD_BEHAVIOR_OPENCOVER, /* 弹舱盖开关 */
|
|
||||||
CMD_BEHAVIOR_ROTOR, /* 小陀螺模式 */
|
|
||||||
CMD_BEHAVIOR_REVTRIG, /* 反转拨弹 */
|
|
||||||
CMD_BEHAVIOR_FOLLOWGIMBAL35, /* 跟随云台呈35度 */
|
|
||||||
CMD_BEHAVIOR_GIMBAL_MODE, /* 切换云台模式 */
|
|
||||||
CMD_BEHAVIOR_NUM,
|
|
||||||
} CMD_Behavior_t;
|
|
||||||
typedef struct {
|
|
||||||
CMD_PCValue_t key;
|
|
||||||
CMD_TriggerType_t trigger_type;
|
|
||||||
} CMD_KeyMapItem_t;
|
|
||||||
|
|
||||||
/* 行为映射的对应按键数组 */
|
|
||||||
typedef struct {
|
|
||||||
CMD_KeyMapItem_t key_map[CMD_BEHAVIOR_NUM];
|
|
||||||
} CMD_KeyMap_Params_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
float sens_mouse; /* 鼠标灵敏度 */
|
|
||||||
float move_sense; /* 移动灵敏度 */
|
|
||||||
float move_fast_sense; /* 快速移动灵敏度 */
|
|
||||||
float move_slow_sense; /* 慢速移动灵敏度 */
|
|
||||||
} CMD_PC_Sensitivity_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
CMD_KeyMap_Params_t map; /* 按键映射行为命令 */
|
|
||||||
CMD_PC_Sensitivity_t sensitivity; /* PC灵敏度设置 */
|
|
||||||
}CMD_PCParams_t;
|
|
||||||
#ifndef CMD_NOPC_FLAG
|
|
||||||
typedef struct {
|
|
||||||
bool online;
|
|
||||||
CMD_RCType_TABLE(CMDMACRO_VAR_PCDATA)
|
|
||||||
CMD_RCType_TABLE(CMDMACRO_VAR_LASTPCDATA)
|
|
||||||
#undef CMDMACRO_VAR_PCDATA
|
|
||||||
#undef CMDMACRO_VAR_LASTPCDATA
|
|
||||||
}CMD_Input_PC_t;
|
|
||||||
#else
|
|
||||||
typedef struct {
|
|
||||||
bool online;
|
|
||||||
}CMD_Input_PC_t;
|
|
||||||
#endif
|
|
||||||
/* PC part end---------------------------------------- */
|
|
||||||
|
|
||||||
/* NUC part begin------------------------------------- */
|
|
||||||
typedef struct {
|
|
||||||
bool online;
|
|
||||||
struct {
|
|
||||||
float delta_yaw;
|
|
||||||
float delta_pit;
|
|
||||||
}gimbal;
|
|
||||||
struct {
|
|
||||||
float expectedSpeed;
|
|
||||||
bool fire;
|
|
||||||
}shoot;
|
|
||||||
}CMD_Input_NUC_t;
|
|
||||||
|
|
||||||
/* NUC part end--------------------------------------- */
|
|
||||||
|
|
||||||
/* REF part begin------------------------------------- */
|
|
||||||
typedef struct {
|
|
||||||
bool online;
|
|
||||||
}CMD_Input_REF_t;
|
|
||||||
|
|
||||||
/* REF part begin------------------------------------- */
|
|
||||||
|
|
||||||
/* 底盘控制命令 */
|
|
||||||
typedef struct {
|
|
||||||
CMD_InputSource_t source;
|
|
||||||
Chassis_CMD_t cmd;
|
|
||||||
} CMD_Output_CHASSIS_t;
|
|
||||||
|
|
||||||
/* 云台控制命令 */
|
|
||||||
typedef struct {
|
|
||||||
CMD_InputSource_t source;
|
|
||||||
Gimbal_CMD_t cmd;
|
|
||||||
} CMD_Output_GIMBAL_t;
|
|
||||||
|
|
||||||
/* 射击控制命令 */
|
|
||||||
typedef struct {
|
|
||||||
CMD_InputSource_t source;
|
|
||||||
Shoot_CMD_t cmd;
|
|
||||||
} CMD_Output_SHOOT_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
CMD_Input_RC_t rc;
|
|
||||||
CMD_Input_PC_t pc;
|
|
||||||
CMD_Input_NUC_t nuc;
|
|
||||||
CMD_Input_REF_t ref;
|
|
||||||
} CMD_Input_t;
|
|
||||||
typedef struct {
|
|
||||||
CMD_Output_CHASSIS_t chassis;
|
|
||||||
CMD_Output_GIMBAL_t gimbal;
|
|
||||||
CMD_Output_SHOOT_t shoot;
|
|
||||||
} CMD_Output_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
CMD_InputSource_t sourcePriorityConfigs[CMD_SRC_NUM];/* 输入源优先级配置 */
|
|
||||||
CMD_PCParams_t pc;
|
|
||||||
} CMD_Params_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
float now;
|
|
||||||
float dt;
|
|
||||||
uint64_t last;
|
|
||||||
} CMD_Timer_t;
|
|
||||||
typedef struct {
|
|
||||||
CMD_Timer_t timer;
|
|
||||||
CMD_Params_t *params;
|
|
||||||
|
|
||||||
CMD_Input_t input;
|
|
||||||
CMD_Output_t output;
|
|
||||||
} CMD_t;
|
|
||||||
|
|
||||||
/* Exported functions prototypes -------------------------------------------- */
|
|
||||||
int8_t Cmd_Init(CMD_t *c, CMD_Params_t *params);
|
|
||||||
int8_t Cmd_Get(CMD_t *c, CMD_RCType_TABLE(CMDMACRO_NAME_EXPANSION));
|
|
||||||
int8_t Cmd_GenerateCommand(CMD_t *c);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@ -11,7 +11,7 @@
|
|||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
|
|
||||||
/* 从RC输入生成底盘命令 */
|
/* 从RC输入生成底盘命令 */
|
||||||
static void CMD_RC_BuildChassisCmd(CMD_Context_t *ctx, const CMD_RawInput_t *input) {
|
static void CMD_RC_BuildChassisCmd(CMD_t *ctx, const CMD_RawInput_t *input) {
|
||||||
CMD_RCModeMap_t *map = &ctx->config->rc_mode_map;
|
CMD_RCModeMap_t *map = &ctx->config->rc_mode_map;
|
||||||
|
|
||||||
/* 根据左拨杆位置选择模式 */
|
/* 根据左拨杆位置选择模式 */
|
||||||
@ -36,7 +36,7 @@ static void CMD_RC_BuildChassisCmd(CMD_Context_t *ctx, const CMD_RawInput_t *inp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 从RC输入生成云台命令 */
|
/* 从RC输入生成云台命令 */
|
||||||
static void CMD_RC_BuildGimbalCmd(CMD_Context_t *ctx, const CMD_RawInput_t *input) {
|
static void CMD_RC_BuildGimbalCmd(CMD_t *ctx, const CMD_RawInput_t *input) {
|
||||||
CMD_RCModeMap_t *map = &ctx->config->rc_mode_map;
|
CMD_RCModeMap_t *map = &ctx->config->rc_mode_map;
|
||||||
|
|
||||||
/* 根据拨杆选择云台模式 */
|
/* 根据拨杆选择云台模式 */
|
||||||
@ -61,7 +61,7 @@ static void CMD_RC_BuildGimbalCmd(CMD_Context_t *ctx, const CMD_RawInput_t *inpu
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 从RC输入生成射击命令 */
|
/* 从RC输入生成射击命令 */
|
||||||
static void CMD_RC_BuildShootCmd(CMD_Context_t *ctx, const CMD_RawInput_t *input) {
|
static void CMD_RC_BuildShootCmd(CMD_t *ctx, const CMD_RawInput_t *input) {
|
||||||
if (input->online) {
|
if (input->online) {
|
||||||
ctx->shoot.cmd.mode = SHOOT_MODE_SINGLE;
|
ctx->shoot.cmd.mode = SHOOT_MODE_SINGLE;
|
||||||
} else {
|
} else {
|
||||||
@ -87,7 +87,7 @@ static void CMD_RC_BuildShootCmd(CMD_Context_t *ctx, const CMD_RawInput_t *input
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 从PC输入生成底盘命令 */
|
/* 从PC输入生成底盘命令 */
|
||||||
static void CMD_PC_BuildChassisCmd(CMD_Context_t *ctx, const CMD_RawInput_t *input) {
|
static void CMD_PC_BuildChassisCmd(CMD_t *ctx, const CMD_RawInput_t *input) {
|
||||||
CMD_Sensitivity_t *sens = &ctx->config->sensitivity;
|
CMD_Sensitivity_t *sens = &ctx->config->sensitivity;
|
||||||
|
|
||||||
if (!input->online) {
|
if (!input->online) {
|
||||||
@ -126,7 +126,7 @@ static void CMD_PC_BuildChassisCmd(CMD_Context_t *ctx, const CMD_RawInput_t *inp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 从PC输入生成云台命令 */
|
/* 从PC输入生成云台命令 */
|
||||||
static void CMD_PC_BuildGimbalCmd(CMD_Context_t *ctx, const CMD_RawInput_t *input) {
|
static void CMD_PC_BuildGimbalCmd(CMD_t *ctx, const CMD_RawInput_t *input) {
|
||||||
CMD_Sensitivity_t *sens = &ctx->config->sensitivity;
|
CMD_Sensitivity_t *sens = &ctx->config->sensitivity;
|
||||||
|
|
||||||
if (!input->online) {
|
if (!input->online) {
|
||||||
@ -142,7 +142,7 @@ static void CMD_PC_BuildGimbalCmd(CMD_Context_t *ctx, const CMD_RawInput_t *inpu
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 从PC输入生成射击命令 */
|
/* 从PC输入生成射击命令 */
|
||||||
static void CMD_PC_BuildShootCmd(CMD_Context_t *ctx, const CMD_RawInput_t *input) {
|
static void CMD_PC_BuildShootCmd(CMD_t *ctx, const CMD_RawInput_t *input) {
|
||||||
if (!input->online) {
|
if (!input->online) {
|
||||||
ctx->shoot.cmd.mode = SHOOT_MODE_SAFE;
|
ctx->shoot.cmd.mode = SHOOT_MODE_SAFE;
|
||||||
return;
|
return;
|
||||||
@ -153,7 +153,7 @@ static void CMD_PC_BuildShootCmd(CMD_Context_t *ctx, const CMD_RawInput_t *input
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 离线安全模式 */
|
/* 离线安全模式 */
|
||||||
static void CMD_SetOfflineMode(CMD_Context_t *ctx) {
|
static void CMD_SetOfflineMode(CMD_t *ctx) {
|
||||||
ctx->chassis.cmd.mode = CHASSIS_MODE_RELAX;
|
ctx->chassis.cmd.mode = CHASSIS_MODE_RELAX;
|
||||||
ctx->gimbal.cmd.mode = GIMBAL_MODE_RELAX;
|
ctx->gimbal.cmd.mode = GIMBAL_MODE_RELAX;
|
||||||
ctx->shoot.cmd.mode = SHOOT_MODE_SAFE;
|
ctx->shoot.cmd.mode = SHOOT_MODE_SAFE;
|
||||||
@ -163,12 +163,12 @@ static void CMD_SetOfflineMode(CMD_Context_t *ctx) {
|
|||||||
/* 公开API实现 */
|
/* 公开API实现 */
|
||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
|
|
||||||
int8_t CMD_Init(CMD_Context_t *ctx, CMD_Config_t *config) {
|
int8_t CMD_Init(CMD_t *ctx, CMD_Config_t *config) {
|
||||||
if (ctx == NULL || config == NULL) {
|
if (ctx == NULL || config == NULL) {
|
||||||
return CMD_ERR_NULL;
|
return CMD_ERR_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(ctx, 0, sizeof(CMD_Context_t));
|
memset(ctx, 0, sizeof(CMD_t));
|
||||||
ctx->config = config;
|
ctx->config = config;
|
||||||
|
|
||||||
/* 初始化适配器 */
|
/* 初始化适配器 */
|
||||||
@ -180,7 +180,7 @@ int8_t CMD_Init(CMD_Context_t *ctx, CMD_Config_t *config) {
|
|||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t CMD_UpdateInput(CMD_Context_t *ctx) {
|
int8_t CMD_UpdateInput(CMD_t *ctx) {
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
return CMD_ERR_NULL;
|
return CMD_ERR_NULL;
|
||||||
}
|
}
|
||||||
@ -196,12 +196,12 @@ int8_t CMD_UpdateInput(CMD_Context_t *ctx) {
|
|||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t CMD_Arbitrate(CMD_Context_t *ctx) {
|
int8_t CMD_Arbitrate(CMD_t *ctx) {
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
return CMD_ERR_NULL;
|
return CMD_ERR_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 智能仲裁算法:优先级 PC > RC > NUC */
|
/* 自动仲裁:优先级 PC > RC > NUC */
|
||||||
CMD_InputSource_t candidates[] = {CMD_SRC_PC, CMD_SRC_RC, CMD_SRC_NUC};
|
CMD_InputSource_t candidates[] = {CMD_SRC_PC, CMD_SRC_RC, CMD_SRC_NUC};
|
||||||
const int num_candidates = sizeof(candidates) / sizeof(candidates[0]);
|
const int num_candidates = sizeof(candidates) / sizeof(candidates[0]);
|
||||||
|
|
||||||
@ -217,23 +217,23 @@ int8_t CMD_Arbitrate(CMD_Context_t *ctx) {
|
|||||||
CMD_InputSource_t src = candidates[i];
|
CMD_InputSource_t src = candidates[i];
|
||||||
if (ctx->input[src].online) {
|
if (ctx->input[src].online) {
|
||||||
ctx->active_source = src;
|
ctx->active_source = src;
|
||||||
|
break;
|
||||||
|
}else {
|
||||||
|
ctx->active_source = CMD_SRC_NUM;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx->chassis.source = ctx->active_source;
|
ctx->chassis.source = ctx->active_source;
|
||||||
ctx->gimbal.source = ctx->active_source;
|
ctx->gimbal.source = ctx->active_source;
|
||||||
ctx->shoot.source = ctx->active_source;
|
ctx->shoot.source = ctx->active_source;
|
||||||
|
|
||||||
|
/* 优先级抢占逻辑 */
|
||||||
seize:
|
seize:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* 没有可用输入源 */
|
|
||||||
ctx->active_source = CMD_SRC_NUM;
|
|
||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t CMD_GenerateCommands(CMD_Context_t *ctx) {
|
int8_t CMD_GenerateCommands(CMD_t *ctx) {
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
return CMD_ERR_NULL;
|
return CMD_ERR_NULL;
|
||||||
}
|
}
|
||||||
@ -282,7 +282,7 @@ int8_t CMD_GenerateCommands(CMD_Context_t *ctx) {
|
|||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t CMD_Update(CMD_Context_t *ctx) {
|
int8_t CMD_Update(CMD_t *ctx) {
|
||||||
int8_t ret;
|
int8_t ret;
|
||||||
|
|
||||||
ret = CMD_UpdateInput(ctx);
|
ret = CMD_UpdateInput(ctx);
|
||||||
|
|||||||
@ -74,8 +74,6 @@ typedef struct {
|
|||||||
/* RC模式映射 */
|
/* RC模式映射 */
|
||||||
CMD_RCModeMap_t rc_mode_map;
|
CMD_RCModeMap_t rc_mode_map;
|
||||||
|
|
||||||
/* 是否启用PC输入 */
|
|
||||||
bool enable_pc_input;
|
|
||||||
} CMD_Config_t;
|
} CMD_Config_t;
|
||||||
|
|
||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
@ -107,7 +105,7 @@ typedef struct CMD_Context {
|
|||||||
CMD_GimbalOutput_t gimbal;
|
CMD_GimbalOutput_t gimbal;
|
||||||
CMD_ShootOutput_t shoot;
|
CMD_ShootOutput_t shoot;
|
||||||
|
|
||||||
} CMD_Context_t;
|
} CMD_t;
|
||||||
|
|
||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
/* 主API接口 */
|
/* 主API接口 */
|
||||||
@ -119,52 +117,52 @@ typedef struct CMD_Context {
|
|||||||
* @param config 配置指针
|
* @param config 配置指针
|
||||||
* @return CMD_OK成功,其他失败
|
* @return CMD_OK成功,其他失败
|
||||||
*/
|
*/
|
||||||
int8_t CMD_Init(CMD_Context_t *ctx, CMD_Config_t *config);
|
int8_t CMD_Init(CMD_t *ctx, CMD_Config_t *config);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 更新所有输入源的数据
|
* @brief 更新所有输入源的数据
|
||||||
* @param ctx CMD上下文
|
* @param ctx CMD上下文
|
||||||
* @return CMD_OK成功
|
* @return CMD_OK成功
|
||||||
*/
|
*/
|
||||||
int8_t CMD_UpdateInput(CMD_Context_t *ctx);
|
int8_t CMD_UpdateInput(CMD_t *ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 执行仲裁,决定使用哪个输入源
|
* @brief 执行仲裁,决定使用哪个输入源
|
||||||
* @param ctx CMD上下文
|
* @param ctx CMD上下文
|
||||||
* @return 选中的输入源
|
* @return 选中的输入源
|
||||||
*/
|
*/
|
||||||
int8_t CMD_Arbitrate(CMD_Context_t *ctx);
|
int8_t CMD_Arbitrate(CMD_t *ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 生成所有模块的控制命令
|
* @brief 生成所有模块的控制命令
|
||||||
* @param ctx CMD上下文
|
* @param ctx CMD上下文
|
||||||
* @return CMD_OK成功
|
* @return CMD_OK成功
|
||||||
*/
|
*/
|
||||||
int8_t CMD_GenerateCommands(CMD_Context_t *ctx);
|
int8_t CMD_GenerateCommands(CMD_t *ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 一键更新(包含UpdateInput + Arbitrate + GenerateCommands)
|
* @brief 一键更新(包含UpdateInput + Arbitrate + GenerateCommands)
|
||||||
* @param ctx CMD上下文
|
* @param ctx CMD上下文
|
||||||
* @return CMD_OK成功
|
* @return CMD_OK成功
|
||||||
*/
|
*/
|
||||||
int8_t CMD_Update(CMD_Context_t *ctx);
|
int8_t CMD_Update(CMD_t *ctx);
|
||||||
|
|
||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
/* 输出获取接口 */
|
/* 输出获取接口 */
|
||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
|
|
||||||
/* 获取底盘命令 */
|
/* 获取底盘命令 */
|
||||||
static inline Chassis_CMD_t* CMD_GetChassisCmd(CMD_Context_t *ctx) {
|
static inline Chassis_CMD_t* CMD_GetChassisCmd(CMD_t *ctx) {
|
||||||
return &ctx->chassis.cmd;
|
return &ctx->chassis.cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 获取云台命令 */
|
/* 获取云台命令 */
|
||||||
static inline Gimbal_CMD_t* CMD_GetGimbalCmd(CMD_Context_t *ctx) {
|
static inline Gimbal_CMD_t* CMD_GetGimbalCmd(CMD_t *ctx) {
|
||||||
return &ctx->gimbal.cmd;
|
return &ctx->gimbal.cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 获取射击命令 */
|
/* 获取射击命令 */
|
||||||
static inline Shoot_CMD_t* CMD_GetShootCmd(CMD_Context_t *ctx) {
|
static inline Shoot_CMD_t* CMD_GetShootCmd(CMD_t *ctx) {
|
||||||
return &ctx->shoot.cmd;
|
return &ctx->shoot.cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,8 @@
|
|||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
/* 适配器存储 */
|
/* 适配器存储 */
|
||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
static CMD_InputAdapter_t *g_adapters[CMD_SRC_NUM] = {0};
|
// static CMD_InputAdapter_t *g_adapters[CMD_SRC_NUM] = {0};
|
||||||
|
CMD_InputAdapter_t *g_adapters[CMD_SRC_NUM] = {0};
|
||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
/* DR16 适配器实现 */
|
/* DR16 适配器实现 */
|
||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
@ -66,7 +66,7 @@ int8_t CMD_DR16_PC_GetInput(void *data, CMD_RawInput_t *output) {
|
|||||||
output->mouse.r_click = dr16->data.pc.mouse.r_click;
|
output->mouse.r_click = dr16->data.pc.mouse.r_click;
|
||||||
|
|
||||||
/* 键盘映射 */
|
/* 键盘映射 */
|
||||||
output->keyboard.bitmap = dr16->data.pc.keyboard.value;
|
output->keyboard.bitmap = dr16->raw_data.key;
|
||||||
|
|
||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
@ -75,10 +75,10 @@ bool CMD_DR16_IsOnline(void *data) {
|
|||||||
DR16_t *dr16 = (DR16_t *)data;
|
DR16_t *dr16 = (DR16_t *)data;
|
||||||
return dr16->header.online;
|
return dr16->header.online;
|
||||||
}
|
}
|
||||||
|
extern DR16_t cmd_dr16;
|
||||||
/* 定义适配器实例 */
|
/* 定义适配器实例 */
|
||||||
CMD_DEFINE_ADAPTER(DR16_RC, dr16, CMD_SRC_RC, CMD_DR16_Init, CMD_DR16_RC_GetInput, CMD_DR16_IsOnline)
|
CMD_DEFINE_ADAPTER(DR16_RC, cmd_dr16, CMD_SRC_RC, CMD_DR16_Init, CMD_DR16_RC_GetInput, CMD_DR16_IsOnline)
|
||||||
CMD_DEFINE_ADAPTER(DR16_PC, dr16, CMD_SRC_PC, CMD_DR16_Init, CMD_DR16_PC_GetInput, CMD_DR16_IsOnline)
|
CMD_DEFINE_ADAPTER(DR16_PC, cmd_dr16, CMD_SRC_PC, CMD_DR16_Init, CMD_DR16_PC_GetInput, CMD_DR16_IsOnline)
|
||||||
|
|
||||||
#endif /* CMD_RC_DEVICE_TYPE == 0 */
|
#endif /* CMD_RC_DEVICE_TYPE == 0 */
|
||||||
|
|
||||||
|
|||||||
@ -10,49 +10,49 @@
|
|||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
|
|
||||||
/* 行为处理函数实现 */
|
/* 行为处理函数实现 */
|
||||||
int8_t CMD_Behavior_Handle_FORE(CMD_Context_t *ctx) {
|
int8_t CMD_Behavior_Handle_FORE(CMD_t *ctx) {
|
||||||
ctx->chassis.cmd.ctrl_vec.vy += ctx->config->sensitivity.move_sens;
|
ctx->chassis.cmd.ctrl_vec.vy += ctx->config->sensitivity.move_sens;
|
||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t CMD_Behavior_Handle_BACK(CMD_Context_t *ctx) {
|
int8_t CMD_Behavior_Handle_BACK(CMD_t *ctx) {
|
||||||
ctx->chassis.cmd.ctrl_vec.vy -= ctx->config->sensitivity.move_sens;
|
ctx->chassis.cmd.ctrl_vec.vy -= ctx->config->sensitivity.move_sens;
|
||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t CMD_Behavior_Handle_LEFT(CMD_Context_t *ctx) {
|
int8_t CMD_Behavior_Handle_LEFT(CMD_t *ctx) {
|
||||||
ctx->chassis.cmd.ctrl_vec.vx -= ctx->config->sensitivity.move_sens;
|
ctx->chassis.cmd.ctrl_vec.vx -= ctx->config->sensitivity.move_sens;
|
||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t CMD_Behavior_Handle_RIGHT(CMD_Context_t *ctx) {
|
int8_t CMD_Behavior_Handle_RIGHT(CMD_t *ctx) {
|
||||||
ctx->chassis.cmd.ctrl_vec.vx += ctx->config->sensitivity.move_sens;
|
ctx->chassis.cmd.ctrl_vec.vx += ctx->config->sensitivity.move_sens;
|
||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t CMD_Behavior_Handle_ACCELERATE(CMD_Context_t *ctx) {
|
int8_t CMD_Behavior_Handle_ACCELERATE(CMD_t *ctx) {
|
||||||
ctx->chassis.cmd.ctrl_vec.vx *= ctx->config->sensitivity.move_fast_mult;
|
ctx->chassis.cmd.ctrl_vec.vx *= ctx->config->sensitivity.move_fast_mult;
|
||||||
ctx->chassis.cmd.ctrl_vec.vy *= ctx->config->sensitivity.move_fast_mult;
|
ctx->chassis.cmd.ctrl_vec.vy *= ctx->config->sensitivity.move_fast_mult;
|
||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t CMD_Behavior_Handle_DECELERATE(CMD_Context_t *ctx) {
|
int8_t CMD_Behavior_Handle_DECELERATE(CMD_t *ctx) {
|
||||||
ctx->chassis.cmd.ctrl_vec.vx *= ctx->config->sensitivity.move_slow_mult;
|
ctx->chassis.cmd.ctrl_vec.vx *= ctx->config->sensitivity.move_slow_mult;
|
||||||
ctx->chassis.cmd.ctrl_vec.vy *= ctx->config->sensitivity.move_slow_mult;
|
ctx->chassis.cmd.ctrl_vec.vy *= ctx->config->sensitivity.move_slow_mult;
|
||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t CMD_Behavior_Handle_FIRE(CMD_Context_t *ctx) {
|
int8_t CMD_Behavior_Handle_FIRE(CMD_t *ctx) {
|
||||||
ctx->shoot.cmd.firecmd = true;
|
ctx->shoot.cmd.firecmd = true;
|
||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t CMD_Behavior_Handle_FIRE_MODE(CMD_Context_t *ctx) {
|
int8_t CMD_Behavior_Handle_FIRE_MODE(CMD_t *ctx) {
|
||||||
ctx->shoot.cmd.mode = (ctx->shoot.cmd.mode + 1) % SHOOT_MODE_NUM;
|
ctx->shoot.cmd.mode = (ctx->shoot.cmd.mode + 1) % SHOOT_MODE_NUM;
|
||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t CMD_Behavior_Handle_ROTOR(CMD_Context_t *ctx) {
|
int8_t CMD_Behavior_Handle_ROTOR(CMD_t *ctx) {
|
||||||
if (ctx->chassis.cmd.mode == CHASSIS_MODE_ROTOR) {
|
if (ctx->chassis.cmd.mode == CHASSIS_MODE_ROTOR) {
|
||||||
ctx->chassis.cmd.mode = CHASSIS_MODE_FOLLOW_GIMBAL;
|
ctx->chassis.cmd.mode = CHASSIS_MODE_FOLLOW_GIMBAL;
|
||||||
} else {
|
} else {
|
||||||
@ -62,7 +62,7 @@ int8_t CMD_Behavior_Handle_ROTOR(CMD_Context_t *ctx) {
|
|||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t CMD_Behavior_Handle_AUTOAIM(CMD_Context_t *ctx) {
|
int8_t CMD_Behavior_Handle_AUTOAIM(CMD_t *ctx) {
|
||||||
/* TODO: 自瞄模式切换 */
|
/* TODO: 自瞄模式切换 */
|
||||||
return CMD_OK;
|
return CMD_OK;
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ bool CMD_Behavior_IsTriggered(const CMD_RawInput_t *current,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t CMD_Behavior_ProcessAll(CMD_Context_t *ctx,
|
int8_t CMD_Behavior_ProcessAll(CMD_t *ctx,
|
||||||
const CMD_RawInput_t *current,
|
const CMD_RawInput_t *current,
|
||||||
const CMD_RawInput_t *last,
|
const CMD_RawInput_t *last,
|
||||||
CMD_ModuleMask_t active_modules) {
|
CMD_ModuleMask_t active_modules) {
|
||||||
|
|||||||
@ -10,15 +10,7 @@
|
|||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
|
|
||||||
/* 默认配置 */
|
/* 默认配置 */
|
||||||
static CMD_Config_t g_cmd_config = {
|
static CMD_Config_t g_cmd_config = {
|
||||||
/* 输入源优先级:RC > PC > NUC > REF */
|
|
||||||
.source_priority = {
|
|
||||||
CMD_SRC_RC,
|
|
||||||
CMD_SRC_PC,
|
|
||||||
CMD_SRC_NUC,
|
|
||||||
CMD_SRC_REF,
|
|
||||||
},
|
|
||||||
|
|
||||||
/* 灵敏度设置 */
|
/* 灵敏度设置 */
|
||||||
.sensitivity = {
|
.sensitivity = {
|
||||||
.mouse_sens = 0.8f,
|
.mouse_sens = 0.8f,
|
||||||
@ -40,11 +32,10 @@ static CMD_Config_t g_cmd_config = {
|
|||||||
.gimbal_sw_down = GIMBAL_MODE_RELATIVE,
|
.gimbal_sw_down = GIMBAL_MODE_RELATIVE,
|
||||||
},
|
},
|
||||||
|
|
||||||
.enable_pc_input = true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* CMD上下文 */
|
/* CMD上下文 */
|
||||||
static CMD_Context_t g_cmd_ctx;
|
static CMD_t g_cmd_ctx;
|
||||||
|
|
||||||
/* ========================================================================== */
|
/* ========================================================================== */
|
||||||
/* 任务示例 */
|
/* 任务示例 */
|
||||||
@ -148,6 +139,6 @@ void Example_CMD_Task(void) {
|
|||||||
*
|
*
|
||||||
* ### 添加新输出模块
|
* ### 添加新输出模块
|
||||||
* 1. 在 CMD_OUTPUT_MODULE_TABLE 添加条目
|
* 1. 在 CMD_OUTPUT_MODULE_TABLE 添加条目
|
||||||
* 2. 在 CMD_Context_t 中添加输出成员
|
* 2. 在 CMD_t 中添加输出成员
|
||||||
* 3. 实现对应的 BuildXXXCmd 函数
|
* 3. 实现对应的 BuildXXXCmd 函数
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -28,10 +28,10 @@ extern "C" {
|
|||||||
* 格式: X(枚举名, 优先级, 适配器初始化函数, 获取数据函数)
|
* 格式: X(枚举名, 优先级, 适配器初始化函数, 获取数据函数)
|
||||||
*/
|
*/
|
||||||
#define CMD_INPUT_SOURCE_TABLE(X) \
|
#define CMD_INPUT_SOURCE_TABLE(X) \
|
||||||
X(RC, 0, CMD_RC_AdapterInit, CMD_RC_GetInput) \
|
X(RC, CMD_RC_AdapterInit, CMD_RC_GetInput) \
|
||||||
X(PC, 1, CMD_PC_AdapterInit, CMD_PC_GetInput) \
|
X(PC, CMD_PC_AdapterInit, CMD_PC_GetInput) \
|
||||||
X(NUC, 2, CMD_NUC_AdapterInit, CMD_NUC_GetInput) \
|
X(NUC, CMD_NUC_AdapterInit, CMD_NUC_GetInput) \
|
||||||
X(REF, 3, CMD_REF_AdapterInit, CMD_REF_GetInput)
|
X(REF, CMD_REF_AdapterInit, CMD_REF_GetInput)
|
||||||
|
|
||||||
/* 输出模块配置宏表 */
|
/* 输出模块配置宏表 */
|
||||||
#define CMD_OUTPUT_MODULE_TABLE(X) \
|
#define CMD_OUTPUT_MODULE_TABLE(X) \
|
||||||
@ -139,7 +139,7 @@ typedef enum {
|
|||||||
X(RIGHT, CMD_KEY_D, CMD_ACTIVE_PRESSED, CMD_MODULE_CHASSIS) \
|
X(RIGHT, CMD_KEY_D, CMD_ACTIVE_PRESSED, CMD_MODULE_CHASSIS) \
|
||||||
X(ACCELERATE, CMD_KEY_SHIFT, CMD_ACTIVE_PRESSED, CMD_MODULE_CHASSIS) \
|
X(ACCELERATE, CMD_KEY_SHIFT, CMD_ACTIVE_PRESSED, CMD_MODULE_CHASSIS) \
|
||||||
X(DECELERATE, CMD_KEY_CTRL, CMD_ACTIVE_PRESSED, CMD_MODULE_CHASSIS) \
|
X(DECELERATE, CMD_KEY_CTRL, CMD_ACTIVE_PRESSED, CMD_MODULE_CHASSIS) \
|
||||||
X(FIRE, CMD_KEY_NONE, CMD_ACTIVE_PRESSED, CMD_MODULE_SHOOT) \
|
X(FIRE, CMD_KEY_L_CLICK, CMD_ACTIVE_PRESSED, CMD_MODULE_SHOOT) \
|
||||||
X(FIRE_MODE, CMD_KEY_B, CMD_ACTIVE_RISING_EDGE, CMD_MODULE_SHOOT) \
|
X(FIRE_MODE, CMD_KEY_B, CMD_ACTIVE_RISING_EDGE, CMD_MODULE_SHOOT) \
|
||||||
X(ROTOR, CMD_KEY_E, CMD_ACTIVE_RISING_EDGE, CMD_MODULE_CHASSIS) \
|
X(ROTOR, CMD_KEY_E, CMD_ACTIVE_RISING_EDGE, CMD_MODULE_CHASSIS) \
|
||||||
X(AUTOAIM, CMD_KEY_R, CMD_ACTIVE_RISING_EDGE, CMD_MODULE_GIMBAL | CMD_MODULE_SHOOT)
|
X(AUTOAIM, CMD_KEY_R, CMD_ACTIVE_RISING_EDGE, CMD_MODULE_GIMBAL | CMD_MODULE_SHOOT)
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
#include "module/config.h"
|
#include "module/config.h"
|
||||||
#include "bsp/can.h"
|
#include "bsp/can.h"
|
||||||
#include "device/motor_dm.h"
|
#include "device/motor_dm.h"
|
||||||
#include "module/cmd.h"
|
#include "module/cmd_v2/cmd.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
/* Private typedef ---------------------------------------------------------- */
|
/* Private typedef ---------------------------------------------------------- */
|
||||||
/* Private define ----------------------------------------------------------- */
|
/* Private define ----------------------------------------------------------- */
|
||||||
@ -196,7 +196,7 @@ Config_RobotParam_t robot_config = {
|
|||||||
.reverse = false,
|
.reverse = false,
|
||||||
},
|
},
|
||||||
.yaw_motor = {
|
.yaw_motor = {
|
||||||
.can = BSP_CAN_1,
|
.can = BSP_CAN_2,
|
||||||
.can_id = 0x50,
|
.can_id = 0x50,
|
||||||
.master_id = 0x60,
|
.master_id = 0x60,
|
||||||
.module = MOTOR_DM_J4310,
|
.module = MOTOR_DM_J4310,
|
||||||
@ -363,39 +363,58 @@ Config_RobotParam_t robot_config = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// .cmd_param={
|
||||||
|
// .sourcePriorityConfigs={
|
||||||
|
// CMD_SRC_RC,
|
||||||
|
// CMD_SRC_PC,
|
||||||
|
// CMD_SRC_NUC,
|
||||||
|
// CMD_SRC_REF
|
||||||
|
// },
|
||||||
|
// .pc.map = { /*1<<CMD_KEY_W记录一下不要忘了这个思路 */
|
||||||
|
// .key_map[CMD_BEHAVIOR_FORE] = {CMD_KEY_W, CMD_ACTIVE_PRESSED},
|
||||||
|
// .key_map[CMD_BEHAVIOR_BACK] = {CMD_KEY_S, CMD_ACTIVE_PRESSED},
|
||||||
|
// .key_map[CMD_BEHAVIOR_LEFT] = {CMD_KEY_A, CMD_ACTIVE_PRESSED},
|
||||||
|
// .key_map[CMD_BEHAVIOR_RIGHT] = {CMD_KEY_D, CMD_ACTIVE_PRESSED},
|
||||||
|
// .key_map[CMD_BEHAVIOR_ACCELERATE] = {CMD_KEY_SHIFT, CMD_ACTIVE_PRESSED},
|
||||||
|
// .key_map[CMD_BEHAVIOR_DECELEBRATE] = {CMD_KEY_CTRL, CMD_ACTIVE_PRESSED},
|
||||||
|
// .key_map[CMD_BEHAVIOR_FIRE] = {CMD_L_CLICK, CMD_ACTIVE_PRESSED},
|
||||||
|
// .key_map[CMD_BEHAVIOR_FIRE_MODE] = {CMD_R_CLICK, CMD_ACTIVE_RISING_EDGE},
|
||||||
|
// .key_map[CMD_BEHAVIOR_FOLLOWGIMBAL35] = {CMD_KEY_E, CMD_ACTIVE_RISING_EDGE},
|
||||||
|
// .key_map[CMD_BEHAVIOR_OPENCOVER] = {CMD_KEY_F, CMD_ACTIVE_RISING_EDGE},
|
||||||
|
// .key_map[CMD_BEHAVIOR_REVTRIG] = {CMD_KEY_R, CMD_ACTIVE_RISING_EDGE},
|
||||||
|
// .key_map[CMD_BEHAVIOR_ROTOR] = {CMD_KEY_G, CMD_ACTIVE_PRESSED},
|
||||||
|
// .key_map[CMD_BEHAVIOR_GIMBAL_MODE] = {CMD_KEY_V, CMD_ACTIVE_RISING_EDGE},
|
||||||
|
// },
|
||||||
|
// .pc.sensitivity={
|
||||||
|
|
||||||
|
// .move_sense=0.1f,
|
||||||
|
// .sens_mouse=3.0f,
|
||||||
|
// .move_fast_sense=2.4f,
|
||||||
|
// .move_slow_sense=0.8f
|
||||||
|
// },
|
||||||
|
// },
|
||||||
.cmd_param={
|
.cmd_param={
|
||||||
.sourcePriorityConfigs={
|
.source_priority = {
|
||||||
CMD_SRC_RC,
|
CMD_SRC_RC,
|
||||||
CMD_SRC_PC,
|
CMD_SRC_PC,
|
||||||
CMD_SRC_NUC,
|
CMD_SRC_NUC,
|
||||||
CMD_SRC_REF
|
CMD_SRC_REF,
|
||||||
},
|
},
|
||||||
.pc.map = { /*1<<CMD_KEY_W记录一下不要忘了这个思路 */
|
.sensitivity = {
|
||||||
.key_map[CMD_BEHAVIOR_FORE] = {CMD_KEY_W, CMD_ACTIVE_PRESSED},
|
.mouse_sens = 0.8f,
|
||||||
.key_map[CMD_BEHAVIOR_BACK] = {CMD_KEY_S, CMD_ACTIVE_PRESSED},
|
.move_sens = 1.0f,
|
||||||
.key_map[CMD_BEHAVIOR_LEFT] = {CMD_KEY_A, CMD_ACTIVE_PRESSED},
|
.move_fast_mult = 1.5f,
|
||||||
.key_map[CMD_BEHAVIOR_RIGHT] = {CMD_KEY_D, CMD_ACTIVE_PRESSED},
|
.move_slow_mult = 0.5f,
|
||||||
.key_map[CMD_BEHAVIOR_ACCELERATE] = {CMD_KEY_SHIFT, CMD_ACTIVE_PRESSED},
|
},
|
||||||
.key_map[CMD_BEHAVIOR_DECELEBRATE] = {CMD_KEY_CTRL, CMD_ACTIVE_PRESSED},
|
.rc_mode_map = {
|
||||||
.key_map[CMD_BEHAVIOR_FIRE] = {CMD_L_CLICK, CMD_ACTIVE_PRESSED},
|
.sw_left_up = CHASSIS_MODE_BREAK,
|
||||||
.key_map[CMD_BEHAVIOR_FIRE_MODE] = {CMD_R_CLICK, CMD_ACTIVE_RISING_EDGE},
|
.sw_left_mid = CHASSIS_MODE_FOLLOW_GIMBAL,
|
||||||
.key_map[CMD_BEHAVIOR_FOLLOWGIMBAL35] = {CMD_KEY_E, CMD_ACTIVE_RISING_EDGE},
|
.sw_left_down = CHASSIS_MODE_ROTOR,
|
||||||
.key_map[CMD_BEHAVIOR_OPENCOVER] = {CMD_KEY_F, CMD_ACTIVE_RISING_EDGE},
|
.gimbal_sw_up = GIMBAL_MODE_ABSOLUTE,
|
||||||
.key_map[CMD_BEHAVIOR_REVTRIG] = {CMD_KEY_R, CMD_ACTIVE_RISING_EDGE},
|
.gimbal_sw_mid = GIMBAL_MODE_ABSOLUTE,
|
||||||
.key_map[CMD_BEHAVIOR_ROTOR] = {CMD_KEY_G, CMD_ACTIVE_PRESSED},
|
.gimbal_sw_down = GIMBAL_MODE_RELATIVE,
|
||||||
.key_map[CMD_BEHAVIOR_GIMBAL_MODE] = {CMD_KEY_V, CMD_ACTIVE_RISING_EDGE},
|
|
||||||
},
|
|
||||||
.pc.sensitivity={
|
|
||||||
|
|
||||||
.move_sense=0.1f,
|
|
||||||
.sens_mouse=3.0f,
|
|
||||||
.move_fast_sense=2.4f,
|
|
||||||
.move_slow_sense=0.8f
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -16,14 +16,14 @@ extern "C" {
|
|||||||
#include "module/gimbal.h"
|
#include "module/gimbal.h"
|
||||||
#include "module/chassis.h"
|
#include "module/chassis.h"
|
||||||
#include "module/track.h"
|
#include "module/track.h"
|
||||||
#include "module/cmd.h"
|
#include "module/cmd_v2/cmd.h"
|
||||||
#include "component/PowerControl.h"
|
#include "component/PowerControl.h"
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Shoot_Params_t shoot_param;
|
Shoot_Params_t shoot_param;
|
||||||
Gimbal_Params_t gimbal_param;
|
Gimbal_Params_t gimbal_param;
|
||||||
Chassis_Params_t chassis_param;
|
Chassis_Params_t chassis_param;
|
||||||
Track_Params_t track_param;
|
Track_Params_t track_param;
|
||||||
CMD_Params_t cmd_param;
|
CMD_Config_t cmd_param;
|
||||||
} Config_RobotParam_t;
|
} Config_RobotParam_t;
|
||||||
|
|
||||||
extern power_model_t cha;
|
extern power_model_t cha;
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
#include "module/chassis.h"
|
#include "module/chassis.h"
|
||||||
#include "module/gimbal.h"
|
#include "module/gimbal.h"
|
||||||
#include "module/shoot.h"
|
#include "module/shoot.h"
|
||||||
#include "module/cmd.h"
|
#include "module/cmd_v2/cmd.h"
|
||||||
//#define DEAD_AREA 0.05f
|
//#define DEAD_AREA 0.05f
|
||||||
/* USER INCLUDE END */
|
/* USER INCLUDE END */
|
||||||
|
|
||||||
@ -26,11 +26,11 @@ DR16_t cmd_dr16;
|
|||||||
#elif CMD_RCTypeTable_Index == 1
|
#elif CMD_RCTypeTable_Index == 1
|
||||||
AT9S_t cmd_at9s;
|
AT9S_t cmd_at9s;
|
||||||
#endif
|
#endif
|
||||||
Shoot_CMD_t cmd_for_shoot;
|
Shoot_CMD_t *cmd_for_shoot;
|
||||||
Chassis_CMD_t cmd_for_chassis;
|
Chassis_CMD_t *cmd_for_chassis;
|
||||||
Gimbal_CMD_t cmd_for_gimbal;
|
Gimbal_CMD_t *cmd_for_gimbal;
|
||||||
|
|
||||||
CMD_t cmd;
|
static CMD_t cmd;
|
||||||
/* USER STRUCT END */
|
/* USER STRUCT END */
|
||||||
|
|
||||||
/* Private function --------------------------------------------------------- */
|
/* Private function --------------------------------------------------------- */
|
||||||
@ -46,7 +46,7 @@ void Task_cmd(void *argument) {
|
|||||||
|
|
||||||
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
|
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
|
||||||
/* USER CODE INIT BEGIN */
|
/* USER CODE INIT BEGIN */
|
||||||
Cmd_Init(&cmd, &Config_GetRobotParam()->cmd_param);
|
CMD_Init(&cmd, &Config_GetRobotParam()->cmd_param);
|
||||||
/* USER CODE INIT END */
|
/* USER CODE INIT END */
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -57,19 +57,20 @@ void Task_cmd(void *argument) {
|
|||||||
#elif CMD_RCTypeTable_Index == 1
|
#elif CMD_RCTypeTable_Index == 1
|
||||||
osMessageQueueGet(task_runtime.msgq.cmd.rc, &cmd_at9s, NULL, 0);
|
osMessageQueueGet(task_runtime.msgq.cmd.rc, &cmd_at9s, NULL, 0);
|
||||||
#endif
|
#endif
|
||||||
Cmd_Get(&cmd,cmd_dr16);
|
CMD_Update(&cmd);
|
||||||
Cmd_GenerateCommand(&cmd);
|
|
||||||
cmd_for_shoot=cmd.output.shoot.cmd;
|
/* 获取命令发送到各模块 */
|
||||||
cmd_for_chassis=cmd.output.chassis.cmd;
|
cmd_for_chassis = CMD_GetChassisCmd(&cmd);
|
||||||
cmd_for_gimbal=cmd.output.gimbal.cmd;
|
cmd_for_gimbal = CMD_GetGimbalCmd(&cmd);
|
||||||
|
cmd_for_shoot = CMD_GetShootCmd(&cmd);
|
||||||
osMessageQueueReset(task_runtime.msgq.gimbal.cmd);
|
osMessageQueueReset(task_runtime.msgq.gimbal.cmd);
|
||||||
osMessageQueuePut(task_runtime.msgq.gimbal.cmd, &cmd_for_gimbal, 0, 0);
|
osMessageQueuePut(task_runtime.msgq.gimbal.cmd, cmd_for_gimbal, 0, 0);
|
||||||
osMessageQueueReset(task_runtime.msgq.shoot.cmd);
|
osMessageQueueReset(task_runtime.msgq.shoot.cmd);
|
||||||
osMessageQueuePut(task_runtime.msgq.shoot.cmd, &cmd_for_shoot, 0, 0);
|
osMessageQueuePut(task_runtime.msgq.shoot.cmd, cmd_for_shoot, 0, 0);
|
||||||
osMessageQueueReset(task_runtime.msgq.chassis.cmd);
|
osMessageQueueReset(task_runtime.msgq.chassis.cmd);
|
||||||
osMessageQueuePut(task_runtime.msgq.chassis.cmd, &cmd_for_chassis, 0, 0);
|
osMessageQueuePut(task_runtime.msgq.chassis.cmd, cmd_for_chassis, 0, 0);
|
||||||
/* USER CODE END */
|
/* USER CODE END */
|
||||||
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user