Compare commits

...

3 Commits

3 changed files with 62 additions and 43 deletions

View File

@ -197,7 +197,7 @@ int8_t CMD_Arbitrate(CMD_t *ctx) {
} }
/* 自动仲裁:优先级 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_RC, CMD_SRC_PC, CMD_SRC_NUC};
const int num_candidates = sizeof(candidates) / sizeof(candidates[0]); const int num_candidates = sizeof(candidates) / sizeof(candidates[0]);
/* 如果当前输入源仍然在线且有效,保持使用 */ /* 如果当前输入源仍然在线且有效,保持使用 */

View File

@ -10,7 +10,7 @@
// 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}; CMD_InputAdapter_t *g_adapters[CMD_SRC_NUM] = {0};
/* ========================================================================== */ /* ========================================================================== */
/* DR16 抽象实现 */ /* DR16 适配器实现 */
/* ========================================================================== */ /* ========================================================================== */
#if CMD_RC_DEVICE_TYPE == 0 #if CMD_RC_DEVICE_TYPE == 0
@ -27,19 +27,19 @@ int8_t CMD_DR16_RC_GetInput(void *data, CMD_RawInput_t *output) {
output->online[CMD_SRC_RC] = dr16->header.online; output->online[CMD_SRC_RC] = dr16->header.online;
/* 遥控器摇杆映射 */ /* 遥控器摇杆映射 */
output->rc.joy_left.x = dr16->data.rc.ch_l_x; output->rc.joy_left.x = dr16->data.ch_l_x;
output->rc.joy_left.y = dr16->data.rc.ch_l_y; output->rc.joy_left.y = dr16->data.ch_l_y;
output->rc.joy_right.x = dr16->data.rc.ch_r_x; output->rc.joy_right.x = dr16->data.ch_r_x;
output->rc.joy_right.y = dr16->data.rc.ch_r_y; output->rc.joy_right.y = dr16->data.ch_r_y;
/* 拨杆映射 */ /* 拨杆映射 */
switch (dr16->data.rc.sw_l) { switch (dr16->data.sw_l) {
case DR16_SW_UP: output->rc.sw[0] = CMD_SW_UP; break; case DR16_SW_UP: output->rc.sw[0] = CMD_SW_UP; break;
case DR16_SW_MID: output->rc.sw[0] = CMD_SW_MID; break; case DR16_SW_MID: output->rc.sw[0] = CMD_SW_MID; break;
case DR16_SW_DOWN: output->rc.sw[0] = CMD_SW_DOWN; break; case DR16_SW_DOWN: output->rc.sw[0] = CMD_SW_DOWN; break;
default: output->rc.sw[0] = CMD_SW_ERR; break; default: output->rc.sw[0] = CMD_SW_ERR; break;
} }
switch (dr16->data.rc.sw_r) { switch (dr16->data.sw_r) {
case DR16_SW_UP: output->rc.sw[1] = CMD_SW_UP; break; case DR16_SW_UP: output->rc.sw[1] = CMD_SW_UP; break;
case DR16_SW_MID: output->rc.sw[1] = CMD_SW_MID; break; case DR16_SW_MID: output->rc.sw[1] = CMD_SW_MID; break;
case DR16_SW_DOWN: output->rc.sw[1] = CMD_SW_DOWN; break; case DR16_SW_DOWN: output->rc.sw[1] = CMD_SW_DOWN; break;
@ -47,7 +47,7 @@ int8_t CMD_DR16_RC_GetInput(void *data, CMD_RawInput_t *output) {
} }
/* 拨轮映射 */ /* 拨轮映射 */
output->rc.dial = dr16->data.rc.ch_res; output->rc.dial = dr16->data.ch_res;
return CMD_OK; return CMD_OK;
} }
@ -60,10 +60,10 @@ int8_t CMD_DR16_PC_GetInput(void *data, CMD_RawInput_t *output) {
output->online[CMD_SRC_PC] = dr16->header.online; output->online[CMD_SRC_PC] = dr16->header.online;
/* PC端鼠标映射 */ /* PC端鼠标映射 */
output->pc.mouse.x = dr16->data.pc.mouse.x; output->pc.mouse.x = dr16->data.mouse.x;
output->pc.mouse.y = dr16->data.pc.mouse.y; output->pc.mouse.y = dr16->data.mouse.y;
output->pc.mouse.l_click = dr16->data.pc.mouse.l_click; output->pc.mouse.l_click = dr16->data.mouse.l_click;
output->pc.mouse.r_click = dr16->data.pc.mouse.r_click; output->pc.mouse.r_click = dr16->data.mouse.r_click;
/* 键盘映射 */ /* 键盘映射 */
output->pc.keyboard.bitmap = dr16->raw_data.key; output->pc.keyboard.bitmap = dr16->raw_data.key;
@ -83,7 +83,7 @@ CMD_DEFINE_ADAPTER(DR16_PC, cmd_dr16, CMD_SRC_PC, CMD_DR16_Init, CMD_DR16_PC_Get
#endif /* CMD_RC_DEVICE_TYPE == 0 */ #endif /* CMD_RC_DEVICE_TYPE == 0 */
/* ========================================================================== */ /* ========================================================================== */
/* AT9S 抽象实现 (示例框架) */ /* AT9S 适配器实现 (示例框架) */
/* ========================================================================== */ /* ========================================================================== */
#if CMD_RC_DEVICE_TYPE == 1 #if CMD_RC_DEVICE_TYPE == 1
@ -100,10 +100,10 @@ int8_t CMD_AT9S_GetInput(void *data, CMD_RawInput_t *output) {
output->online[CMD_SRC_RC] = at9s->header.online; output->online[CMD_SRC_RC] = at9s->header.online;
/* TODO: 按照AT9S的数据格式进行映射 */ /* TODO: 按照AT9S的数据格式进行映射 */
output->joy_left.x = at9s->data.rc.ch_l_x; output->joy_left.x = at9s->data.ch_l_x;
output->joy_left.y = at9s->data.rc.ch_l_y; output->joy_left.y = at9s->data.ch_l_y;
output->joy_right.x = at9s->data.rc.ch_r_x; output->joy_right.x = at9s->data.ch_r_x;
output->joy_right.y = at9s->data.rc.ch_r_y; output->joy_right.y = at9s->data.ch_r_y;
/* 拨杆映射需要根据AT9S的实际定义 */ /* 拨杆映射需要根据AT9S的实际定义 */
@ -142,10 +142,6 @@ int8_t CMD_Adapter_InitAll(void) {
CMD_Adapter_Register(&g_adapter_AT9S); CMD_Adapter_Register(&g_adapter_AT9S);
#endif #endif
/* 注册NUC适配器 */
/* 注册REF适配器 */
/* 初始化所有已注册的适配器 */ /* 初始化所有已注册的适配器 */
for (int i = 0; i < CMD_SRC_NUM; i++) { for (int i = 0; i < CMD_SRC_NUM; i++) {
if (g_adapters[i] != NULL && g_adapters[i]->init != NULL) { if (g_adapters[i] != NULL && g_adapters[i]->init != NULL) {

View File

@ -6,7 +6,7 @@
#include "cmd.h" #include "cmd.h"
/* ========================================================================== */ /* ========================================================================== */
/* 配置示例 */ /* config示例 */
/* ========================================================================== */ /* ========================================================================== */
/* 默认配置 */ /* 默认配置 */
@ -37,35 +37,58 @@
// /* CMD上下文 */ // /* CMD上下文 */
// static CMD_t g_cmd_ctx; // static CMD_t g_cmd_ctx;
/* ========================================================================== */
/* 队列创建示例 */
/* ========================================================================== */
// #if CMD_RCTypeTable_Index == 0
// task_runtime.msgq.cmd.rc= osMessageQueueNew(3u, sizeof(DR16_t), NULL);
// #elif CMD_RCTypeTable_Index == 1
// task_runtime.msgq.cmd.rc= osMessageQueueNew(3u, sizeof(AT9S_t), NULL);
// #endif
/* ========================================================================== */ /* ========================================================================== */
/* 任务示例 */ /* 任务示例 */
/* ========================================================================== */ /* ========================================================================== */
/* // #if CMD_RCTypeTable_Index == 0
* // DR16_t cmd_dr16;
*/ // #elif CMD_RCTypeTable_Index == 1
// void Example_CMD_Init(void) { // AT9S_t cmd_at9s;
// CMD_Init(&g_cmd_ctx, &g_cmd_config); // #endif
// } // Shoot_CMD_t *cmd_for_shoot;
// Chassis_CMD_t *cmd_for_chassis;
// Gimbal_CMD_t *cmd_for_gimbal;
// /* // static CMD_t cmd;
// * 任务循环示例
// */ // void Task_cmd() {
// void Example_CMD_Task(void) {
// /* 一键更新 */ // CMD_Init(&cmd, &Config_GetRobotParam()->cmd_param);
// CMD_Update(&g_cmd_ctx);
// while (1) {
// #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
// CMD_Update(&cmd);
// /* 获取命令发送到各模块 */ // /* 获取命令发送到各模块 */
// Chassis_CMD_t *chassis_cmd = CMD_GetChassisCmd(&g_cmd_ctx); // cmd_for_chassis = CMD_GetChassisCmd(&cmd);
// Gimbal_CMD_t *gimbal_cmd = CMD_GetGimbalCmd(&g_cmd_ctx); // cmd_for_gimbal = CMD_GetGimbalCmd(&cmd);
// Shoot_CMD_t *shoot_cmd = CMD_GetShootCmd(&g_cmd_ctx); // cmd_for_shoot = CMD_GetShootCmd(&cmd);
// osMessageQueueReset(task_runtime.msgq.gimbal.cmd);
// osMessageQueuePut(task_runtime.msgq.gimbal.cmd, cmd_for_gimbal, 0, 0);
// osMessageQueueReset(task_runtime.msgq.shoot.cmd);
// osMessageQueuePut(task_runtime.msgq.shoot.cmd, cmd_for_shoot, 0, 0);
// osMessageQueueReset(task_runtime.msgq.chassis.cmd);
// osMessageQueuePut(task_runtime.msgq.chassis.cmd, cmd_for_chassis, 0, 0);
// }
// /* 使用命令... */
// (void)chassis_cmd;
// (void)gimbal_cmd;
// (void)shoot_cmd;
// } // }
/* ========================================================================== */ /* ========================================================================== */
/* 架构说明 */ /* 架构说明 */
/* ========================================================================== */ /* ========================================================================== */