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]

# Simulator / on-robot stack — interface defaults to lo
python3 rbq_sport_client.py

# Real robot — pass the interface that reaches it
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)
8get_stateGetState() — prints FSM ID, name, speed level, auto-recovery, process state
11stand_upStandUp()
12enter_leftside_gaitLeftSideGait(1)
13exit_leftside_gaitLeftSideGait(0)

The example program's list also prints commands the robot does not implement; those return a "not implemented" error. Only the commands above are supported.

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.