用户输入与通信接口
用户指令接口
Section titled “用户指令接口”输入层统一封装在 UserCommandInterface,负责将用户操作转换为状态机可识别的命令。
virtual void Start() = 0;virtual void Stop() = 0;virtual UserCommand* GetUserCommand() = 0;状态反馈绑定示例
Section titled “状态反馈绑定示例”uc_ptr_->SetMotionStateFeedback(&StateBase::msfb_);键盘输入模式对应 KeyboardInterface,基于 libevdev 直接读取 /dev/input 设备。
模式选择示例
Section titled “模式选择示例”std::make_shared<q::QStateMachine>(RobotName::Lite3, RemoteCommandType::kKeyBoard);| 按键 | 功能 | 有效状态 |
|---|---|---|
z | standing up | 仅在 WaitingForStand 状态有效 |
c | RL control | 仅在 StandingUp 状态有效 |
r | joint damping | 任意状态 |
wasd | movement(ramp-up 速度递增) | RL 控制状态 |
qe | rotation | RL 控制状态 |
ESC | 退出 | 任意状态 |
手柄通信接口
Section titled “手柄通信接口”Retroid 手柄输入基于 RetroidGamepadInterface,通过订阅 /GAMEPAD_DATA 话题接收手柄数据。手柄数据由 lite3_transfer 中的 RetroidGamepadPublisher 发布。
手柄启动示例
Section titled “手柄启动示例”uc_ptr_ = std::make_shared<RetroidGamepadInterface>(robot_name_, ri_ptr_->get_node());手柄订阅示例
Section titled “手柄订阅示例”gamepad_sub_ = node_->create_subscription<drdds::msg::GamepadData>( "/GAMEPAD_DATA", 10, std::bind(&RetroidGamepadInterface::GamepadDataCallback, this, std::placeholders::_1));手柄映射示例
Section titled “手柄映射示例”RetroidGamepadInterface 中的按键处理(基于位掩码):
Y键(上升沿)-> Standing UpA键(上升沿)-> RL Control左摇杆按键 + 右摇杆按键同时按下 -> Joint Damping(紧急阻尼)