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>
# 예:
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)
7speed_levelSpeedLevel(1)
8get_stateGetState() — FSM ID, 이름, 속도 레벨, 자동 복구, 프로세스 상태 출력
9recovery_switchSetAutoRecovery(0)
10body_heightBodyHeight(0.3)
11stand_upStandUp()
12enter_leftside_gaitLeftSideGait(1)
13exit_leftside_gaitLeftSideGait(0)
14enter_handstandHandStand(1)
15exit_handstandHandStand(0)
16front_flip이 로봇에서는 지원하지 않음
17back_flip이 로봇에서는 지원하지 않음
18pose이 로봇에서는 지원하지 않음
19euler이 로봇에서는 지원하지 않음

주요 구현 사항

  • 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.