def __init__(self, dobotPort='/dev/ttyUSB0'): available_ports = glob('/dev/tty*USB*') # mask for OSX Dobot port if len(available_ports) == 0: print('no port /dev/tty*USB* found for Dobot Magician') exit(1) #self.DobotPort = 'COM4' self.DobotPort = dobotPort; self.ecRelay = Relay(18);#bcm pin for physical pin 12 self.pdRelay = Relay(24);#bcm for physical 18 self.rhRelay = Relay(23);#bcm for physical 16 self.gripper = ServoGripper(2); self.dvc = DigitalVoltControl(); self.lastCmd = [0,0,0,0]; #x, y, z, r print("Setting Port to " + self.DobotPort); self.device = Dobot(port=self.DobotPort) time.sleep(1) if self.device is not None: print("Opened connection") self.device.speed(60) self.z_up = 100 self.z_down = -70 #self.RH_Voltage = 2.5; #self.PD_Voltage = 1.9; #self.EC_Voltage = 4.8; self.home_xyzr = [215, 0, self.z_up, 0]; global global_status global_status = "Rh Electroplating";
def dobotPort(port, fungsi): if fungsi == 1: main = Dobot(port=port) return main if fungsi == 2: jog = JOG(port=port) return jog
def _connect_dobot(self, i): try: portArray = [ "/dev/ttyUSB0", "/dev/ttyUSB01", "/dev/ttyUSB2", "/dev/ttyUSB3", "/dev/ttyUSB4", "/dev/ttyUSB5", "/dev/ttyS0", "/dev/ttyS1", "/dev/ttyS2", "/dev/ttyS3", "/dev/ttyS4", "/dev/ttyS5" ] self.device = Dobot(port=portArray[i], verbose=False) print("連接成功") except Exception as e: print("無法在" + portArray[i] + "連接Dobot\n原因:" + str(e)) if (i < len(portArray) - 1): print("沒關係的別驚慌,我會嘗試連接下一個port\n") self._connect_dobot(i + 1) else: print("連接失敗,請檢查是否有將dobot接上USB")
def connect_dobot(): available_ports = glob('/dev/ttyUSB0') # mask for OSX Dobot port if len(available_ports) == 0: print("NOT FOUND!!!") print('no port found for Dobot Magician') exit(1) # device = Dobot(port=available_ports[0]) print("Connected") return device
def __init__(self,streamload,mtx=[],dist=[]): self.refh = 20 self.z_ = None self.H = [] self.imaskG = [] self.mtx = mtx self.dist = dist self.awaycoor = (-25,-230,50) self.cencoor = (254,8,13) self.armcp = np.array([[271.55,7.53],[272.76,91.28],[319.10,6.78], [268.29,-163.73],[207.71,77.28],[304.95,-91.05]]) self.streamload = streamload port = list_ports.comports()[0].device device = Dobot(port=port,verbose=False) self.device = device self.columns = os.get_terminal_size().columns
import time from glob import glob from pydobot import Dobot available_ports = glob('/dev/cu*usb*') # mask for OSX Dobot port if len(available_ports) == 0: print('no port found for Dobot Magician') exit(1) device = Dobot(port=available_ports[0]) time.sleep(0.5) device.speed(100) device.go(250.0, 0.0, 25.0) device.speed(10) device.go(250.0, 0.0, 0.0) time.sleep(2) device.close()
from serial.tools import list_ports from pydobot import Dobot port = list_ports.comports()[0].device device = Dobot(port=port, verbose=True) (x, y, z, r, j1, j2, j3, j4) = device.pose() (l) = device.pose_l() print(f'x:{x} y:{y} z:{z} r:{r} l:{l} j1:{j1} j2:{j2} j3:{j3} j4:{j4}') #device.move_to(x + 100, y, z, r, wait=False) #device.move_to(x + 100, y + 100, z, r, wait=False) #device.move_to(x + 100, y + 100, z + 100, r, wait=False) device.grip(False) #device.move_to(x, y, z, r, wait=True) # we wait until this movement is done before continuing #device.grip(True) #device.move_to(x + 20, y, z, r, wait=False) #device.move_to(x, y, z, r, wait=True) device.move_to_with_l(228, -65, -18, -17, 0, wait=True) #device.move_to_with_l(228, -65, -47, -16, 0, wait=True) device.suck(False) #device.move_to_with_l(x, y, z, r, l, wait=True) device.close()
from math import sqrt, asin, pi, degrees from serial.tools import list_ports from time import sleep from pydobot import Dobot import speech_recognition as sr # import win32com.client as wincl # from simpleTest import armMotor, modelInit, modelExit # import SpeechRecognition as sr def modelInit(): pass port = list_ports.comports()[1].device device = Dobot(port=port, verbose=True) modelInit() def sendToModel(): pass # arrToModel = [] # (_, __, ___, ____, arrToModel[0], arrToModel[1], arrToModel[2], arrToModel[3]) = device.pose() # armMotor(arrToModel) def findLine(a, b): return sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2) def talk(words):
class CustomDobot: def __init__(self, port): self.device = Dobot(port=port, verbose=True) self.home_x = 200 self.home_y = 0 self.home_z = 135 def speed(self, speed: float): self.device.speed(speed) def set_home(self, x: float, y: float, z: float): self.home_x = x self.home_y = y self.home_z = z def relocate(self): self.device.home() self._move_home() def move_and_suck(self, from_x: float, from_y: float, from_z: float, to_x: float, to_y: float, to_z: float): self._move_home() (now_x, now_y, now_z, now_r, now_j1, now_j2, now_j3, now_j4) = self.device.pose() # move to object location self.device.move_to(from_x, from_y, now_z) self.device.move_to(from_x, from_y, from_z) # suck object self.device.suck(True) # move to target location self.device.move_to(now_x, now_y, self.home_z) self.device.move_to(to_x, to_y, self.home_z) self.device.move_to(to_x, to_y, to_z) self.device.suck(False) def move_to(self, x=None, y=None, z=None): if x is None: x = self.pose()[0] if y is None: y = self.pose()[1] if z is None: z = self.pose()[2] self.device.move_to(x, y, z) self.show_position() def _move_home(self): (now_x, now_y, now_z, now_r, now_j1, now_j2, now_j3, now_j4) = self.device.pose() self.device.move_to(now_x, now_y, self.home_z) self.device.move_to(self.home_x, self.home_y, self.home_z) def suck(self, suck): self.suck(suck) def pose(self): return self.device.pose() def show_position(self): (x, y, z, r, j1, j2, j3, j4) = self.device.pose() print() print(TerminalColor.Green + "CUSTOM_DOBOT at position:") print(TerminalColor.Green + 'x:{', x, '}\ny:{', y, '}\nz:{', z, '}') print(TerminalColor.ResetAll) def close(self): self.device.close()
from board import * from utils import * import time import cv2 import vision from pydobot import Dobot # 连接机械臂 global device device = Dobot(port='com6', verbose=False) time.sleep(0.5) device.speed(1) device._get_pose() # 位置初始化 device.go_init_pos() def text_objects(text, font): textSurface = font.render(text, True, black) return textSurface, textSurface.get_rect() def message_display(text, x, y, size): largeText = pygame.font.Font('freesansbold.ttf', size) TextSurf, TextRect = text_objects(text, largeText) TextRect.center = (x, y) screen.blit(TextSurf, TextRect) pygame.display.update()
def main(): global bootOffset global nextBlue global nextOrange global tokensInPlay global orangeStorage global blueStorage global playArea if not simulate: port0 = list_ports.comports()[0].device device0 = Dobot(port=port0, verbose=True) (x1, y1, z1, r1, j1, j2, j3, j4) = device0.pose() bootOffset["x"] = x1 bootOffset["y"] = y1 bootOffset["z"] = z1 # print(f'x:{x1} y:{y1} z:{z1} r:{0} j1:{j1} j2:{j2} j3:{j3} j4:{j4}') device0.speed(250, 250) device0.move_to(x1, y1, z1 - 1, 0, wait=False) device0.suck(True) device0.move_to( x1, y1, z1 + 20, 0, wait=False ) # we wait until this movement is done before continuing device0.move_to( x1 + 81.5, y1 - 94.5, z1 + 20, 0, wait=False ) # we wait until this movement is done before continuing device0.move_to( x1 + 81.5, y1 - 94.5, z1, 0, wait=False ) # we wait until this movement is done before continuing device0.suck(False) device0.move_to( x1 + 81.5, y1 - 94.5, z1 + 20, 0, wait=False ) # we wait until this movement is done before continuing device0.move_to(x1 - 36, y1 - 56, z1 + 20, 0, wait=False) try: os.remove("position_log.txt") except Exception as e: print("Exception while deleting file position_log.txt: " + str(e)) # starting move to reposition home block from center of grid to last position of orange nest while (1): if (inputSource == "buttons"): if GPIO.input(button1) == 0: playStep("11") if GPIO.input(button2) == 0: playStep("12") if GPIO.input(button3) == 0: playStep("13") if GPIO.input(button4) == 0: playStep("21") if GPIO.input(button5) == 0: playStep("22") if GPIO.input(button6) == 0: playStep("23") if GPIO.input(button7) == 0: playStep("31") if GPIO.input(button8) == 0: playStep("32") if GPIO.input(button9) == 0: playStep("33") elif (inputSource == "console"): while True: consoleInput = "" while consoleInput == "": consoleInput = "" consoleInput = input( "Select a position to place your token. Use the number pad orientation:\n" ) if len(consoleInput) == 1 and consoleInput.isdigit(): playStep(digitInputLookup[str(consoleInput)]) elif len(consoleInput) > 1: print("Please enter only one position!") elif not consoleInput.isdigit(): print("Please enter only one digit!")
elif (mode == 0): device.set_io_multiplexing(index, EIOMode.IO_FUNC_DUMMY) device.set_io_do(index, 0) return ("IO %d INPUT" % (index)) available_ports = [] for port in list_ports.comports(): if (port.pid == 0x7523 and port.vid == 0x1a86): available_ports.append(port.device) if len(available_ports) == 0: print("No Dobot found") exit() device = Dobot(port=available_ports[0], verbose=False, skipInit=False) device._get_device_version() print(("Dobot device version: %d.%d.%d" % (device.majorVersion, device.minorVersion, device.revision))) webRespDict["/version"] = ( "Dobot device version: %d.%d.%d" % (device.majorVersion, device.minorVersion, device.revision)) webRespDict["/jog"] = jogMachine webRespDict["/emotor"] = moveEMotor webRespDict["/pose"] = getPose webRespDict["/home"] = home webRespDict["/moveinc"] = moveInc webRespDict["/io"] = accessIOPorts laserJig = LaserJig.LaserJig(device)
class DobotPlating(): def __init__(self, dobotPort='/dev/ttyUSB0'): available_ports = glob('/dev/tty*USB*') # mask for OSX Dobot port if len(available_ports) == 0: print('no port /dev/tty*USB* found for Dobot Magician') exit(1) #self.DobotPort = 'COM4' self.DobotPort = dobotPort; self.ecRelay = Relay(18);#bcm pin for physical pin 12 self.pdRelay = Relay(24);#bcm for physical 18 self.rhRelay = Relay(23);#bcm for physical 16 self.gripper = ServoGripper(2); self.dvc = DigitalVoltControl(); self.lastCmd = [0,0,0,0]; #x, y, z, r print("Setting Port to " + self.DobotPort); self.device = Dobot(port=self.DobotPort) time.sleep(1) if self.device is not None: print("Opened connection") self.device.speed(60) self.z_up = 100 self.z_down = -70 #self.RH_Voltage = 2.5; #self.PD_Voltage = 1.9; #self.EC_Voltage = 4.8; self.home_xyzr = [215, 0, self.z_up, 0]; global global_status global_status = "Rh Electroplating"; def calibrate(self): self.device.goHome(); def isMoveFinished(self): euDist = math.pow(self.lastCmd[0] - self.device.x,2) + math.pow(self.lastCmd[1] - self.device.y, 2) + math.pow(self.lastCmd[2] - self.device.z, 2) + math.pow(self.lastCmd[3] - self.device.r, 2); euDist = math.sqrt(euDist); if(euDist < 2): return True; else: #print("still moving .."); return False; def move_home(self): self.move_xy(self.home_xyzr[0], self.home_xyzr[1], self.home_xyzr[2], self.home_xyzr[3], 0.3); def move_xy(self, x, y, z, r, duration = 1): self.lastCmd = [x, y, z, r]; self.device.go(x, y, z, r); #MOVJ # time.sleep(duration); # print("in is move finished.."); print("xyzr position: " + str(self.device.x) + ", " + str(self.device.y) + ", " + str(self.device.z) + ", " + str(self.device.r)); def move_xy_linear(self, x, y, z, r, duration = 1): self.lastCmd = [x, y, z, r]; self.device.goMovL(x, y, z, r); #MOVJ # time.sleep(duration); # print("in is move finished.."); print("xyzr position: " + str(self.device.x) + ", " + str(self.device.y) + ", " + str(self.device.z) + ", " + str(self.device.r)); def shake(self, x, y, z, r, shakeDuration, dispStr): global global_status; t_end = time.time() + shakeDuration; tdiff = t_end - time.time(); while tdiff > 0: if(dispStr is not None): global_status = dispStr + str(int(tdiff)) + "s" self.move_xy(x, y, z + 10, r, 0.1); self.move_xy(x, y, z - 10, r, 0.1); tdiff = t_end - time.time(); def up_down_beaker(self,id): print ("Doing beaker %d now" % (id)); self.move_xy(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3], 0.3); self.move_xy(Beakers[id][0], Beakers[id][1], (self.z_up + self.z_down)/2.0 , Beakers[id][3], 0.3); #adding a mid point so that the Joint motion isn't touching th edges of the beakers self.move_xy(Beakers[id][0], Beakers[id][1], self.z_down, Beakers[id][3], 0.3); dispStr = "Step " + str(id) + ": "; while(not self.isMoveFinished()): time.sleep(0.01); if(id == 1): self.ecRelay.on(); dispStr = dispStr + "EC " elif(id == 8): self.pdRelay.on(); dispStr = dispStr + "Pd Solution " elif(id == 11): self.rhRelay.on(); dispStr = dispStr + "Rh Solution " if(id == 1 or id == 8 or id == 11): if(id == 11): self.shake(Beakers[id][0], Beakers[id][1], self.z_down - 20, Beakers[id][3], Beakers[id][4], dispStr); #x, y, z and shake_duration else: self.shake(Beakers[id][0], Beakers[id][1], self.z_down, Beakers[id][3], Beakers[id][4], dispStr); #x, y, z and shake_duration else: self.shake(Beakers[id][0], Beakers[id][1], self.z_down, Beakers[id][3], Beakers[id][4], None); #x, y, z and shake_duration self.ecRelay.off(); self.pdRelay.off(); self.rhRelay.off(); #move up #shake to drop the excess drops #go half way to adjust for MOVJ self.move_xy(Beakers[id][0], Beakers[id][1], (self.z_up + self.z_down)/2.0 , Beakers[id][3], 0.3); #adding a mid point so that the Joint motion isn't touching th edges of the beakers #self.move_xy(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3]); self.shake(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3], 2, None); self.move_xy(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3]); while(not self.isMoveFinished()): time.sleep(0.01); def startProcess(self, EC_Voltage, PD_Voltage, RH_Voltage): global process_running process_running = True; global global_status global_status = "Step 1: EC" #1 if(EC_Voltage == 5.6): self.dvc.setMaxVoltage(); else: self.dvc.setVoltage(EC_Voltage); self.up_down_beaker(1); #2 global_status = "Step 2: Dragout" self.up_down_beaker(2); #3 global_status = "Step 3: Water" self.up_down_beaker(3); #4 global_status = "Step 4: Activation" self.up_down_beaker(4); #5 global_status = "Step 5: Water" self.up_down_beaker(5); #6 global_status = "Step 6: Water" self.up_down_beaker(6); #7 global_status = "Step 7: Water" self.up_down_beaker(7); #8 #global_status = "Step 8: Pd Solution" #self.dvc.setVoltage(PD_Voltage); #self.up_down_beaker(8); #9 #global_status = "Step 9: Pd Dragout" #self.up_down_beaker(9); #10 #global_status = "Step 10: Water" #self.up_down_beaker(10); #11 global_status = "Step 11: Rh Solution" self.dvc.setVoltage(RH_Voltage); self.up_down_beaker(11); #12 global_status = "Step 12: Rh Dragout" self.up_down_beaker(12); #13 #repeat of beaker 10 global_status = "Step 13: Water" self.up_down_beaker(10); #Home self.move_home() global_status = "Done.." process_running = False; print("\n DONE \n"); def __del__(self): self.device.close(); del self.gripper; del self.dvc; del self.ecRelay; del self.pdRelay; del self.rhRelay; print("Exiting Cleanly..");
from serial.tools import list_ports from pydobot import Dobot port = list_ports.comports()[0].device device = Dobot(port=port, verbose=True) (x, y, z, r, j1, j2, j3, j4) = device.pose() print() print('|Before| x:{', x, '} y:{', y, '} z:{', z, '} r:{', r, '} j1:{', j1, '} j2:{', j2, '} j3:{', j3, '} j4:{', j4, '}') print() device.speed(10) device.wait_for_cmd(device.move_to(206, 0, 134)) (x, y, z, r, j1, j2, j3, j4) = device.pose() device.wait_for_cmd(device.move_to(x, y, -20)) (x, y, z, r, j1, j2, j3, j4) = device.pose() print() print('|After | x:{', x, '} y:{', y, '} z:{', z, '} r:{', r, '} j1:{', j1, '} j2:{', j2, '} j3:{', j3, '} j4:{', j4, '}') print() device.close()
#if psutil.OSX: # available_ports = glob('/dev/cu*usbserial*') # mask for OSX Dobot port #if psutil.LINUX: # available_ports = glob('/dev/ttyUSB*') # mask for Linux Dobot port available_ports = [] for port in list_ports.comports(): if (port.pid == 0x7523 and port.vid == 0x1a86): available_ports.append(port.device) if len(available_ports) == 0: print("No Dobot found") exit() device = Dobot(port=available_ports[0], verbose=True) device._get_device_version() #test only #device._set_end_effector_parameters(65) #paste dispenser #device._get_end_effector_parameters() #device._get_jog_joint_parameters() #default: jog joint velocity 15.0, 15.0, 15.0, 30.0. jog joint acceleration 50.0, 50.0, 50.0, 50.0 #device._get_jog_coordinate_parameters() #default:jog coordinate velocity 60.0, 60.0, 60.0, 60.0. jog coordinate acceleration 60.0, 60.0, 60.0, 60.0 #device._set_jog_common_parameters(1.5,5.0) #device._get_jog_common_parameters() #default jog velocityRatio:15.000 jog accelerationRatio:50.000 #device.set_arc_params(50,50); #device.move_to(200,0,25,0, wait=True) #device.arc_via_to(210,0,25,0,220,10,25,0, wait=True)
# Copyright (c) 2020 Sagar Gubbi. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import socket from pydobot import Dobot CLIENT_UDP_IP = "0.0.0.0" UDP_PORT = 9090 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind((CLIENT_UDP_IP, UDP_PORT)) d = Dobot(port='/dev/ttyUSB0', verbose=False) d.wait_for_cmd(d.suck(True)) d.wait_for_cmd(d.grip(False)) g_state = False d_origin_x = 225. d_origin_y = 0. d_origin_z = 15. dr = -20 d_scale = 300. dx_min, dx_max = 180, 270 dy_min, dy_max = -110, 110 dz_min, dz_max = -30, 70
from serial.tools import list_ports from pydobot import Dobot from util import (BELT_ONE_X_POSITION, BELT_ONE_Y_POSITION, BELT_TW0_Y_POSITION, BELT_TWO_X_POSITION, QUEUE_X_POSITION, QUEUE_Y_POSITION, HOME_X, HOME_Y) port = list_ports.comports()[0].device device = Dobot(port=port, verbose=True) # device.move_to_with_l(HOME_X, HOME_Y, -30, -75, 450, wait=True) # start positon # device.move_to_with_l(QUEUE_X_POSITION, QUEUE_Y_POSITION, -30, -75, 400, wait=True) # Position above queue start # device.move_to_with_l(HOME_X, HOME_Y, -30, -75, 100, wait=True) # Stop between both # device.move_to_with_l(BELT_ONE_X_POSITION, BELT_ONE_Y_POSITION, -20, -10, 0, wait=True) # Position above first conveyor belt # device.move_to_with_l(120, -215, -30, -75, 620, wait=True) # Position above queue end to push # device.move_to_with_l(120, -215, -75, -75, 620, wait=True) # Position behind queue end to push # device.move_to_with_l(325, 0, -20, 40, 825, wait=True) # Position above second conveyor belt # device.move_to_with_l(QUEUE_X_POSITION, QUEUE_Y_POSITION, -30, -75, 625, wait=True) # Position above queue end to put device.move_to_with_l(QUEUE_X_POSITION, QUEUE_Y_POSITION, -75, -75, 645, wait=True) # Position above queue end to push device.close()
from serial.tools import list_ports from pydobot import Dobot port = list_ports.comports()[0].device device = Dobot(port=port, verbose=True) (x, y, z, r, j1, j2, j3, j4) = device.pose() (l) = device.pose_l() device.move_to_with_l(236, 23, 20, 5, 0, wait=True) # we wait until this movement is done before continuing device.move_to_with_l(226, 106, -28, 5, 0, wait=True) # we wait until this movement is done before continuing device.grip(True) device.close()
from serial.tools import list_ports from pydobot import Dobot port = list_ports.comports()[0].device device = Dobot(port=port, verbose=True) (x, y, z, r, j1, j2, j3, j4) = device.pose() (l) = device.pose_l() device.move_to_with_l( x, y, 20, r, l, wait=True) # we wait until this movement is done before continuing device.move_to_with_l(300, 40, 20, 20, 600, wait=True) device.move_to_with_l( 300, 40, -45, 20, 600, wait=True) # we wait until this movement is done before continuing device.grip(False) device.suck(False) device.close()
import sys # Global variable definitions TURTLE_SIZE = 10 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) flag = False tmp = '' message = '' count = 0 column = 0 c = 0 # Binding for the socket. IP, Port s.bind(('127.0.0.1', 2000)) # Physical port where DoBot is. port = list_ports.comports()[1].device device = Dobot(port=port, verbose=False) def init(): device.speed(75,75) # Defines dobot velocity and acceleration in 75% device.move_to(250, 0, 50, 0, wait=True) #DOBOT HOME #print("Move DoBOT to desired position for writing") #input("Press Enter to continue...") device.move_to(193.02188110351562, -45.02191162109375, -48.760108947753906, 0, wait = True) def receive(): recibido = s.recvfrom(1024) # Receives message using socket data = recibido[0] message_received = '' for key in data: message_received += chr(key) message_received=message_received.upper()
from serial.tools import list_ports import util from pydobot import Dobot port = list_ports.comports()[0].device device = Dobot(port=port, verbose=False) util.pushCubeQueue(device) device.close()
class MainWindow(QtWidgets.QMainWindow, Ui_Form): def __init__(self, parent=None): super(MainWindow, self).__init__(parent=parent) self.setupUi(self) self.nowItem = [] self.x = 640.0 self.y = 360.0 self.user_set_pos = [(0, 0, 0, 0)] print("開始自動尋找dobot所在的port\n") self._connect_dobot(0) self._init_ui_connect() self.isScanDone = False self.get_pos() self.waitTime = 2 def _connect_dobot(self, i): try: portArray = [ "/dev/ttyUSB0", "/dev/ttyUSB01", "/dev/ttyUSB2", "/dev/ttyUSB3", "/dev/ttyUSB4", "/dev/ttyUSB5", "/dev/ttyS0", "/dev/ttyS1", "/dev/ttyS2", "/dev/ttyS3", "/dev/ttyS4", "/dev/ttyS5" ] self.device = Dobot(port=portArray[i], verbose=False) print("連接成功") except Exception as e: print("無法在" + portArray[i] + "連接Dobot\n原因:" + str(e)) if (i < len(portArray) - 1): print("沒關係的別驚慌,我會嘗試連接下一個port\n") self._connect_dobot(i + 1) else: print("連接失敗,請檢查是否有將dobot接上USB") #compute (u,v) to real world corrdinate space def trans(self): (x, y, z) = self.get_pos() u = self.x v = self.y X = np.array([[u, v, 1.0]]).reshape(1, 3) M = np.array([[3.68564350e-02, -3.29055785e-01, -1.51788304e-18], [-3.54059036e-01, -4.73030558e-02, 2.60208521e-18], [3.56735424e+02, 2.87496286e+02, 1.00000000e+00]]) result = X.dot(M) #self.depth = self.th.get_depth(u, v) #we use fixed depth for now #if(self.depth==0.0): # self.depth = self.th.get_depth(u, v) # print("trying to get depth but fail\n") self.device.move_to(211.9, 1.1, 172.64, 0.0, wait=True) #depth = self.depth*1000.0 - 65.0 #depth = 172.64 - depth #print("self depth") #print(self.depth) #self.device.move_to(x+20.0 ,y ,depth+10.0, 0.0 , wait = True) self.device.move_to(result[0][0] - 2.5, result[0][1] + 1.5, -91.0, 0.0, wait=True) # go to initinal position def return_ori(self): (x, y, z) = self.get_pos() #191.34018, 1.1, 172.64001 self.device.move_to(x, y, z + 40, 0.0) self.device.move_to(211.9, y, z + 40, 0.0) self.device.move_to(211.9, 21.100004196166992, z + 40, 0.0) self.device.move_to(211.9, 21.100004196166992, 172.64, 0.0) self.device.move_to(191.26025390625, 21.100004196166992, 172.6400146484375, 0.0) self.get_pos() def rotate_90(self): self.device.move_to(191.34018, 1.1, 172.64001, 0.0) (x, y, z) = self.get_pos() y = y - 40 self.device.move_to(x, y, z, 0.0) x = x + 80 z = z + 70 self.device.move_to(x, y, z, 0.0) y = y + 60 x = x + 60 self.device.move_to(x, y, z, 0.0) y = y + 40 x = x + 40 self.device.move_to(x, y, z, 0.0) x = x + 40 y = y + 100 self.device.move_to(x, y, z, 0.0) x = x - 20 y = y z = z + 80 self.device.move_to(x, y, z, 0.0) def rotate_minus90(self): (x, y, z) = self.get_pos() x = x + 20 y = y z = z - 80 self.device.move_to(x, y, z, 0.0) x = x - 40 y = y - 100 self.device.move_to(x, y, z, 0.0) y = y - 40 x = x - 40 self.device.move_to(x, y, z, 0.0) y = y - 60 x = x - 60 self.device.move_to(x, y, z, 0.0) x = x - 80 z = z - 70 self.device.move_to(x, y, z, 0.0) y = y + 40 self.device.move_to(x, y, z, 0.0) # x -80 # z - 70 # y +40 def _init_ui_connect(self): _translate = QtCore.QCoreApplication.translate self.btn_new.clicked.connect(self._set_user_set_pos) #get data self.btn_move.clicked.connect(self.action) self.btn_go.clicked.connect(self.trans) self.comboBox.insertItem(0, "點1") self.lineEdit.textEdited.connect(self.set_time) self.X_edit.textEdited.connect(self.set_x) self.Y_edit.textEdited.connect(self.set_y) self.Z_edit.textEdited.connect(self.set_z) self.R_edit.textEdited.connect(self.set_r) self.comboBox.currentIndexChanged.connect(self.switch_point) self.lineEdit.setText(_translate("Form", str(2))) self.btn_rotate_j1_90.clicked.connect(self.rotate_minus90) self.btn_reverse.clicked.connect(self.rotate_90) self.streampopup = MyPopup(dobot=self) self.streampopup.show() self.setWindowFlags(Qt.WindowStaysOnTopHint) #self.btn_detect.clicked.connect(self.single_detect) #button.clicked.connect(lambda: calluser(name)) self.interval = 1 self.input_interval.textEdited.connect(self.set_inputinterval) self.btn_x_increase.clicked.connect( lambda: self.move_xyz(self.interval, 0, 0)) self.btn_x_reduce.clicked.connect( lambda: self.move_xyz(-self.interval, 0, 0)) self.btn_y_increase.clicked.connect( lambda: self.move_xyz(0, self.interval, 0)) self.btn_y_reduce.clicked.connect( lambda: self.move_xyz(0, -self.interval, 0)) self.btn_z_increase.clicked.connect( lambda: self.move_xyz(0, 0, self.interval)) self.btn_z_reduce.clicked.connect( lambda: self.move_xyz(0, 0, -self.interval)) self.btn_return.clicked.connect(self.return_ori) self.btn_update_loc.clicked.connect(self.print_location) self.th = Thread(self) self.th.main = self self.th.changePixmap.connect(self.setImage) self.th.addNewObj.connect(self.add_obj) self.th.start() self.stream_label.resize(1280, 720) self.stream_label.move(0, 0) self.btn_save.clicked.connect(self.save_img) self.btn_suck.clicked.connect(self.run_suck) self.btn_free.clicked.connect(self.free) self.agv = threading.Thread(target=self.handleAGV) self.agv.main = self self.agv.start() def cleanScan(self): self.isScanDone = True def add_obj(self, name, objList): _translate = QtCore.QCoreApplication.translate self.objArr = [] j = 0 self.nowItem = [] if objList == []: return for obj in objList: try: self.nowItem.append({"name": name[j], "pos": obj}) except: self.nowItem.append({"name": "不明物", "pos": obj}) #self.objArr[j][2].click.connect(self.get_items) j += 1 self.isScanDone = True def get_items(self, idi): btn_id = idi print("id is " + str(btn_id)) print("click " + str(btn_id)) x = self.nowItem[btn_id]["pos"][0] y = self.nowItem[btn_id]["pos"][1] print("go to " + str(x) + " " + str(y)) ##在這裡做座標轉換 y1 = float(-55 * x / 228 + 204.1228) x1 = float(-5 * y / 19 + 414.4737) ##在上面做座標轉換 self.device.move_to(x1, y1, -20, 0, wait=True) self.run_suck() time.sleep(1) self.device.move_to(260, 0, 100, 0, wait=True) self.free def run_suck(self): self.device.grip(True) def free(self): #self.device.grip(False) self.device.suck(False) def print_location(self): (x, y, z) = self.get_pos() print("location\n") print(x) print(y) print(z) def mousePressEvent(self, event): self.x = event.x() self.y = event.y() # get depth self.depth = self.th.get_depth(self.x, self.y) if self.x <= 1280 and self.y <= 720: #print (x,y) self.label_X.setText(str(self.x)) self.label_Y.setText(str(self.y)) self.update() def save_img(self): global signal signal.sig.emit() @QtCore.pyqtSlot(QtGui.QImage) def setImage(self, image): self.stream_label.setPixmap(QPixmap.fromImage(image)) self.update() def set_inputinterval(self, content): self.interval = float(content) def closeEvent(self, event): self.th.stop() self.streampopup.quit() def single_detect(self): self.th.setFinish() def save_img(self): global signal signal.sig.emit() def switch_point(self, index): try: _translate = QtCore.QCoreApplication.translate self.lineEdit_1.setText( _translate("Form", str(self.user_set_pos[index][0]))) self.lineEdit_2.setText( _translate("Form", str(self.user_set_pos[index][1]))) self.lineEdit_3.setText( _translate("Form", str(self.user_set_pos[index][2]))) self.lineEdit_4.setText( _translate("Form", str(self.user_set_pos[index][3]))) except Exception as e: print(e) def set_time(self, content): try: self.waitTime = float(content) except Exception as e: print("輸入格式錯誤") print(e) def set_x(self, content): try: tmp = self.user_set_pos[self.comboBox.count() - 1] print(tmp) (x, y, z, r) = tmp self.user_set_pos[self.comboBox.count() - 1] = (float(content), y, z, r) print(content) except Exception as e: print("輸入格式錯誤") print(e) def set_y(self, content): try: tmp = self.user_set_pos[self.comboBox.count() - 1] (x, y, z, r) = tmp self.user_set_pos[self.comboBox.count() - 1] = (x, float(content), z, r) except Exception as e: print("輸入格式錯誤") print(e) def set_z(self, content): try: tmp = self.user_set_pos[self.comboBox.count() - 1] (x, y, z, r) = tmp self.user_set_pos[self.comboBox.count() - 1] = (x, y, float(content), r) except Exception as e: print("輸入格式錯誤") print(e) def set_r(self, content): try: tmp = self.user_set_pos[self.comboBox.count() - 1] (x, y, z, r) = tmp self.user_set_pos[self.comboBox.count() - 1] = (x, y, z, float(content)) except Exception as e: print("輸入格式錯誤") print(e) def get_pos(self): _translate = QtCore.QCoreApplication.translate try: (x, y, z, r, j1, j2, j3, j4) = self.device.pose() self.user_set_pos[0] = (x, y, z, r) except Exception as e: (x, y, z) = (0, 0, 0) self.user_set_pos[0] = (0, 0, 0, 0) pos = self.user_set_pos[0] self.X_output.setText(_translate("Form", str(round(pos[0], 5)))) self.X_edit.setText(_translate("Form", str(round(pos[0], 5)))) self.Y_output.setText(_translate("Form", str(round(pos[1], 5)))) self.Y_edit.setText(_translate("Form", str(round(pos[1], 5)))) self.Z_output.setText(_translate("Form", str(round(pos[2], 5)))) self.Z_edit.setText(_translate("Form", str(round(pos[2], 5)))) self.R_output.setText(_translate("Form", str(round(pos[3], 5)))) self.R_edit.setText(_translate("Form", str(round(pos[3], 5)))) return (x, y, z) def action(self): test = [] for i in range(self.comboBox.count()): print(str(self.user_set_pos[i])) (x, y, z, r) = self.user_set_pos[i] try: #call pydobot self.device.move_to(x, y, z, r, wait=True) time.sleep(self.waitTime) self.get_pos() test.append(self.device.pose()) except Exception as e: print("輸入格式錯誤") print("錯誤訊息: " + str(e)) with open('pos.txt', 'w') as f: for item in test: f.write(str(item)) f.write("\n") def handleAGV(self): HOST = '' PORT = 8000 ADDR = (HOST, PORT) self.tcpSerSock = socket(AF_INET, SOCK_STREAM) self.tcpSerSock.bind(ADDR) self.tcpSerSock.listen() print('wating for AGV connection...') test = True waitFish = False while (1): print("done\n") self.tcpCliSock, self.addr = self.tcpSerSock.accept() print('...connected from:', self.addr) BUFSIZE = 1024 data = self.tcpCliSock.recv(BUFSIZE) print(data.decode()) if (data.decode() == "OK"): print("AGV arrive!") self.th.yolo_t.is_always_detect = True try: while (self.isScanDone == False): continue if (len(self.nowItem) == 0): self.tcpCliSock.send(str("no").encode()) self.tcpCliSock.close() self.isScanDone = False time.sleep(4) else: x = self.nowItem[0]["pos"][0] y = self.nowItem[0]["pos"][1] print("go to " + str(x) + " " + str(y)) self.y1 = float(-55 * x / 228 + 204.1228) self.x1 = float(-5 * y / 19 + 414.4737) self.return_ori() print("x is " + str(x)) self.x = int(x) self.y = int(y) self.trans() #time.sleep(4) #self.isScanDone=False #self.th.yolo_t.is_always_detect=True #while(self.isScanDone==False): #continue #x=self.nowItem[0]["pos"][0] #y=self.nowItem[0]["pos"][1] #self.go_to_depth(x,y) self.run_suck() time.sleep(2) self.return_ori() print("AGV get!") self.tcpCliSock.send(str("yes").encode()) print("done\n") self.isScanDone = False self.nowItem = [] time.sleep(4) waitFish = True except Exception as e: self.tcpCliSock.send(str("no").encode()) self.isScanDone = False self.nowItem = [] print("stop during thread pool") print(e) else: print("release") self.free() def _set_user_set_pos(self): try: self.comboBox.addItem("點" + str(self.comboBox.count() + 1)) self.user_set_pos.append((0, 0, 0, 0)) print(str(self.user_set_pos)) except Exception as e: print("輸入格式錯誤") print("錯誤訊息: " + str(e)) def onBindingUi(self): pass def _del_(self): self.tcpSerSock.close() def _set_user_set_pos(self): try: self.comboBox.addItem("點" + str(self.comboBox.count() + 1)) self.user_set_pos.append((0, 0, 0, 0)) print(str(self.user_set_pos)) except Exception as e: print("輸入格式錯誤") print("錯誤訊息: " + str(e)) def move_xyz(self, x_, y_, z_): (x, y, z) = self.get_pos() self.device.move_to(x + x_, y + y_, z + z_, 0.0, wait=True)
def moveToken(sourceSpace, targetSpace, colorToMove, clearing=False): print("moveToken called with: {} {} {}".format(str(sourceSpace), str(targetSpace), str(colorToMove))) global tokensInPlay global playArea # use sourcePosition and targetPosition to lookup the xyz values to call with if not clearing: targetPosition = playArea[str(targetSpace)] sourcePosition = orangeStorage[str( sourceSpace)] if colorToMove == "orange" else blueStorage[str( sourceSpace)] playArea[str(targetSpace)].color = colorToMove tokensInPlay += 1 else: sourcePosition = playArea[str(sourceSpace)] targetPosition = orangeStorage[str( targetSpace)] if colorToMove == "orange" else blueStorage[str( targetSpace)] playArea[str(sourceSpace)].color = "empty" tokensInPlay -= 1 if simulate: print("Would move token color {} from {} to {}.".format( colorToMove.upper(), "({}, {})".format(str(sourcePosition.xPos), str(sourcePosition.yPos)), "({}, {})".format(str(targetPosition.xPos), str(targetPosition.yPos)))) else: port0 = list_ports.comports()[0].device device0 = Dobot(port=port0, verbose=False) (x, y, z, r, j1, j2, j3, j4) = device0.pose() #file.write(datetime.datetime.now()) # posLog("Button1") # posLog(f'{x - x1} {y - y1} {z - z1} {j1} \n') # pick up next orange piece (need to figure out how to find next) (pick up first orange) device0.move_to(bootOffset["x"] + sourcePosition.xPos, bootOffset["y"] + sourcePosition.yPos, bootOffset["z"] + 20, 0, wait=True) device0.move_to(bootOffset["x"] + sourcePosition.xPos, bootOffset["y"] + sourcePosition.yPos, bootOffset["z"] - 1, 0, wait=False) device0.suck(True) device0.move_to(bootOffset["x"] + sourcePosition.xPos, bootOffset["y"] + sourcePosition.yPos, bootOffset["z"] + 20, 0, wait=False) # place piece in grid 1 device0.move_to(bootOffset["x"] + targetPosition.xPos, bootOffset["y"] + targetPosition.yPos, bootOffset["z"] + 20, 0, wait=False) device0.move_to(bootOffset["x"] + targetPosition.xPos, bootOffset["y"] + targetPosition.yPos, bootOffset["z"] - 1, 0, wait=False) device0.suck(False) sleep(0.5) device0.move_to( bootOffset["x"] + targetPosition.xPos, bootOffset["y"] + targetPosition.yPos, bootOffset["z"] + 20, 0, wait=True) # we wait until this movement is done before continuing # go to neutral pose device0.move_to(bootOffset["x"] - 36, bootOffset["y"] - 56, bootOffset["z"] + 20, 0, wait=True)
""" get arm position of picking object using verbose mode. 2018-06-01 msrks """ import time from glob import glob from pydobot import Dobot available_ports = glob('/dev/cu*usb*') device = Dobot(port=available_ports[0], verbose=True) time.sleep(0.5) device.close()
"""@Author: Sameer Kesava""" from google import auth #for authorization import os import time import dialogflow #Google Natural Language Processing API from pydobot import Dobot # Dobot serial_port = input('Enter the serial port connecting the Dobot: ') dobot = Dobot(port=serial_port) # Set the speed of the Dobot speed = 100 dobot.speed(speed) json_file = input('Enter path to the json credentials file: ') #Authorization to login to the project chosen during gcloud init os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = json_file credentials, project = auth.default() #Creating a session using the credentials session_client = dialogflow.SessionsClient(credentials=credentials) session_ID = input('Enter a name for session id: ') #Final step setting up a session session = session_client.session_path(project, session_ID)
# Copyright (c) 2020 Sagar Gubbi. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. from pydobot import Dobot d = Dobot(port='/dev/ttyUSB0', verbose=False) d.wait_for_cmd(d.home()) d.close()
from serial.tools import list_ports from pydobot import Dobot port0 = list_ports.comports()[0].device device = Dobot(port=port0, verbose=True) while 1 < 2: (x, y, z, r, j1, j2, j3, j4) = device.pose() print(f'x:{x} y:{y} z:{z} j1:{j1} j2:{j2} j3:{j3} j4:{j4}') #device.speed(100, 100) #device.move_to(x + 20, y+20, z+20, r-20, wait=False) #device.suck(True) #device.move_to(x, y, z, r, wait=False) # we wait until this movement is done before continuing #device.suck(False) device.close()
from serial.tools import list_ports from pydobot import Dobot port = list_ports.comports()[0].device device = Dobot(port=port, verbose=True) (x, y, z, r, j1, j2, j3, j4) = device.pose() (l) = device.pose_l() device.grip(False) device.move_to_with_l( 228, -65, 20, -17, 0, wait=True) # we wait until this movement is done before continuing device.move_to_with_l( 228, -65, -47, -17, 0, wait=True) # we wait until this movement is done before continuing device.grip(True) device.move_to_with_l( 228, -65, -47, -17, 0, wait=True) # we wait until this movement is done before continuing device.move_to_with_l( 228, -65, 20, -17, 0, wait=True) # we wait until this movement is done before continuing device.move_to_with_l( 228, -65, 40, -17, 211, wait=True) # we wait until this movement is done before continuing device.grip(False) device.suck(False) device.close()
def __init__(self, port): self.device = Dobot(port=port, verbose=True) self.home_x = 200 self.home_y = 0 self.home_z = 135
from serial.tools import list_ports from pydobot import Dobot port = list_ports.comports()[0].device device = Dobot(port=port, verbose=True) device.home() (x, y, z, r, j1, j2, j3, j4) = device.pose() (l) = device.pose_l() device.close()