MyAGV Plus API Documentation

Note: The APIs below are Python APIs. Please ensure the pymycobot Python SDK package is installed before use. This document is adapted based on the latest myagvplus and myagvplusapi source code.


1. System & Product Information

get_system_version()

  • Function: Get the main firmware version number.
  • Returns: float (Version number)

get_modify_version()

  • Function: Get the sub-firmware modification version number (accuracy fixed, returns the real value directly).
  • Returns: float (Version number)

power_on()

  • Function: Power on the robot (turn on the relay, enable all motors, and initialize velocity control mode).
  • Returns: int (1: Success, 0: Failure)

power_off()

  • Function: Power off the robot (disable all wheel motors and turn off the relay power).
  • Returns: int (1: Success, 0: Failure)

is_power_on()

  • Function: Check if the robot's chassis relay power is turned on.
  • Returns: int (1: Power on, 0: Power off)

get_robot_status()

  • Function: Read the robot's hardware exception status.
  • Returns: list[int] [Battery Status, Gyroscope Status, Power Level]
    • Battery Status: 0-Normal, 1-Abnormal
    • Gyroscope Status: 0-Normal, 1-Abnormal
    • Power Level: 0-Normal, 1-Warning (<=19.6V), 2-Low Battery (<19.0V)

get_all_msg()

  • Function: Fetch all chassis status information and sensor readings at once.
  • Returns: list
    • 0: (int) Battery Status (0: Normal, 1: Abnormal)
    • 1: (int) Gyroscope Status (0: Normal, 1: Abnormal)
    • 2: (int) Power Level (0: Normal, 1: Warning, 2: Critical Low)
    • 3: (str) Charging Status (binary string format)
    • 4: (float) Main Battery Voltage
    • 5: (float) Secondary Battery Voltage
    • 6: (list[float]) Parsed 18-byte gyroscope data
    • 7: (float) High-precision Main Battery Voltage (if supported)
    • 8: (float) High-precision Secondary Battery Voltage (if supported)

2. Movement Control

Warning:

  1. The valid range for the speed parameter in translation movement commands is 0.01 ~ 1.60 m/s. Passing an out-of-bounds value will trigger a warning and return directly.
  2. Safety Interlock & Undervoltage Protection: If the dual batteries detect an undervoltage (<19.0V) or a motor is overloaded and stalled, the background thread will automatically lock all movements, and subsequent movement commands will be intercepted.

move_forward(speed)

  • Function: Translate the robot forward.
  • Returns: int (1: Success, -1: Failed/Intercepted)

move_backward(speed)

  • Function: Translate the robot backward.
  • Returns: int (1: Success, -1: Failed/Intercepted)

move_left_lateral(speed)

  • Function: Translate the robot laterally to the left.
  • Returns: int (1: Success, -1: Failed/Intercepted)

move_right_lateral(speed)

  • Function: Translate the robot laterally to the right.
  • Returns: int (1: Success, -1: Failed/Intercepted)

turn_left(angular_speed)

  • Function: Rotate the robot in place to the left (counterclockwise).
  • Parameters: angular_speed (float): Angular speed
  • Returns: int (1: Success, -1: Failed/Intercepted)

turn_right(angular_speed)

  • Function: Rotate the robot in place to the right (clockwise).
  • Parameters: angular_speed (float): Angular speed
  • Returns: int (1: Success, -1: Failed/Intercepted)

stop()

  • Function: Stop all movements.
  • Returns: int (1: Success, -1: Failed/Intercepted)

set_auto_report_state(state)

  • Function: Set the auto-report state for underlying data (ESP32 actively reports every 50ms).
  • Parameters: state (int): 0-Disable, 1-Enable
  • Returns: int (1: Success, 0: Failure)

get_auto_report_state()

  • Function: Get the current auto-report state.
  • Returns: int (0: Disable, 1: Enable)

get_auto_report_message()

  • Function: Passively fetch the latest parsed auto-report data.
  • Returns: list (Structure is identical to the get_all_msg return value)

3. Motor Auxiliary Control

set_motor_enable(motor_id, state)

  • Function: Set the enable state of a motor.
  • Parameters:
    • motor_id (int): 1~4 represents a single motor.
    • state (int): 0-Disable, 1-Enable
  • Returns: int (1: Success)

get_motor_enable_status()

  • Function: Get the enable status of all motors.
  • Returns: list[int] [m1, m2, m3, m4] (0-Disabled/Offline, 1-Enabled/Online)

get_motor_status()

  • Function: Get the hardware error status code of each DM motor (0 means normal).
  • Returns: list[int] [m1, m2, m3, m4]

clear_motor_error(motor_id)

  • Function: Motor exception self-healing API to reset a stalled or errored motor.
  • Parameters: motor_id (int): 1~4
  • Returns: int (1: Success)

get_motor_temps()

  • Function: Get the current MOS temperature of each motor.
  • Returns: list[float] [m1, m2, m3, m4]

get_motor_velocity(motor_id)

  • Function: Get the current angular velocity of a specified motor.
  • Parameters: motor_id (int): 1~4
  • Returns: float (Angular velocity in rad/s)

get_motor_torque(motor_id)

  • Function: Get the current output torque of a specified motor.
  • Parameters: motor_id (int): 1~4
  • Returns: float (Torque in N·m)

get_motor_move_speeds()

  • Function: Batch fetch the travel speeds of all 4 motors.
  • Returns: list[float] [m1, m2, m3, m4]

get_motor_turn_speeds()

  • Function: Batch fetch the rotational speeds of all 4 motors.
  • Returns: list[float] [m1, m2, m3, m4]

get_motor_torques()

  • Function: Batch fetch the current output torque of all 4 motors.
  • Returns: list[float] [m1, m2, m3, m4]

4. IO Control & Communication

set_led_mode(mode)

  • Function: Set the LED mode.
  • Parameters: mode (int): 0-Battery indicator mode (default), 1-DIY custom mode
  • Returns: int (1: Success, 0: Failure)

set_led_color(brightness, color)

  • Function: Set DIY LED color (requires calling set_led_mode(1) first).
  • Parameters:
    • brightness (int): Brightness from 0 - 255
    • color (tuple): RGB tuple (R, G, B)
  • Returns: int (1: Success, 0: Failure)

get_pin_input(pin)

  • Function: Get the input IO status.
  • Parameters: pin (int): Pin number 1 - 6
  • Returns: int (Current level status; -1 for read failure or invalid pin)

set_pin_output(pin, state)

  • Function: Set the output IO level.
  • Parameters:
    • pin (int): 1 - 6
    • state (int): 0-Low level, 1-High level
  • Returns: int (1: Success, 0: Failure)

set_communication_state(state, force=False)

  • Function: Switch the underlying communication state mode. When switched to 1 (Socket), the local serial port will be intelligently released.
  • Parameters:
    • state (int): 0-Serial communication (default), 1-Socket communication, 2-Bluetooth communication
    • force (bool): Whether to force overwrite the locked state
  • Returns: int (1: Success, -1: Failure)

get_communication_state()

  • Function: Get the current communication state.
  • Returns: int (0-Serial, 1-Socket, 2-Bluetooth)

5. WiFi & Bluetooth

get_wifi_ip()

  • Function: Get the current connected Wi-Fi local area network IP.
  • Returns: str (IP address, returns empty string on failure)

get_wifi_account()

  • Function: Get the currently connected Wi-Fi account (SSID) name.
  • Returns: str (SSID, returns empty string on failure)

get_bluetooth_address()

  • Function: Get the MAC address of the local Bluetooth adapter.
  • Returns: str (Bluetooth MAC, returns empty string on failure)

6. Use Cases

6.1 Get AGVPlus System Information

from pymycobot import MyAGVPlus

# Initialize AGVPlus object
agv_plus = MyAGVPlus("/dev/myagvplus_controller", baudrate=921600, esp32_port='/dev/ttyACM0', esp32_baud=115200, debug=True)

# Get main firmware version number
version = agv_plus.get_system_version()
print(version)

# Get all chassis and battery status information
print(agv_plus.get_all_msg())

6.2 Control AGVPlus Movement & Lights

import time
from pymycobot import MyAGVPlus

agv_plus = MyAGVPlus("/dev/myagvplus_controller", baudrate=921600, esp32_port='/dev/ttyACM0', esp32_baud=115200, debug=True)

# Power on the robot (includes relay power-on and motor enabling, requires 6 seconds to wait)
agv_plus.power_on()

# Switch LED to DIY mode and set to red
agv_plus.set_led_mode(1)
agv_plus.set_led_color(255, (255, 0, 0))

# Control AGVPlus to move forward at 0.5m/s
agv_plus.move_forward(0.5)
time.sleep(3)

# Rotate in place
agv_plus.turn_left(0.3)
time.sleep(2)

# Stop movement
agv_plus.stop()

# Power off the robot and disable motors
agv_plus.power_off()

6.3 Get Network Info and Switch Communication Mode to Socket

from pymycobot import MyAGVPlus

agv_plus = MyAGVPlus("/dev/myagvplus_controller", baudrate=921600, esp32_port='/dev/ttyACM0', esp32_baud=115200, debug=True)

# Get AGVPlus WIFI account
account = agv_plus.get_wifi_account() 
print(f"SSID: {account}")

# Get AGVPlus IP address
ip = agv_plus.get_wifi_ip()
print(f"IP: {ip}")

# Set current communication mode to Socket
set_result = agv_plus.set_communication_state(1)
if set_result == 1:
    print("Set communication mode to Socket successfully.")

6.4 Start and Use the Socket Daemon for Seamless Remote Control

The Socket mode allows you to control the AGV with zero latency from any computer connected to the same LAN, perfectly supporting secondary development.

Step 1: Start the network daemon on the robot's mainboard (Jetson Nano/Raspberry Pi) Open the terminal and run:

python3 -m pymycobot.myagvplussocket_server # or run a specific agv_socket_server.py

(Note: While this program is running, the background will automatically detect the communication state and take over port 9000 of the physical serial port.)

Step 2: Trigger the state switch command in your code

agv_plus.set_communication_state(1)

The underlying layer will instantly release the usage rights of the physical serial port! Once the background socket server detects the mode has changed to 1, it will take over the chassis.

Step 3: Control from a remote computer

from pymycobot.myagvplussocket import MyAGVPlusSocket
import time

# Connect to the robot's IP, specify port 9000
agv = MyAGVPlusSocket("192.168.1.132", 9000)

print(agv.get_motor_move_speeds()) # Remotely read speed information
agv.move_left_lateral(0.3)         # Remotely control left lateral movement
time.sleep(2)
agv.stop()

← Previous Page | Next Page →

results matching ""

    No results matching ""