Skip to content

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:

ActorRateRole
Control loop (timer)50 HzPublishes HighLevelCommand with the current gait + velocity
Joystick threadevent-drivenReads joystick events and updates atomic velocity values
Terminal threadblockingReads gait names/IDs from stdin

At startup, switch_control_mode = 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 ROS2 SDK Overview.
  • Robot stack running (simulation or hardware).
  • A Linux joystick device at /dev/input/js* (optional; terminal-only mode still works without one).

Build

bash
source /opt/ros/humble/setup.bash
cd rbq_sdk/ros2
rosdep install --from-paths src -y --ignore-src   # first build only, if deps are missing
colcon build --packages-up-to rbq_examples
source install/setup.bash

Run

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/js1

Default joystick path: /dev/input/js0.

Terminal commands

Type either a gait name or a numeric gait ID and press Enter.

list              # print the example's built-in list
stand             # switch to STAND by name
3                 # switch to WALK by ID
wave              # switch to WAVE by name

Supported gaits

NameIDDescription
sit0Robot sits on the ground
stand1Neutral standing posture
walk3MPC trot gait
stairs4Stair-adaptive gait
wave5Slow walk gait

The example's built-in list also prints internal gaits that are not supported. Use only the gaits in the table above.

Joystick velocity controls

AxisMaps toMax 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

DirectionTopicMessage type
Publish/rbq/cmd/high_levelrbq_msgs/msg/HighLevelCommand
Publish/rbq/cmd/switch_control_modestd_msgs/msg/Bool
Publish/rbq/cmd/switch_gaitstd_msgs/msg/Int8
Subscribe/rbq/robot_statusrbq_msgs/msg/RobotStatus (best-effort QoS)

Key implementation notes

  • Populated fields: onTimer() fills only gait_state, gait_transition, vel_x, vel_y, and omega_z (all float32). roll, pitch, yaw, delta_body_h, and delta_foot_h are left at zero.
  • gait_transition flag: Set to true on every HighLevelCommand (not only on a gait change), so a newly selected gait_state is applied as a transition on the next publish cycle.
  • switch_control_mode: 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.

See also

This user manual is intended for RBQ users.