/* * cmd模组 */ #pragma once #ifdef __cplusplus extern "C" { #endif /* Includes ----------------------------------------------------------------- */ #include "component\user_math.h" #include "gimbal.h" #include "remote_control.h" #include "chassis.h" #include "module\shoot.h" #include "module\cmd\cmd_types.h" /* ========================================================================== */ /* 输出命令结构 */ /* ========================================================================== */ /* 每个模块的输出包含源信息和命令 */ typedef struct { CMD_InputSource_t source; Chassis_CMD_t cmd; } CMD_ChassisOutput_t; typedef struct { CMD_InputSource_t source; Gimbal_CMD_t cmd; } CMD_GimbalOutput_t; typedef struct { CMD_InputSource_t source; Shoot_CMD_t cmd; } CMD_ShootOutput_t; /* ========================================================================== */ /* 配置结构 */ /* ========================================================================== */ /* 灵敏度配置 */ typedef struct { float mouse_sens; /* 鼠标灵敏度 */ float move_sens; /* 移动灵敏度 */ float move_fast_mult; /* 快速移动倍率 */ float move_slow_mult; /* 慢速移动倍率 */ } CMD_Sensitivity_t; /* RC模式映射配置 - 定义开关位置到模式的映射 */ typedef struct { /* 左拨杆映射 - 底盘模式 */ Chassis_mode_t sw_left_up; Chassis_mode_t sw_left_mid; Chassis_mode_t sw_left_down; /* 右拨杆映射 - 云台/射击模式 */ Gimbal_Mode_t gimbal_sw_up; Gimbal_Mode_t gimbal_sw_mid; Gimbal_Mode_t gimbal_sw_down; Shoot_Mode_t shoot_sw_up; Shoot_Mode_t shoot_sw_mid; Shoot_Mode_t shoot_sw_down; } CMD_RCModeMap_t; /* 整体配置 */ typedef struct { /* 输入源优先级,索引越小优先级越高 */ CMD_InputSource_t source_priority[CMD_SRC_NUM]; /* 灵敏度设置 */ CMD_Sensitivity_t sensitivity; /* RC模式映射 */ CMD_RCModeMap_t rc_mode_map; } CMD_Config_t; /* ========================================================================== */ /* 主控制上下文 */ /* ========================================================================== */ typedef struct { float now; float dt; uint32_t last_us; } CMD_Timer_t; typedef struct CMD_Context { /* 配置 */ CMD_Config_t *config; /* 时间 */ CMD_Timer_t timer; /* 当前帧和上一帧的原始输入 */ CMD_RawInput_t input; CMD_RawInput_t last_input; /* 仲裁后的活跃输入源 */ CMD_InputSource_t active_source; /* 输出 */ struct { CMD_ChassisOutput_t chassis; CMD_GimbalOutput_t gimbal; CMD_ShootOutput_t shoot; } output; } CMD_t; /* ========================================================================== */ /* 全局配置实例 */ static CMD_Config_t g_cmd_config = { /* 灵敏度设置 */ .sensitivity = { .mouse_sens = 0.8f, .move_sens = 1.0f, .move_fast_mult = 1.5f, .move_slow_mult = 0.5f, }, /* RC拨杆模式映射 */ .rc_mode_map = { /* 左拨杆控制底盘模式 */ .sw_left_up = CHASSIS_MODE_BREAK, .sw_left_mid = CHASSIS_MODE_FOLLOW_GIMBAL, .sw_left_down = CHASSIS_MODE_ROTOR, /* 用于云台模式 */ .gimbal_sw_up = GIMBAL_MODE_RELAX, .gimbal_sw_mid = GIMBAL_MODE_ABSOLUTE, .gimbal_sw_down = GIMBAL_MODE_RELATIVE, .shoot_sw_up=SHOOT_MODE_SAFE, .shoot_sw_mid=SHOOT_MODE_SINGLE, .shoot_sw_down=SHOOT_MODE_BURST, }, }; #ifdef __cplusplus } #endif