机械臂功能

ECO65抓取试管demo

Ron 2024-05-23

系统:Windows11

硬件设备:ECO65机械臂、钧舵夹爪×2、试管、试管架

编程语言:python3.9

编程IDE:Pycharm

SDK版本:4.2.8

第一步、硬件安装如下图所示。

图1 夹爪1

图2 夹爪2

 

图3 ECO65

第二步、创建工程文件夹,将log_setting.py、RM_Base.dll、robotic_arm.py放到文件夹中,再新建一个py文件文件夹结构如图所示。

图4 文件夹结构

第三步、在demo.py编写以下程序。

import socket
import time
import json
from robotic_arm import *
port = 8080
client1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
# 左臂
Left = '192.168.1.18'
 
# 右臂
Right = '192.168.1.19'
 
left_robot = Arm(ECO65, Left)
right_robot = Arm(RM65, Right)
 
poDIAN2 = [-0.296145, -0.165672, 0.194378, 3.138, -0.004, 0]
 
#过渡点
poDIAN2GD = [-0.296145, -0.165672, 0.234378, 3.138, -0.004, 0]
 
poDIAN2H = [-0.296157, -0.165673, 0.333832, 3.138, -0.004, 0]
 
poDIAN4GD = [-0.359668, 0.106477, 0.205197, 3.152, -0.002, 0.047]
poDIAN4 = [-0.359674, 0.106474, 0.198199, 3.152, -0.002, 0.047]
poDIAN4H = [-0.359687, 0.106453, 0.293503, 3.152, -0.002, 0.047]
 
# 全局变量用于判断IO状态
IO_state_value = 0
def Robot_instruct_re(lr, instruct):
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    host = lr
    port = 8080
    client.connect((host, port))
    print('Robot_right_connect--OK')
    control = instruct
    client.send(control.encode('utf-8'))
    time.sleep(0.5)
    result = client.recv(1024).decode()
    print(result)
    client.close()
    return result
def Robot_instruct(lr, instruct):
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    host = lr
    port = 8080
    client.connect((host, port))
    print('Robot_right_connect--OK')
    control = instruct
    client.send(control.encode('utf-8'))
    time.sleep(0.5)
    result = client.recv(1024).decode()
    print(result)
    client.close()
# 关闭socket
def Robot_close(lr):
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    host = lr
    port = 8080
    client.connect((host, port))
    print('Robot_close--OK')
client.close()
# 打开socket
def Robot_open(lr):
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    host = lr
    port = 8080
    client.connect((host, port))
    print('Robot_open--OK')
speed2h_4h = 100
if __name__ == "__main__":
counter = 0
# 右臂打开控制器modbus
    while True:
        right_robot.Set_Modbus_Mode(0, 115200, 1, True)
        time.sleep(1)
    # 夹爪2初始化
        right_robot.Write_Registers(0, 1000, 1, [0, 0], 9, False)
        time.sleep(1)
    # 夹爪2上使能
        right_robot.Write_Registers(0, 1000, 1, [0, 1], 9, False)
        time.sleep(3)
#松开夹爪2
        right_robot.Write_Registers(0, 1000, 3, [0, 9, 0, 0, 255, 255], 9, False)
        time.sleep(1)
    # 左臂打开末端modbus
        left_robot.Set_Modbus_Mode(1, 115200, 1, True)
        time.sleep(1)
    # 夹爪1初始化
        left_robot.Write_Registers(1, 1000, 2, [0, 0, 0, 0], 9, True)
    # 夹爪1上使能
        left_robot.Write_Registers(1, 1000, 2, [0, 1, 0, 1], 9, True)
    # 夹爪1旋转使能
        left_robot.Write_Registers(1, 1004, 4, [1, 104, 32, 32, 1, 104, 0, 2], 9, True)
    # 松开夹爪1
        left_robot.Write_Registers(1, 1000, 1, [1, 11], 9, False)
        time.sleep(4)
# 到点2H
 
        left_robot.Movel_Cmd(poDIAN2H, 50, 0, True)
 
    # 到点2
        left_robot.Movel_Cmd(poDIAN2, 20, 0, True)
        time.sleep(2)
 
    # 左臂夹爪1闭合
        left_robot.Write_Registers(1, 1000, 1, [6, 11], 9, False)
        time.sleep(3)
 
    # 上提到点2H
        left_robot.Movel_Cmd(poDIAN2H, 70, 0, True)
 
    # 到点4H
        left_robot.Movel_Cmd(poDIAN4H, speed2h_4h, 0, True)
        time.sleep(2)
 
    # 再到点4
        left_robot.Movel_Cmd(poDIAN4, 40, 0, True)
        time.sleep(2)
# 夹爪2闭合
        right_robot.Write_Registers(0, 1000, 1, [4, 11], 9, False)
        time.sleep(2)
# 夹爪1反转,拧松盖子
 
        left_robot.Write_Registers(1, 1004, 4, [1, 104, 32, 32, -5, 104, 0, 2], 9, False)
        time.sleep(1)
 
    # 到点4GD
        left_robot.Movel_Cmd(poDIAN4GD, 1, 0, True)
        time.sleep(1)
 
    # 到点4H
        left_robot.Movel_Cmd(poDIAN4H, 50, 0, True)
        time.sleep(1)
    # 运行到点2H
 
        left_robot.Movel_Cmd(poDIAN2H, speed2h_4h, 0, True)
        time.sleep(1)
# 再到点4H
        left_robot.Movel_Cmd(poDIAN4H, speed2h_4h, 0, True)
        time.sleep(1)
    # 再到点4GD
 
        left_robot.Movel_Cmd(poDIAN4GD, 50, 0, True)
        time.sleep(1)
    # 夹爪1正转,拧紧盖子
        left_robot.Write_Registers(1, 1004, 4, [1, 104, 32, 32, 3, 104, 0, 2], 9, False)
    # 到点4
        left_robot.Movel_Cmd(poDIAN4, 1, 0, True)
        time.sleep(2)
# 松开右臂夹爪2
        right_robot.Write_Registers(0, 1000, 3, [0, 9, 0, 0, 255, 255], 9, False)
        time.sleep(2)
        # 到点4H
        left_robot.Movel_Cmd(poDIAN4H, 60, 0, True)
        time.sleep(1)
    # 到点2H
        left_robot.Movel_Cmd(poDIAN2H, speed2h_4h, 0, True)
        time.sleep(1)
    # 到点2
        left_robot.Movel_Cmd(poDIAN2GD, 60, 0, True)
        time.sleep(2)
 # 松开夹爪1
        left_robot.Write_Registers(1, 1000, 1, [1, 11], 9, False)
        time.sleep(1)
    # 到点2H
        left_robot.Movel_Cmd(poDIAN2H, 70, 0, True)
        time.sleep(1)
 
        right_robot.Close_Modbus_Mode(0,True)
        left_robot.Close_Modbus_Mode(1,True)
        counter += 1
        print("已运行:",counter,"次")

附件下载

0 条评论

关于作者

Ron

这家伙很懒,什么也没写!

选择发帖板块
选择发帖板块