Basic Control of the Robotics Arm

https://github.com/HKUArmStrong/dobot_workshop/blob/main/dobot.ipynb

Step 1: Find the Correct USB Port for the Robotic Arm

Before controlling the Dobot Magician, you must find which USB port it is connected to.

The following function helps you detect the correct port:

from serial.tools import list_ports

def find_robot_arm_port():
    print("Step 1: Please ensure the Dobot Magician is plugged in, then press Enter.")
    input()
    ports_before = {port.device for port in list_ports.comports()}

    print("Step 2: Now unplug the Dobot Magician, then press Enter.")
    input()
    ports_after = {port.device for port in list_ports.comports()}

    diff_ports = ports_before - ports_after
    if not diff_ports:
        print("No port difference detected. Please try again.")
        return None
    robot_port = diff_ports.pop()
    print(f"Dobot Magician detected on port: {robot_port}")
    return robot_port

port = find_robot_arm_port()
if port is None:
    print("Could not detect Dobot Magician port. Exiting.")
    exit(1)
print(f"Using port: {port}")

What this does:


Step 2: Calibrate (Home) the Arm

Once you know the port, connect to the Dobot Magician and home it to calibrate its reference position.

from pydobotplus import Dobot
import time

dobot = Dobot(port=port)
dobot.home() # The python code to home the robotic arm
print("Dobot Magician is homing...")
time.sleep(3)  # Wait for homing to complete

What this does:


Step 3: Move the Arm Forwards by 25 mm

You can move the arm in Cartesian coordinates using move_to()

Suppose you want to move to (x=275, y=0, z=50, r=0):