Skip to content

Moby gRPC Client Python API

Moby gRPC API List

Moby 상태 데이터 얻기

Command Description Return Type
get_moby_state() Get the current state of the Moby dict
get_moby_error_state() Get the error state of the Moby [str, int, 0, 0]
recover() Recover the error state of the Moby -

예시로 Moby의 상태와 에러상태를 다음과 같이 얻을 수 있습니다.

state = moby.get_moby_state()
print(state)

error = moby.get_moby_error_state()
print(error)
* 출력:
{'state': 'IDLE', 'is_ready': True, 'is_enable': True, 'is_moving': False, 'is_violation': False}
['NONE', 0, 0, 0]

상태 및 에러 유형은 다음과 같습니다.

  • STRING STATE

    • state : 현재 Moby의 상태

State Description
SYSTEM_OFF None
SYSTEM_ON Initializing System and Servo
IDLE Idle, Wait for command
MOVING Drive by move rotation or driving
TELE_OP Drive by set_target_vel
VIOLATE Error : get Violation
RECOVER_SOFT Recover Error State

  • BOOL STATE

    • is_ready : 이더캣 마스터와 슬레이브가 모두 연결되어있고, 활성화되어있는 상태
    • is_enable : 모든 서보가 켜져있는 상태
    • is_moving : Moby가 움직이는 상태
    • is_violation : 에러 발생
  • Error STATE

Error State Description
None Normal State
SW_MASTER_NOT_OP EtherCAT Master is not operational
SW_SLAVES_NOT_OP EtherCAT Slaves are not operational
SW_SERVO_NOT_ON Servo is not On
SW_SERVO_NOT_READY Servo is not Ready to control
SW_ENCODER_ABNORMAL rotation encoder not working
SW_BUMPER_DETECT (with bumper) collision detected
HW_CONNECTION_LOST EtherCAT Comm Disconnected

오도메트리와 로봇 역학 데이터

Command Description Parameters Return Type
get_moby_pose() Get the Moby pose including position and orientation. None list [1]
get_moby_vel() Get the Moby velocity including linear and angular velocities. None list [1]
get_target_vel() Get the target velocity of Moby. None list [1]
reset_moby_pose() Reset the Moby pose to its initial state. None None
get_rotation_angle() Get the Moby's rotation angle. None dict [2]
get_drive_speed() Get the drive speed of Moby. None dict [2]
get_zero() Get the zero counts of rotation motors. None dict [2]

[1]: [x, y, w]

[2]: [fl:Front Left, fr:Front Right, bl:Back Left, br:Back Right]

사용 예시는 다음과 같습니다.

pose_data = moby.get_moby_pose()
vel_data = moby.get_moby_vel()
rotation_angle = moby.get_rotation_angle()
drive_speed = moby.get_drive_speed()
target_vel = moby.get_target_vel()
zero_point = moby.get_zero()

print("Pose", pose_data)
print("Velocity", vel_data)
print("Rotation angle", rotation_angle)
print("Driving speed", drive_speed)
print("Target velocity", target_vel)
print("Zero position", zero_point)

moby.reset_moby_pose()
  • 출력:
Pose [0.0, 0.0, -0.0]

Velocity [0.0, 0.0, 0.0]

Rotation angle {'fl': -0.0, 'fr': -0.00, 'bl': 0.00, 'br': -0.00}

Driving speed {'fl': 0.0, 'fr': 0.0, 'bl': 0.0, 'br': 0.0}

Target velocity [0.0, 0.0, 0.0]

Zero position {'fl': 9410731, 'fr': -2143286890, 'bl': 266461587, 'br': -1685613215}

이 예시에서 Odometry 및 Physical 데이터를 얻는 것을 보여주며, Pose는 reset_moby_pose() 함수를 사용하여 초기 상태로 재설정 할 수 있습니다.

센서 값 획득

Command Description Parameters Return Type
get_gyro_data() Get the gyroscope data. Heading angle and angular velocity as [rad] and [rad/s] units None list
get_imu_data() Get the Inertial Measurement Unit (IMU) data. Angle, angular velocity, linear acceleration None [list, list, list]
reset_gyro() Reset the gyroscope data None None
use_gyro_for_odom(use_gyro)() use gyro sensor to estimate the heading direction use_gyro: bool None
get_us_data() Get the UltraSonic (US) sensor data None dict
get_bms() Get the Battery Management System (BMS) data[1],[2] None dict

[1] : GreenPuzzle

BMS status-1, BMS status-2, Pack voltage-1, Pack voltage-2, Battery Voltage-1, Battery Voltage-2, Pack current1-1, Pack current1-2, Pack current2-1, Pack current2-2, Temperature-1, Temperature-2, Temperature-3, Temperature-4

[2] : CTNS

Pack voltage-1, Pack current1-1, Is Charge, Is Cell OverVoltage, Is Cell UnderVoltage, Is OverCurrent Charge, Is OverCurrent Discharge, Is Short Circuit, Is OverTemperature, Is Pack OverVoltage, SOC', SOH, Time for Charge, time for Discharge Remain Capacity Ah, Remain Capacity Wh Temperature-(1~3), Cell Voltage-(1~13)

사용 예시는 다음과 같습니다.

gyro_data = moby.get_gyro_data()
moby.reset_gyro()
use_gyro_for_odom(use_gyro=True)
imu_data = moby.get_imu_data()
us_data = moby.get_us_data()
bms_data = moby.get_bms()

print("Gyro data")
print(gyro_data)

print("IMU all")
print(imu_data)

print("US data")
print(us_data)

print("BMS-GreenPuzzle")
print(bms_data)
* 출력:
Gyro data
[-0.002, -0.0]

IMU all
([0.0, 0.0, -0.0], [0.0, 0.0, 0.0], [-0.0, 0.0, 9.56148375])

US data
{'front_left1': 65535, 'front_left2': 65535, 'front_left3': 65535, 'front_ground': 100, 'front_right1': 65535, 'front_right2': 65535, 'front_right3': 65535, 'front_right4': 65535,
 'back_right1': 65535, 'back_right2': 65535, 'back_right3': 65535, 'back_ground': 100, 'back_left1': 65535, 'back_left2': 65535, 'back_left3': 65535, 'back_left4': 65535}

BMS
{'BMS status-1': 84.0, 'BMS status-2': 84.0, 'Pack voltage-1': 54.62, 'Pack voltage-2': 54.35, 'Battery Voltage-1': 54.44, 'Battery Voltage-2': 54.42,
 'Pack current1-1': -1.3, 'Pack current1-2': -1.9, 'Pack current2-1': -1.6, 'Pack current2-2': -2.3, 'Is Charge': 0, 'Is Cell OverVoltage': 0, 'Is Cell UnderVoltage': 0,
 'Is OverCurrent Charge': 0, 'Is OverCurrent Discharge': 0, 'Is Short Circuit': 0, 'Is OverTemperature': 0, 'Is Pack OverVoltage': 0, 'SOC': 0.0, 'SOH': 0,
 'Time for Charge': 0, 'time for Discharge': 0, 'Remain Capacity Ah': 0.0, 'Remain Capacity Wh': 0, 'Temperature-1': 21.0, 'Temperature-2': 20.0, 'Temperature-3': 21.0,
 'Temperature-4': 20.0, 'Cell Voltage-1': 0.0, 'Cell Voltage-2': 0.0, 'Cell Voltage-3': 0.0, 'Cell Voltage-4': 0.0, 'Cell Voltage-5': 0.0, 'Cell Voltage-6': 0.0,
 'Cell Voltage-7': 0.0, 'Cell Voltage-8': 0.0, 'Cell Voltage-9': 0.0, 'Cell Voltage-10': 0.0, 'Cell Voltage-11': 0.0, 'Cell Voltage-12': 0.0, 'Cell Voltage-13': 0.0}
이 예제에서 gyro_data, imu_data, us_data 및 bms_data 변수는 각각 자이로스코프, IMU, 초음파 센서 및 BMS에서 데이터를 저장합니다. 딕셔너리의 키를 사용하여 특정 값을 액세스할 수 있습니다. 예를 들어, BMS 데이터의 배터리 팩 전압을 액세스하려면 bms_data['Pack voltage-1']을 사용하면 됩니다.

이 예제는 센서 데이터 딕셔너리에서 특정 값을 액세스하고 출력하는 방법을 보여줍니다.

Moby 모션 커맨드

Command Description Parameters
stop_motion() Stops all motion of Moby. None
set_target_vel(vx: float, vy: float, vw: float) Set the target linear and angular velocities for Moby. vx: float
vy: float
vw: float
move_rotation_deg(fl: float, fr: float, bl: float, br: float) Rotate each wheel of Moby by specified angles in degrees. fl: float
fr: float
bl: float
br: float
move_driving_mps(fl: float, fr: float, bl: float, br: float) Drive each wheel of Moby at specified speeds in meters per second. fl: float
fr: float
bl: float
br: float

사용 예시는 다음과 같습니다.

# Stop Moby's motion
moby.stop_motion()

# Set target velocity (linear_x, linear_y, angular_z)
moby.set_target_vel(0.5, 0.0, 0.1)

# Rotate each wheel by 90 degrees
moby.move_rotation_deg(fl=90, fr=90, bl=90, br=90)

# Drive each wheel forward for 0.5 m/s
moby.move_driving_mps(fl=0.5, fr=0.5, bl=0.5, br=0.5)

상기 예제는 Moby 모션 명령을 사용하여 로봇의 움직임을 제어하는 방법을 보여줍니다.
move_rotation_degmove_driving_mps는 로봇을 MOVING 상태로, set_target_vel는 로봇을 TELEOP 상태로 전환하고 주행을 시작합니다.

Moby Control Parameter 설정

Command Description Parameters Return Type
set_zero_as_current() Set zero as current position of rotation motors None None
set_rotation_gain(index, k, kv, kp) Set control gains for the rotation motor
(k, kv, kp)
index: int[1]
k: float
kv: float
kp: float
None
get_rotation_gain(index) Get control gains for the rotation motor (k, kv, kp) index: int[1] dict
{'k', 'kv', 'kp'}
set_rotation_controller_type(val) set control type for rotation motor
0: HINFPID_CONTROLLER (default)
1: SIMPLEPID_POS_CONTROLLER
2: SIMPLEPID_VEL_CONTROLLER
int None
set_rotation_interpolator(val) set interpolator type for rotation motor
0: Ramp interpolator (default)
1: Streaming interpolator
int None
moby.set_rotation_vel_acc(vel, acc) Set maximum rotation velocity and acceleration vel:float
acc:float
None
set_drive_interpolator_on_off(on) Set activate/deactivate interpolator for drive wheels bool None
set_drive_acc_dec(acc, dec) Set maximum driving acceleration and deceleration acc:float
dec:float
None
set_kinematics_forced(activate, angle) Set Kinematics Forced
activate: allow infinite steering
angle: steering error limit to allow wheel driving
activate:bool
angle:float
None
get_kinematics_forced() Get Kinematics Forced
activate: allow infinite steering
angle: steering error limit to allow wheel driving
None activate:bool
angle:float

[1]: index : 1-Front Left, 2-Front Right, 3-Back Left, 4-Back Right</

사용 예시는 다음과 같습니다

# Get/Set Rotation Control Gain
print("Control Gain: ", moby.get_rotation_gain(0))
moby.set_rotation_gain(index=0, k=4000, kv=2000, kp=300)

# Set Rotation Interpolator Parameters
moby.set_rotation_interpolator(val=0)
moby.set_rotation_controller_type(val=0)
moby.set_rotation_vel_acc(vel=1.884, acc=942.0)

# Set Driving Interpolator Parameters
moby.set_drive_interpolator_on_off(on=True)
moby.set_drive_acc_dec(acc = 0.01, dec = 0.01)

moby.set_kinematics_forced(activate=True, angle=5.0)
  • 출력:
    Control Gain: {k: 4000.0, kv: 2000.0, kp: 300.0}
    

이 예제는 Control 및 Interpolator의 파라미터를 성정하는 방법을 보여줍니다.

예제에 설정된 파라미터는 로봇에 설정되어있는 기본 파라미터로, 값을 조금씩 바꿔가며 성능의 변화를 확인할 수 있습니다.

Real Time Logger

Command Description
start_rt_logging() Start to gather Moby data
end_rt_logging() Save data and Stop logging

start_rt_logging()를 사용하여 Moby의 주행관련 데이터를 기록하고, end_rt_logging()를 사용하여 기록을 종료 및 기록 파일을 생성합니다.

다음은 RT Log 명령어 예시입니다..

moby.start_rt_logging()

# robot driving

moby.end_rt_logging()

기록 파일은 '~/release/IndyDeployment/MobyRTLog'의 경로에 .csv 형태의 파일로 저장됩니다.

저장되는 데이터는 다음과 같습니다.

  • 0 : record time

  • rotation motor [fl, fr, bl, br]

    • 1, 2, 3, 4 : angle
    • 5, 6, 7, 8 : angular velocity
    • 9, 10, 11, 12 : torque
    • 13, 14, 15, 16 : target angle

    • 17, 18, 19, 20 : desired angle

    • 21, 22, 23, 24 : desired angular velocity
    • 25, 26, 27, 28 : desired angular acceleration
  • driving wheel [fl, fr, bl, br]

    • 29, 30, 31, 32 : linear velocity
    • 33, 34, 35, 36 : target linear velocity