跳转到内容

用户输入与通信接口

输入层统一封装在 UserCommandInterface,负责将用户操作转换为状态机可识别的命令。

virtual void Start() = 0;
virtual void Stop() = 0;
virtual UserCommand* GetUserCommand() = 0;
uc_ptr_->SetMotionStateFeedback(&StateBase::msfb_);

键盘输入模式对应 KeyboardInterface,基于 libevdev 直接读取 /dev/input 设备。

std::make_shared<q::QStateMachine>(RobotName::Lite3, RemoteCommandType::kKeyBoard);
按键功能有效状态
zstanding up仅在 WaitingForStand 状态有效
cRL control仅在 StandingUp 状态有效
rjoint damping任意状态
wasdmovement(ramp-up 速度递增)RL 控制状态
qerotationRL 控制状态
ESC退出任意状态

Retroid 手柄输入基于 RetroidGamepadInterface,通过订阅 /GAMEPAD_DATA 话题接收手柄数据。手柄数据由 lite3_transfer 中的 RetroidGamepadPublisher 发布。

uc_ptr_ = std::make_shared<RetroidGamepadInterface>(robot_name_, ri_ptr_->get_node());
gamepad_sub_ = node_->create_subscription<drdds::msg::GamepadData>(
"/GAMEPAD_DATA", 10,
std::bind(&RetroidGamepadInterface::GamepadDataCallback, this, std::placeholders::_1));

RetroidGamepadInterface 中的按键处理(基于位掩码):

  • Y 键(上升沿)-> Standing Up
  • A 键(上升沿)-> RL Control
  • 左摇杆按键 + 右摇杆按键 同时按下 -> Joint Damping(紧急阻尼)