High Level Command — ROS2 Example
Source: rbq_sdk/ros2/src/rbq_examples/src/rbq_high_level.cpp
Publishes HighLevelCommand messages at 50 Hz over ROS 2.
Gait selection is done from the terminal; velocity setpoints come from a joystick.
Overview
Three concurrent actors run together:
| Actor | Rate | Role |
|---|---|---|
| Control loop (timer) | 50 Hz | Publishes HighLevelCommand with the current gait + velocity |
| Joystick thread | event-driven | Reads joystick events and updates atomic velocity values |
| Terminal thread | blocking | Reads gait names/IDs from stdin |
At startup, switchControlMode = true is published once (after a 200 ms delay) to enable HighLevel mode on the robot — without this the HighLevelCommand topic is ignored.
Prerequisites
- ROS 2 Humble installed and sourced.
- RBQ ROS2 SDK built — see Quick Start.
- Robot stack running (simulation or hardware).
- A Linux joystick device at
/dev/input/js*(optional; terminal-only mode still works without one).
Build
bash
cd RBQ/rbq_sdk/ros2
rosdep install --from-paths src -y --ignore-src
colcon build --symlink-install
source install/setup.bashRun
bash
ros2 run rbq_examples rbq_high_level [joystickPath]
# e.g.
ros2 run rbq_examples rbq_high_level
ros2 run rbq_examples rbq_high_level /dev/input/js1Default joystick path: /dev/input/js0.
Terminal commands
Type either a gait name or a numeric gait ID and press Enter.
list # print all available gaits
stand # switch to STAND by name
3 # switch to WALK by ID
rl_trot # switch to RL_TROT by nameAvailable gaits
| Name | ID | Description |
|---|---|---|
sit | 0 | Robot sits on the ground |
stand | 1 | Neutral standing posture |
aim | 2 | Aiming posture |
walk | 3 | MPC trot gait |
stairs | 4 | Stair-adaptive gait |
wave | 5 | Slow walk gait |
run | 6 | High-speed gait |
rl_trot | 30 | RL-based trot |
rl_front_walk | 31 | RL forward walk |
rl_left_walk | 33 | RL lateral left walk |
rl_right_walk | 34 | RL lateral right walk |
rl_bound | 35 | RL bound gait |
rl_pace | 36 | RL pace gait |
rl_pronk | 37 | RL pronk gait |
rl_3leg_hr | 38 | RL 3-leg (hind-right lifted) |
rl_3leg_hl | 39 | RL 3-leg (hind-left lifted) |
rl_3leg_fr | 40 | RL 3-leg (front-right lifted) |
rl_3leg_fl | 41 | RL 3-leg (front-left lifted) |
rl_trot_vision | 42 | RL trot with vision |
rl_trot_run | 45 | RL trot run |
rl_silent | 46 | RL silent gait |
rl_stairs | 47 | RL stair climbing |
rl_walk_vision | 48 | RL walk w/ terrain height feedback (height/pitch adjustable) |
rl_walk | 49 | RL walk (height/pitch adjustable) |
Joystick velocity controls
| Axis | Maps to | Max value |
|---|---|---|
| Left stick Y (forward/back) | vel_x | ±1.2 m/s |
| Left stick X (left/right) | vel_y | ±0.5 m/s |
| Right stick X (left/right) | omega_z | ±60 deg/s |
A deadzone of 0.12 is applied before scaling.omega_z is sent in degrees per second — QuadWalk converts to rad/s internally.
ROS 2 topics used
| Direction | Topic | Message type |
|---|---|---|
| Publish | /rbq/cmd/highLevel | rbq_msgs/msg/HighLevelCommand |
| Publish | /rbq/cmd/switchControlMode | std_msgs/msg/Bool |
| Publish | /rbq/cmd/switchGait | std_msgs/msg/Int8 |
| Publish | /rbq/cmd/joy | sensor_msgs/msg/Joy |
| Subscribe | /rbq/robot_status | rbq_msgs/msg/RobotStatus (best-effort QoS) |
Key implementation notes
gait_transitionflag: Set totrueon every gait change message. This triggers the QuadWalk gait timer to start the transition.switchControlMode: Sent once at startup after a 200 ms delay (mode_timer_) to allow DDS subscribers to connect before the command arrives.- Joystick events: The joystick thread runs independently and updates
vel_x_,vel_y_,omega_z_atomics. The 50 Hz timer reads these atomics on each publish cycle.
