User Input and Communication Interface
User Command Interface
Section titled “User Command Interface”The input layer is uniformly encapsulated in UserCommandInterface, responsible for converting user operations into commands recognizable by the state machine.
Interface Example
Section titled “Interface Example”virtual void Start() = 0;virtual void Stop() = 0;virtual UserCommand* GetUserCommand() = 0;State Feedback Binding Example
Section titled “State Feedback Binding Example”uc_ptr_->SetMotionStateFeedback(&StateBase::msfb_);Keyboard Input
Section titled “Keyboard Input”The keyboard input mode corresponds to KeyboardInterface, based on libevdev for direct reading of /dev/input devices.
Mode Selection Example
Section titled “Mode Selection Example”std::make_shared<q::QStateMachine>(RobotName::Lite3, RemoteCommandType::kKeyBoard);Key Mapping
Section titled “Key Mapping”| Key | Function | Valid State |
|---|---|---|
z | Standing up | Only in WaitingForStand state |
c | RL control | Only in StandingUp state |
r | Joint damping | Any state |
wasd | Movement (ramp-up velocity increment) | RL control state |
qe | Rotation | RL control state |
ESC | Exit | Any state |
Gamepad Communication Interface
Section titled “Gamepad Communication Interface”The Retroid gamepad input is based on RetroidGamepadInterface, receiving gamepad data by subscribing to the /GAMEPAD_DATA topic. Gamepad data is published by RetroidGamepadPublisher in lite3_transfer.
Gamepad Startup Example
Section titled “Gamepad Startup Example”uc_ptr_ = std::make_shared<RetroidGamepadInterface>(robot_name_, ri_ptr_->get_node());Gamepad Subscription Example
Section titled “Gamepad Subscription Example”gamepad_sub_ = node_->create_subscription<drdds::msg::GamepadData>( "/GAMEPAD_DATA", 10, std::bind(&RetroidGamepadInterface::GamepadDataCallback, this, std::placeholders::_1));Gamepad Mapping Example
Section titled “Gamepad Mapping Example”Button handling in RetroidGamepadInterface (based on bitmask):
Ybutton (rising edge) → Standing UpAbutton (rising edge) → RL ControlLeft joystick button + Right joystick buttonpressed simultaneously → Joint Damping (emergency damping)