Skip to content

Sport Client — Python 예제 ​

소스: rbq_sdk/python/example/sport/rbq_sport_client.py

C++의 rbq_sport_client를 Python으로 포팅한 버전입니다.
SportClient 명령을 하나씩 로봇에 전송하는 터미널 기반 대화형 애플리케이션으로 50 Hz로 동작합니다.

동작 방식 ​

단일 메인 루프:

  1. stdin에서 한 줄 입력 받기 (list, 명령 이름, 또는 명령 ID).
  2. 활성 TestOption 업데이트.
  3. 20 ms 틱마다 해당 SportClient 메서드 호출.

사전 요구사항 ​

  • rbq_sdk_py 설치 완료 — Python SDK 개요 참조.
  • 로봇 스택이 실행 중이며 네트워크 접근 가능.

실행 ​

bash
python3 rbq_sport_client.py [networkInterface]

# 시뮬레이터 / 로봇 내부 스택 — 인터페이스 기본값은 lo
python3 rbq_sport_client.py

# 실제 로봇 — 로봇에 닿는 인터페이스를 넘깁니다
python3 rbq_sport_client.py eth0

사용 가능한 명령 ​

프롬프트에서 list를 입력하면 전체 명령 목록이 출력됩니다.

ID이름호출되는 SportClient 메서드
0dampDamp()
1balance_standBalanceStand()
2stop_moveStopMove()
3stand_downStandDown()
4recovery_standRecoveryStand()
5moveMove(0.0, 0.0, 0.5) — 제자리 회전
6switch_gaitSwitchGait(0)
8get_stateGetState() — FSM ID, 이름, 속도 레벨, 자동 복구, 프로세스 상태 출력
11stand_upStandUp()
12enter_leftside_gaitLeftSideGait(1)
13exit_leftside_gaitLeftSideGait(0)

예제의 list 에는 로봇이 구현하지 않은 명령도 함께 나옵니다 — 그 명령들은 "미구현" 오류를 돌려줍니다. 실제로 쓸 수 있는 것은 위 표에 있는 것뿐입니다.

사용 예 ​

$ 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

주요 구현 사항 ​

  • SetTimeout(25.0): Python SportClient는 25초 타임아웃을 명시적으로 설정합니다 — GetState 같은 RPC 스타일 호출에 필요합니다.
  • 50 Hz 페이싱: time.sleep(max(0.0, next_tick - time.monotonic()))으로 정확한 루프 타이밍 구현.
  • get_state 응답: fsm_id, fsm_name, speed_level, auto_recovery_switch, process_state 키를 가진 딕셔너리를 반환합니다.

C++ 버전과의 차이점 ​

항목C++Python
타임아웃기본값SetTimeout(25.0) 명시
ConvertToInt 실패 시-1 반환None 반환 (ID 0과의 오매칭 없음)
터미널 입력std::getline 블로킹input() 블로킹

관련 문서 ​

This user manual is intended for RBQ users.