Skip to content

Moby gRPC Client Python API

Moby gRPC API List

Getting Moby Status Data

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 -

For example, you can obtain the status and error state of Moby as follows:

state = moby.get_moby_state()
print(state)

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

Status and error types are as follows:

  • STRING STATE

    • state: The current state of 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: EtherCAT master and slaves are all connected and activated
    • is_enable: All servos are turned on
    • is_moving: Moby is moving
    • is_violation: An error occurred
  • 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

Odometry and Robot Kinematics Data

Command Description Parameters Return Type
get_moby_pose() Get the Moby pose including position and orientation. None list [x, y, w]
get_moby_vel() Get the Moby velocity including linear and angular velocities. None list [x, y, w]
get_target_vel() Get the target velocity of Moby. None list [x, y, w]
reset_moby_pose() Reset the Moby pose to its initial state. None None
get_rotation_angle() Get the Moby's rotation angle. None dict [fl:Front Left, fr:Front Right, bl:Back Left, br:Back Right]
get_drive_speed() Get the drive speed of Moby. None dict [fl:Front Left, fr:Front Right, bl:Back Left, br:Back Right]
get_zero() Get the zero counts of rotation motors. None dict [fl:Front Left, fr:Front Right, bl:Back Left, br:Back Right]

Usage examples are as follows:

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()
  • Output:
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}

The example demonstrates obtaining Odometry and Physical data, and the Pose can be reset to its initial state using the reset_moby_pose() function.

Acquiring Sensor Values

Get various sensor data including gyroscope, Inertial Measurement Unit (IMU), UltraSonic (US) sensor data, and Battery Management System (BMS) data.

Commands:

  • get_gyro_data(): Retrieves gyroscope data, providing heading angle and angular velocity in radians and radians per second, respectively.
  • get_imu_data(): Fetches Inertial Measurement Unit (IMU) data, including angle, angular velocity, and linear acceleration.
  • reset_gyro(): Resets the gyroscope data to its initial state.
  • get_us_data(): Gathers UltraSonic (US) sensor data, useful for measuring distances or detecting objects.
  • get_bms(): Obtains Battery Management System (BMS) data, crucial for monitoring the battery's health and status.

Examples:

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

print("Gyro data:", gyro_data)
print("IMU data:", imu_data)
print("US data:", us_data)
print("BMS data:", bms_data)

Moby Motion Commands

Control Moby's movement through various motion commands.

Commands:

  • stop_motion(): Halts all motion of Moby immediately.
  • set_target_vel(vx, vy, vw): Sets the target linear and angular velocities for Moby, facilitating movement in the desired direction and speed.
  • move_rotation_deg(fl, fr, bl, br): Rotates each wheel of Moby by specified angles in degrees, allowing for precise positioning.
  • move_driving_mps(fl, fr, bl, br): Drives each wheel of Moby at specified speeds in meters per second, controlling the overall speed and direction of movement.

Examples:

moby.stop_motion()
moby.set_target_vel(0.5, 0.0, 0.1)
moby.move_rotation_deg(fl=90, fr=90, bl=90, br=90)
moby.move_driving_mps(fl=0.5, fr=0.5, bl=0.5, br=0.5)

Setting Moby Control Parameters

Configure various control parameters to optimize Moby's performance.

Commands:

  • set_zero_as_current(): Defines the current position of rotation motors as zero, recalibrating the system.
  • set_rotation_gain(index, k, kv, kp): Adjusts control gains (k, kv, kp) for the rotation motor, fine-tuning motor performance.
  • get_rotation_gain(index): Retrieves the control gains for the rotation motor, allowing for monitoring and adjustments.
  • set_rotation_controller_type(val): Sets the control type for rotation motors, selecting between different control strategies.
  • set_rotation_interpolator(val): Chooses the interpolator type for rotation motors, affecting motion smoothness.
  • set_rotation_vel_acc(vel, acc): Establishes maximum rotation velocity and acceleration, controlling the speed and responsiveness of movements.
  • set_drive_interpolator_on_off(on): Activates or deactivates the interpolator for drive wheels, influencing driving behavior.
  • set_drive_acc_dec(acc, dec): Sets maximum driving acceleration and deceleration, adjusting how quickly Moby accelerates and decelerates.

Examples:

print("Control Gain:", moby.get_rotation_gain(0))
moby.set_rotation_gain(index=0, k=4000, kv=2000, kp=300)
moby.set_rotation_interpolator(val=0)
moby.set_rotation_controller_type(val=0)
moby.set_rotation_vel_acc(vel=1.884, acc=942.0)
moby.set_drive_interpolator_on_off(on=True)
moby.set_drive_acc_dec(acc=0.01, dec=0.01)

Real Time Logger

Collect and save Moby's operational data for analysis and optimization.

Commands:

  • start_rt_logging(): Begins gathering data from Moby, useful for analysis and troubleshooting.
  • end_rt_logging(): Stops the data collection process and saves the gathered information, creating a log file for later review.

Examples:

moby.start_rt_logging()
# Perform robot driving activities
moby.end_rt_logging()

The log file is saved in the '~/release/IndyDeployment/MobyRTLog' directory in a .csv format, including detailed records of Moby's operational parameters such as angles, angular velocities,