Skip to content

High Level Command — C++ Example

Source: rbq_sdk/cpp/example/src/rbq_high_level.cpp

Publishes HighLevelCommand messages at 50 Hz over DDS.
Gait selection is done from the terminal; velocity setpoints come from a joystick.

Overview

Three concurrent actors run together:

ActorRateRole
Control loop thread50 HzPublishes HighLevelCommand with the current gait + velocity
Joystick loop thread100 HzPolls the joystick and updates atomic velocity globals
Main thread (terminal)blockingReads gait names/IDs from stdin and updates the target gait

At startup the control loop also publishes switchControlMode = true once, which enables EXT_JOY mode on the robot stack — without this the HighLevelCommand topic is ignored.

Prerequisites

  • RBQ SDK built and installed — see C++ SDK Overview.
  • A Linux joystick device at /dev/input/js* (the joystick is required to start the program).
  • Robot stack running (simulation or hardware).

Build

From rbq_sdk/cpp/example/:

bash
bash scripts/setup.bash
bash scripts/build.bash

Binary: bin/rbq_high_level

Run

bash
./bin/rbq_high_level <networkInterface> [joystickPath]
# e.g.
./bin/rbq_high_level eth0
./bin/rbq_high_level eth0 /dev/input/js1

The joystick auto-detection follows the same logic as the Sport Client (Joystick) example.

Terminal commands

At the > prompt type either a gait name or a numeric gait ID.

list              # print the example's built-in list
standing          # switch to STANDING by name
3                 # switch to TROTTING by ID
waving            # switch to WAVING by name

Supported gaits

NameIDDescription
sitting0Robot sits on the ground
standing1Neutral standing posture (default at startup)
trotting3MPC trot gait
trot_stairs4Stair-adaptive trot
waving5Slow walk gait
docking10Auto-docking sequence

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)vel_x±1.2 m/s
Left stick X (lateral)vel_y±0.5 m/s
Right stick X (yaw)omega_z±60 deg/s

A deadzone of 0.12 is applied before scaling.

Note on omega_z units: HighLevelCommand.omega_z is sent in degrees per second.
The on-robot QuadWalk multiplies by D2R internally, so the SDK side sends raw deg/s values (e.g. 60 deg/s ≈ 1.05 rad/s of yaw).

DDS topics used

DirectionTopicMessage type
Publishrt/rbq/cmd/high_levelrbq_msgs::msg::dds_::HighLevelCommand_
Publishrt/rbq/cmd/switch_control_modestd_msgs::msg::dds_::Bool_

Key implementation notes

  • gait_transition flag: Set to true only on the single tick immediately following a gait change, using std::atomic<bool>::exchange(). This ensures the QuadWalk gaitTimer is triggered exactly once rather than continuously.
  • switchControlMode: Published once at startup (after a 200 ms delay to let DDS subscribers connect). If not published, the robot ignores HighLevelCommand and stays in joystick mode.
  • Timing: The control loop uses clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, ...) for precise 20 ms scheduling. If the loop runs late, it resets timeNext to the current time rather than chasing a drifting target.

See also

This user manual is intended for RBQ users.