7.2.7 Integrated Examples

This section lists the UNO Q Debian Python example scripts. Start with control_rgb_demo.py to verify Python and Bridge communication, then continue with motion examples.

Note: The following scripts directly control the robot or accessories. Before running them, fix the robot arm, clear the working area, and make sure App Lab, TCP Socket, gamepad control, or other Python programs are not sending motion commands at the same time.

1. Example Script List

Script Function Robot motion
control_rgb_demo.py RGB color loop No
go_home_demo.py Return the robot to zero position Yes
single_joint_angle_demo.py Single-joint motion Yes
multi_joint_angles_demo.py Multi-joint motion Yes
control_robot_sway_demo.py Left-right sway Yes
control_robot_dance_demo.py Dance motion Yes
control_robot_gripper_demo.py Adaptive gripper test Yes
control_robot_pump_demo.py Pump pick-up process Yes

Run examples from the UNO Q Debian terminal:

cd ~/mycobot/example/debian
python3 control_rgb_demo.py

Run only one script at a time. Do not start the next example until the previous one has stopped.

2. RGB Color Loop

Script: control_rgb_demo.py. This example controls only the Atom RGB light and does not move the robot. Use it as the first communication test.

from pymycobot.mycobot280 import MyCobot280

import time

mc = MyCobot280(unoq_bridge=True)
time.sleep(2)

i = 7
# Loop 7 times
while i > 0:
    mc.set_color(0,0,255) # Blue light on
    time.sleep(2)
    mc.set_color(255,0,0) # Red light on
    time.sleep(2)
    mc.set_color(0,255,0) # Green light on
    time.sleep(2)
    i -= 1

Run:

python3 control_rgb_demo.py

3. Home Position

Script: go_home_demo.py. This example checks the controller connection and sends all 6 joints to zero position.

from pymycobot.mycobot280 import MyCobot280

import time

mc = MyCobot280(unoq_bridge=True)
time.sleep(2)

if mc.is_controller_connected() != 1:
    print("Please connect the robot arm correctly before running the program")
    exit(0)

# Return to zero position
mc.send_angles([0, 0, 0, 0, 0, 0], 30)

Run:

python3 go_home_demo.py

4. Single-Joint Motion

Script: single_joint_angle_demo.py. This example returns the robot to zero position, moves several joints one by one, and finally calls go_home().

from pymycobot.mycobot280 import MyCobot280

import time

mc = MyCobot280(unoq_bridge=True)
time.sleep(2)


# Return to zero position
mc.send_angles([0, 0, 0, 0, 0, 0], 40)
time.sleep(3)

# Move joint 3 to 70 degrees
mc.send_angle(3,70,40)
time.sleep(3)

# Move joint 4 to -70 degrees
mc.send_angle(4,-70,40)
time.sleep(3)

# Move joint 1 to 90 degrees
mc.send_angle(1,90,40)
time.sleep(3)

# Move joint 5 to -90 degrees
mc.send_angle(5,-90,40)
time.sleep(3)

# Move joint 5 to 90 degrees
mc.send_angle(5,90,40)
time.sleep(3)

# Return home
mc.go_home()

Run:

python3 single_joint_angle_demo.py

5. Multi-Joint Motion

Script: multi_joint_angles_demo.py. This example uses send_angles() to send 6 joint angles at the same time.

from pymycobot.mycobot280 import MyCobot280

import time

mc = MyCobot280(unoq_bridge=True)
time.sleep(2)


# Return to zero position
mc.send_angles([0, 0, 0, 0, 0, 0], 40)
time.sleep(2.5)

# Move multiple joints to different angles
mc.send_angles([90,45,-90,90,-90,90],50)
time.sleep(2.5)

# Return to zero position
mc.send_angles([0,0,0,0,0,0],50)
time.sleep(2.5)

# Move multiple joints to different angles
mc.send_angles([-90,-45,90,-90,90,-90],50)
time.sleep(2.5)

# Return to zero position
mc.send_angles([0,0,0,0,0,0],50)

Run:

python3 multi_joint_angles_demo.py

6. Left-Right Sway

Script: control_robot_sway_demo.py. This example reads the current angles, returns to zero, then moves joint 1 and joint 2 to create a left-right sway motion.

from pymycobot.mycobot280 import MyCobot280

import time

mc = MyCobot280(unoq_bridge=True)
time.sleep(2)


# Read current angles
angle_datas = mc.get_angles()
print(angle_datas)

# Move the robot to the specified position
mc.send_angles([0, 0, 0, 0, 0, 0], 50)
time.sleep(2.5)

# Move joint 1 to 90 degrees
mc.send_angle(1, 90, 50)
time.sleep(2)

# Loop count
num = 5

# Sway the robot arm left and right
while num > 0:
    mc.send_angle(2, 50, 50)
    time.sleep(1.5)
    mc.send_angle(2, -50, 50)
    time.sleep(1.5)
    num -= 1

# Fold the robot arm to a stored posture.
mc.send_angles([88.68, -138.51, 145.65, -128.05, -9.93, -15.29], 50)
time.sleep(2.5)

Run:

python3 control_robot_sway_demo.py

7. Dance Motion

Script: control_robot_dance_demo.py. This example contains fast continuous multi-pose motion. Clear the workspace and make sure the robot base is fixed before running it.

from pymycobot.mycobot280 import MyCobot280

import time

mc = MyCobot280(unoq_bridge=True)
time.sleep(2)

# Start time
start = time.time()
# Move to the specified position
mc.send_angles([-1.49, 115, -145, 30, -33.42, 137.9], 80)
# Check whether the robot reaches the specified position
while not mc.is_in_position([-1.49, 115, -145, 30, -33.42, 137.9], 0):
    mc.resume()
    time.sleep(0.5)
    mc.pause()
    if time.time() - start > 3:
        break

start = time.time()
# Run for 30 seconds
while time.time() - start < 30:
    mc.send_angles([-1.49, 115, -145, 30, -33.42, 137.9], 80)
    mc.set_color(0, 0, 50)
    time.sleep(0.7)
    mc.send_angles([-1.49, 55, -145, 80, 33.42, 137.9], 80)
    mc.set_color(0, 50, 0)
    time.sleep(0.7)

Run:

python3 control_robot_dance_demo.py

8. Gripper Control

Script: control_robot_gripper_demo.py. This example tests the adaptive gripper. Confirm the gripper type, power supply, and wiring before running it.

from pymycobot.mycobot280 import MyCobot280

import time

def gripper_test(mc):
    print("Start check IO part of api\n")
    flag = mc.is_gripper_moving()
    print("Is gripper moving: {}".format(flag))
    time.sleep(1)

    mc.send_angle(1, 0, 20)
    time.sleep(2)

    mc.send_angles([88.59, 89.91, -89.64, 90.7, 88.5, 89.29], 30)
    time.sleep(3)

    mc.set_gripper_value(100, 80, 1)
    time.sleep(3)
    mc.set_gripper_value(0, 80, 1)
    time.sleep(3)

    num=5
    while num>0:
        mc.set_gripper_state(0, 80, 1)
        time.sleep(3)
        mc.set_gripper_state(1, 80, 1)
        time.sleep(3)
        num-=1

    print("")
    print(mc.get_gripper_value())

if __name__ == "__main__":
    mc = MyCobot280(unoq_bridge=True)
    time.sleep(2)

    mc.send_angles([0, 0, 0, 0, 0, 0], 40)
    time.sleep(3)
    gripper_test(mc)

Run:

python3 control_robot_gripper_demo.py

9. Pump Control

Script: control_robot_pump_demo.py. This example controls the pump through end IO and uses multiple poses to complete a pick-up process. Confirm the pump wiring and IO definition before running it.

from pymycobot.mycobot280 import MyCobot280

import time

mc = MyCobot280(unoq_bridge=True)
time.sleep(2)

# Robot motion positions
angles = [
            [92.9, -10.1, -60, 5.8, -2.02, -37.7],
            [92.9, -53.7, -83.05, 50.09, -0.43, -38.75],
            [92.9, -10.1, -87.27, 5.8, -2.02, -37.7]
        ]


# Pump on
def pump_on():
    mc.set_digital_output(33, 0)
    time.sleep(0.05)

# Pump off
def pump_off():
    mc.set_digital_output(33, 1)
    time.sleep(0.05)
    mc.set_digital_output(23, 0)
    time.sleep(1)
    mc.set_digital_output(23, 1)
    time.sleep(0.05)

# Return to zero position
mc.send_angles([0, 0, 0, 0, 0, 0], 30)
time.sleep(3)

pump_on()
time.sleep(1)
mc.send_angles(angles[2], 30)
time.sleep(2)

# Pick up a small block
mc.send_angles(angles[1], 30)
time.sleep(2)
mc.send_angles(angles[0], 30)
time.sleep(2)
mc.send_angles(angles[1], 30)
time.sleep(2)

pump_off()
time.sleep(1)
mc.send_angles(angles[0], 40)
time.sleep(1.5)

Run:

python3 control_robot_pump_demo.py

The gamepad example requires extra input hardware and drivers. See 7.4 SBC Gamepad Control.

Previous: Gripper and Pump Control | Back to Python Development | Next: TCP Socket

results matching ""

    No results matching ""