# -- coding utf-8 --import osimport sysimport socketimport threadingimport timeosadd_dll_directoryCUsersyyyDesktop工比代码2023RobotLoaderimport DobotDllType as dType# 创建socket客户端变量socket_client1 = # 定义全局变
-- coding: utf-8 --
import os import sys import socket import threading import time os.add_dll_directory("C:/Users/yyy/Desktop/工比代码/2023/RobotLoader") import DobotDllType as dType
创建socket客户端变量
socket_client1 = ''
定义全局变量
i = 1 j = 0 k = 0 m = 1
定义机械臂状态,用键值存储
CON_STR = { dType.DobotConnect.DobotConnect_NoError: "DobotConnect_NoError", dType.DobotConnect.DobotConnect_NotFound: "DobotConnect_NotFound", dType.DobotConnect.DobotConnect_Occupied: "DobotConnect_Occupied"}
加载机械臂动态链接库DobotDll.dll
api = dType.load()
连接机械臂
state = dType.ConnectDobot(api, "COM6", 115200)[0]
打印机械臂连接状态
print("Connect status:",CON_STR[state])
设置机械臂末端为夹爪
dType.SetEndEffectorParams(api, 59.7, 0, 0, 1)
初始化清空机械臂的指令
dType.SetQueuedCmdClear(api)
开始执行队列指令
dType.SetQueuedCmdStartExec(api) print('Starting...')
def weizhi1(): time_start1=time.time() dType.SetPTPCmdEx(api, 0,247, -157, 48, 12, isQueued=1) #抓取物料 dType.SetEndEffectorGripper(api, 1, 1, isQueued=1) while True: time_end1 = time.time() if(time_end1-time_start1) > 2: break else : pass
def weizhi2(): if j==0 and i==4: time.sleep(3)#3 else: time_start2=time.time() dType.SetPTPCmdEx(api, 0, (197 + j50), (-157 + i46), -2+(m*50), 12, isQueued=1) dType.SetEndEffectorGripper(api, 1, 1, isQueued=1) while True: time_end2 = time.time() if(time_end2-time_start2) > 3:#3 break else : pass
传送带运行设置
def target_reach(): # 传送带速度19000pulse/s dType.SetEMotorEx(api, 0, 1, 19000, isQueued=1)#dType.SetEMotorEx(api, 0, 1, 19000, isQueued=1) time_start = time.time() weizhi2() socket_client.send("arrive".encode('utf-8')) #传送带运行到中间2s时发信号:解决左臂重复接收信号问题。 while True: time_end = time.time() # 3.5秒后传送带停止 if (time_end - time_start) > 4:#if (time_end - time_start) > 3: break else: pass
码垛堆叠多个方块
def pileup(): #移点 dType.SetPTPCmdEx(api, 0, 197, -157, 48, 12, isQueued=1)
# 抓取
dType.SetEndEffectorGripper(api, 1, 1, isQueued=1)
# 延时400ms
dType.dSleep(400)
# 放置
dType.SetPTPCmdEx(api, 0, 11, -275, 74, 12, isQueued=1) #y=-279 R=20
# 释放
dType.SetEndEffectorGripper(api, 1, 0, isQueued=1)
#传送带运行
dType.SetEMotorEx(api, 0, 1, 19000, isQueued=1)#dType.SetEMotorEx(api, 0, 1, 19000, isQueued=1)
#计时开始
time_start = time.time()
weizhi1()
dType.dSleep(2000)#2000
socket_client.send("arrive".encode('utf-8')) #传送带运行到中间2s时发信号:解决左臂重复接收信号问题。
while True:
time_end = time.time()
# 4秒后传送带停止
if (time_end - time_start) > 4:#4
break
else :
pass
# 传送带停止,触发相机拍照定位
dType.SetEMotorEx(api, 0, 0, 0, isQueued=1)
#抓到传送带上面
dType.SetPTPCmdEx(api, 0, 11, -275, 74, 12, isQueued=1)#dType.SetPTPCmdEx(api, 0, -56, -255, 74, 20, isQueued=1) #y=-279 R=20
pass
def pileup1():
global i,j,k,m
# 默认释放夹爪
dType.SetEndEffectorGripper(api, 1, 0, isQueued=1)
# 传送带固定运行3.5s
target_reach()
# 传送带停止,触发相机拍照定位
dType.SetEMotorEx(api, 0, 0, 0, isQueued=1)
# 一层
dType.SetPTPCmdEx(api, 0, (197 + j*50), (-157 + i*46), -2+(m*50), 12, isQueued=1)
if j==1 and i==0 and m==1:
dType.SetPTPCmdEx(api, 0,247, -157, 48, 12, isQueued=1)
dType.SetEndEffectorGripper(api, 1, 1, isQueued=1)
time.sleep(0.4)
dType.SetPTPCmdEx(api, 0, 11, -275, 74, 20, isQueued=1) #x=-56 y=-279
else:
pass
# 抓
原文地址: https://www.cveoy.top/t/topic/eEwg 著作权归作者所有。请勿转载和采集!