Skip to content

Sport Client — Python Example

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

Python port of the C++ rbq_sport_client.
An interactive terminal application that sends SportClient commands to the robot one at a time, looping at 50 Hz.

How it works

The program has a single main loop that:

  1. Reads a line of input from stdin (list, a command name, or a command ID).
  2. Updates the active TestOption.
  3. Calls the matching SportClient method on every 20 ms tick.

Prerequisites

  • rbq_sdk_py installed — see Python SDK Overview.
  • Robot stack running (simulation or hardware) and reachable on the chosen network interface.

Run

From rbq_sdk/python/example/sport/:

bash
python3 rbq_sport_client.py <networkInterface>
# e.g.
python3 rbq_sport_client.py eth0

Available commands

Type list at the prompt to print all commands.

IDNameSportClient method called
0dampDamp()
1balance_standBalanceStand()
2stop_moveStopMove()
3stand_downStandDown()
4recovery_standRecoveryStand()
5moveMove(0.0, 0.0, 0.5) — rotate in place
6switch_gaitSwitchGait(0)
7speed_levelSpeedLevel(1)
8get_stateGetState() — prints FSM ID, name, speed level, auto-recovery, process state
9recovery_switchSetAutoRecovery(0)
10body_heightBodyHeight(0.3)
11stand_upStandUp()
12enter_leftside_gaitLeftSideGait(1)
13exit_leftside_gaitLeftSideGait(0)
14enter_handstandHandStand(1)
15exit_handstandHandStand(0)
16front_flipFrontFlip() ⚠️
17back_flipBackFlip() ⚠️
18poseBodyPosition(0.2, 0.2, -0.2, 0.2)
19eulerEuler(0.2, 0.3, 0.3)

⚠️ Cautionfront_flip and back_flip require a clear open area.

Usage example

$ python3 rbq_sport_client.py eth0
Input "list " to list all test option ...
balance_stand
Test: balance_stand, test_id: 1
Request successed: balance_stand, code: 0
move
Test: move, test_id: 5
Request successed: move, code: 0

Key implementation notes

  • SetTimeout(25.0): The Python SportClient sets a 25-second timeout — relevant for RPC-style calls like GetState.
  • 50 Hz pacing: Uses time.sleep(max(0.0, next_tick - time.monotonic())) for accurate loop timing.
  • get_state response: Returns a dict with keys fsm_id, fsm_name, speed_level, auto_recovery_switch, process_state.

Differences from the C++ version

AspectC++Python
TimeoutdefaultSetTimeout(25.0) set explicitly
ConvertToInt on failurereturns -1returns None (no false match on ID 0)
Terminal inputstd::getline blockinginput() blocking
Error messageprints countprints count

See also

This user manual is intended for RBQ users.