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:
- Reads a line of input from
stdin(list, a command name, or a command ID). - Updates the active
TestOption. - Calls the matching
SportClientmethod on every 20 ms tick.
Prerequisites
rbq_sdk_pyinstalled — 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 eth0Available commands
Type list at the prompt to print all commands.
| ID | Name | SportClient method called |
|---|---|---|
| 0 | damp | Damp() |
| 1 | balance_stand | BalanceStand() |
| 2 | stop_move | StopMove() |
| 3 | stand_down | StandDown() |
| 4 | recovery_stand | RecoveryStand() |
| 5 | move | Move(0.0, 0.0, 0.5) — rotate in place |
| 6 | switch_gait | SwitchGait(0) |
| 7 | speed_level | SpeedLevel(1) |
| 8 | get_state | GetState() — prints FSM ID, name, speed level, auto-recovery, process state |
| 9 | recovery_switch | SetAutoRecovery(0) |
| 10 | body_height | BodyHeight(0.3) |
| 11 | stand_up | StandUp() |
| 12 | enter_leftside_gait | LeftSideGait(1) |
| 13 | exit_leftside_gait | LeftSideGait(0) |
| 14 | enter_handstand | HandStand(1) |
| 15 | exit_handstand | HandStand(0) |
| 16 | front_flip | FrontFlip() ⚠️ |
| 17 | back_flip | BackFlip() ⚠️ |
| 18 | pose | BodyPosition(0.2, 0.2, -0.2, 0.2) |
| 19 | euler | Euler(0.2, 0.3, 0.3) |
⚠️ Caution —
front_flipandback_fliprequire 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: 0Key implementation notes
SetTimeout(25.0): The PythonSportClientsets a 25-second timeout — relevant for RPC-style calls likeGetState.- 50 Hz pacing: Uses
time.sleep(max(0.0, next_tick - time.monotonic()))for accurate loop timing. get_stateresponse: Returns adictwith keysfsm_id,fsm_name,speed_level,auto_recovery_switch,process_state.
Differences from the C++ version
| Aspect | C++ | Python |
|---|---|---|
| Timeout | default | SetTimeout(25.0) set explicitly |
ConvertToInt on failure | returns -1 | returns None (no false match on ID 0) |
| Terminal input | std::getline blocking | input() blocking |
| Error message | prints count | prints count |
