Skip to content

High Level Command — Python Example

Source: rbq_sdk/python/example/sport/rbq_high_level.py

Python port of rbq_high_level.cpp.
Publishes HighLevelCommand at 50 Hz over DDS, selects gaits from the terminal, and reads joystick velocity setpoints.

Overview

Three concurrent actors:

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

At startup the control loop publishes switchControlMode = true once (after 200 ms), enabling EXT_JOY mode on the robot stack. Without this, HighLevelCommand is ignored.

Prerequisites

  • rbq_sdk_py installed — see Python SDK Overview.
  • A Linux joystick device at /dev/input/js* (required to start).
  • Robot stack running (simulation or hardware).

Install & Run

bash
cd RBQ/rbq_sdk/python
pip install -e .
bash
cd RBQ/rbq_sdk/python/example/sport
python3 rbq_high_level.py <networkInterface> [joystickPath]
# e.g.
python3 rbq_high_level.py eth0
python3 rbq_high_level.py eth0 /dev/input/js1

Joystick auto-detection: prefers a device whose name contains "Logitech", "gamepad", "Xbox", or "wireless", then falls back to the first available js* node.
Override via argument or JOY=/dev/input/js1 python3 rbq_high_level.py eth0.

Terminal commands

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

Deadzone of 0.12 applied before scaling.

omega_z units: sent in deg/s — QuadWalk multiplies by D2R internally.

DDS topics

DirectionTopicMessage type
Publishrt/rbq/cmd/high_levelHighLevelCommand_
Publishrt/rbq/cmd/switch_control_modeBool_

Key implementation notes

  • gait_transition flag: A threading.Lock-protected consume_gait_pending() method ensures the flag is consumed exactly once per gait change — mirrors the C++ std::atomic::exchange() pattern.
  • switchControlMode: Published once at startup after a 200 ms delay. If not published, the robot ignores HighLevelCommand.
  • Timing: The control loop uses time.monotonic() and time.sleep() for 20 ms pacing. On slip, it resets next_tick to avoid clock drift.
  • No RT thread: Unlike the C++ version, no real-time thread is used. sudo is not required.

See also

This user manual is intended for RBQ users.