From 7fb69e52195a8d085f363ec01f831279c1920bbb Mon Sep 17 00:00:00 2001 From: jfdzar Date: Sat, 26 Aug 2017 17:00:58 +0200 Subject: [PATCH 1/5] Solve problems from line.startwith on robot class Added method to move with laser on Added method to set acceleration --- basic_example.py | 148 +++++++++++++++++++++++++++++-------------- protocol_swiftpro.py | 2 + uArmRobot.py | 30 +++++++-- 3 files changed, 127 insertions(+), 53 deletions(-) diff --git a/basic_example.py b/basic_example.py index dc46354..6ff0abe 100644 --- a/basic_example.py +++ b/basic_example.py @@ -1,49 +1,99 @@ -# uArm Swift Pro - Python Library Example -# Created by: Richard Garsthagen - the.anykey@gmail.com -# V0.1 - June 2017 - Still under development - -import uArmRobot -import time - -#Configure Serial Port -serialport = "com3" # for windows -#serialport = "/dev/ttyACM0" # for linux like system - -# Connect to uArm -myRobot = uArmRobot.robot(serialport) -myRobot.debug = False # Enable / Disable debug output on screen, by default disabled -myRobot.connect() -myRobot.mode(0) # Set mode to Normal - -time.sleep(1) - -# Move robot, command will complete when motion is completed -myRobot.goto(200,0,100,6000) - -# Turn on the pump -myRobot.pump(True) - -# Send move command, but continue program -myRobot.async_goto(200,150,250,3000) -while myRobot.moving: - print ("Waiting to complete move") - time.sleep(0.5) - -#Turn off the pump -myRobot.pump(False) - -# Send move command, but continue program -myRobot.async_goto(200,0,100,6000) -while myRobot.moving: - print ("Waiting to complete move") - time.sleep(0.5) - - -time.sleep(5) - -#Disconnect serial connection -myRobot.disconnect() - - - - +# uArm Swift Pro - Python Library Example +# Created by: Richard Garsthagen - the.anykey@gmail.com +# V0.1 - June 2017 - Still under development + +import uArmRobot +import time +import serial + +#Configure Serial Port +serialport = 'COM7' # for windows +#serialport = "/dev/ttyACM0" # for linux like system + +# Connect to uArm +myRobot = uArmRobot.robot(serialport) +myRobot.debug = True # Enable / Disable debug output on screen, by default disabled +myRobot.connect() +myRobot.mode(0) # Set mode to Normal + +time.sleep(1) +myRobot.get_position() + + + +myRobot.mode(1) +time.sleep(2) + + +myRobot.set_acceleration(300,300) +myRobot.goto(200,0,100,30000) +myRobot.goto(200,150,100,30000) +myRobot.goto(200,-150,100,30000) + +myRobot.set_acceleration(200,200) +myRobot.goto(200,150,100,5000) +myRobot.goto(200,-150,100,5000) +myRobot.goto(200,0,100,5000) + + +myRobot.mode(0) +myRobot.goto(100,0,40,5000) + +time.sleep(5) + +print('Disconnecting Robot') +myRobot.disconnect() + +exit() +z = 100 +speed = 50000 +for i in range(1,7): + myRobot.laser_goto(200,0,z,speed) + myRobot.laser_goto(200,50,z,speed) + myRobot.laser_goto(210,50,z,speed) + myRobot.laser_goto(210,0,z,speed) + +z = 120 +for i in range(1,7): + myRobot.laser_goto(200,0,z,speed) + myRobot.laser_goto(200,50,z,speed) + myRobot.laser_goto(210,50,z,speed) + myRobot.laser_goto(210,0,z,speed) + +myRobot.mode(0) +myRobot.goto(100,0,40,5000) + +time.sleep(5) + +print('Disconnecting Robot') +myRobot.disconnect() + +exit() + +# Turn on the pump +myRobot.pump(True) + +# Send move command, but continue program +myRobot.async_goto(200,150,250,3000) +while myRobot.moving: + print ("Waiting to complete move") + time.sleep(0.5) + +#Turn off the pump +myRobot.pump(False) + +# Send move command, but continue program +myRobot.async_goto(200,0,100,6000) +while myRobot.moving: + print ("Waiting to complete move") + time.sleep(0.5) + + +time.sleep(5) + +#Disconnect serial connection +myRobot.disconnect() + + + + diff --git a/protocol_swiftpro.py b/protocol_swiftpro.py index 9f9ab81..567c912 100644 --- a/protocol_swiftpro.py +++ b/protocol_swiftpro.py @@ -7,12 +7,14 @@ READY = "@1" OK = "OK" SET_POSITION = "G0 X{} Y{} Z{} F{}" +SET_POSITION_LASER = "G1 X{} Y{} Z{} F{}" SET_POSITION_RELATIVE = "G2204 X{} Y{} Z{} F{}" SIMULATION = "M2222 X{} Y{} Z{} P0" GET_FIRMWARE_VERSION = "P2203" GET_HARDWARE_VERSION = "P2202" SET_ANGLE = "G2202 N{} V{}" SET_MODE = "M2400 S{}" +SET_ACCELERATION = "M204 P{} T{}" # SET_RAW_ANGLE = "sSerN{}V{}" STOP_MOVING = "G2203" diff --git a/uArmRobot.py b/uArmRobot.py index a17cb61..a115885 100644 --- a/uArmRobot.py +++ b/uArmRobot.py @@ -28,7 +28,7 @@ def __init__(self, serialport): self.moving = False self.pumping = False - def connect(self): + def connect(self): try: if (self.debug): print ("trying to connect to: " + self.serialport) self.ser = serial.Serial(self.serialport, 115200, timeout=1) @@ -38,7 +38,7 @@ def connect(self): while (not Ready): line = self.ser.readline() if (self.debug): print (line) - if line.startswith("@5"): + if str(line)[2:4] == '@5': Ready = True self.connected = True if (self.debug): print ("Connected!") @@ -64,12 +64,12 @@ def sendcmd(self, cmnd, waitresponse): id = self.serid self.serid += 1 cmnd = "#{} {}".format(id,cmnd) - cmndString = bytes(cmnd + "\n") + cmndString = bytes(cmnd + "\n",'ascii') if (self.debug): print ("Serial send: {}".format(cmndString)) self.ser.write(cmndString) if (waitresponse): line = self.ser.readline() - while not line.startswith("$" + str(id)): + while not str(line)[2:3+len(str(id))] == "$" + str(id): line = self.ser.readline() if (self.debug): print ("Response {}".format(line)) if (self.moving): @@ -89,6 +89,21 @@ def goto(self,x,y,z,speed): s = str(round(speed, 2)) cmd = protocol.SET_POSITION.format(x,y,z,s) self.sendcmd(cmd, True) + + def laser_goto(self,x,y,z,speed): + self.moving = True + x = str(round(x, 2)) + y = str(round(y, 2)) + z = str(round(z, 2)) + s = str(round(speed, 2)) + cmd = protocol.SET_POSITION_LASER.format(x,y,z,s) + self.sendcmd(cmd, True) + cmd = protocol.SET_POSITION.format(x,y,z,s) + self.sendcmd(cmd, True) + + def get_position(self): + cmd = protocol.GET_COOR + self.sendcmd(cmd, True) def async_goto(self,x,y,z, speed): self.moving = True @@ -108,6 +123,13 @@ def mode(self, modeid): cmd = protocol.SET_MODE.format(modeid) self.sendcmd(cmd,True) + def set_acceleration(self,p,t): + self.moving = True + p = str(round(p, 0)) + t = str(round(t, 0)) + cmd = protocol.SET_ACCELERATION.format(p,t) + self.sendcmd(cmd, True) + @staticmethod def PointsInCircum(r,n): return [(math.cos(2*pi/n*x)*r,math.sin(2*pi/n*x)*r) for x in xrange(0,n+1)] From cb27664318befa5727792865fef9f5098581b7f3 Mon Sep 17 00:00:00 2001 From: jfdzar Date: Sat, 26 Aug 2017 17:21:05 +0200 Subject: [PATCH 2/5] Change basic_example with new functions get_position method in class robot modified return the coordinates as an array --- basic_example.py | 79 ++++++++++++------------------------------------ uArmRobot.py | 6 +++- 2 files changed, 24 insertions(+), 61 deletions(-) diff --git a/basic_example.py b/basic_example.py index 6ff0abe..358538f 100644 --- a/basic_example.py +++ b/basic_example.py @@ -1,5 +1,6 @@ # uArm Swift Pro - Python Library Example # Created by: Richard Garsthagen - the.anykey@gmail.com +# Modified by: jfdzar # V0.1 - June 2017 - Still under development import uArmRobot @@ -12,66 +13,37 @@ # Connect to uArm myRobot = uArmRobot.robot(serialport) -myRobot.debug = True # Enable / Disable debug output on screen, by default disabled +myRobot.debug = False # Enable / Disable debug output on screen, by default disabled myRobot.connect() -myRobot.mode(0) # Set mode to Normal -time.sleep(1) -myRobot.get_position() +# Set mode to Normal +myRobot.mode(0) +# Get actual Position +print(myRobot.get_position()) - -myRobot.mode(1) -time.sleep(2) - - -myRobot.set_acceleration(300,300) +#Go to Test Position myRobot.goto(200,0,100,30000) +#Change the acceleration and move to test acceleartion +myRobot.set_acceleration(300,300) myRobot.goto(200,150,100,30000) myRobot.goto(200,-150,100,30000) - +#Change the acceleration and move to test acceleartion myRobot.set_acceleration(200,200) myRobot.goto(200,150,100,5000) myRobot.goto(200,-150,100,5000) myRobot.goto(200,0,100,5000) - -myRobot.mode(0) -myRobot.goto(100,0,40,5000) - -time.sleep(5) - -print('Disconnecting Robot') -myRobot.disconnect() - -exit() +#Print Test +myRobot.mode(1) z = 100 -speed = 50000 -for i in range(1,7): - myRobot.laser_goto(200,0,z,speed) - myRobot.laser_goto(200,50,z,speed) - myRobot.laser_goto(210,50,z,speed) - myRobot.laser_goto(210,0,z,speed) - -z = 120 -for i in range(1,7): +speed = 5000 +for i in range(1,4): myRobot.laser_goto(200,0,z,speed) myRobot.laser_goto(200,50,z,speed) myRobot.laser_goto(210,50,z,speed) myRobot.laser_goto(210,0,z,speed) - myRobot.mode(0) -myRobot.goto(100,0,40,5000) - -time.sleep(5) - -print('Disconnecting Robot') -myRobot.disconnect() - -exit() - -# Turn on the pump -myRobot.pump(True) # Send move command, but continue program myRobot.async_goto(200,150,250,3000) @@ -79,21 +51,8 @@ print ("Waiting to complete move") time.sleep(0.5) -#Turn off the pump -myRobot.pump(False) - -# Send move command, but continue program -myRobot.async_goto(200,0,100,6000) -while myRobot.moving: - print ("Waiting to complete move") - time.sleep(0.5) - - -time.sleep(5) - -#Disconnect serial connection -myRobot.disconnect() - - - - +#Set Normal Mode go to Home Position and disconnect the robot +myRobot.mode(0) +myRobot.goto(100,0,40,5000) +print('Disconnecting Robot') +myRobot.disconnect() \ No newline at end of file diff --git a/uArmRobot.py b/uArmRobot.py index a115885..4300d67 100644 --- a/uArmRobot.py +++ b/uArmRobot.py @@ -103,7 +103,11 @@ def laser_goto(self,x,y,z,speed): def get_position(self): cmd = protocol.GET_COOR - self.sendcmd(cmd, True) + line = self.sendcmd(cmd, True) + x = float(str(line).split(' ')[2][1:]) + y = float(str(line).split(' ')[3][1:]) + z = float(str(line).split(' ')[4][1:-5]) + return [x,y,z] def async_goto(self,x,y,z, speed): self.moving = True From b1b1ca120d398d8e77ba1a4079584505345709e4 Mon Sep 17 00:00:00 2001 From: jfdzar Date: Sun, 27 Aug 2017 22:04:29 +0200 Subject: [PATCH 3/5] New folder with different svg drawings svg_example modified parameters and add repetitions --- svg_example.py | 55 ++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/svg_example.py b/svg_example.py index d0c343a..763c8f7 100644 --- a/svg_example.py +++ b/svg_example.py @@ -1,6 +1,8 @@ # Example made by OssiLehtinen +# Modified by jfdzar +# Change the parameters and add more repetitions to cut deeper +# Tested with Adobe Ilustrator vector files Objekt -> Pfad -> Kontourlinien # - from svgpathtools import svg2paths, wsvg import numpy as np @@ -9,24 +11,23 @@ #Configure Serial Port -#serialport = "com3" # for windows -serialport = "/dev/ttyACM0" # for linux like system +serialport = "COM7" # for windows # Connect to uArm myRobot = uArmRobot.robot(serialport) -myRobot.debug = True # Enable / Disable debug output on screen, by default disabled +myRobot.debug = False # Enable / Disable debug output on screen, by default disabled myRobot.connect() myRobot.mode(1) # Set mode to Normal # Read in the svg -paths, attributes = svg2paths('drawing.svg') +paths, attributes = svg2paths('svg_drawings\\circle.svg') scale = .25 -steps_per_seg = 3 +steps_per_seg = 10 coords = [] x_offset = 200 -height = 90 -draw_speed = 1000 +height = 150 +draw_speed = 500 # Convert the paths to a list of coordinates for i in range(len(paths)): @@ -44,23 +45,28 @@ -# The starting point -myRobot.goto(coords[0][0][0], coords[0][0][1], height, 6000) - - -for seg in coords: - myRobot.goto(seg[0][0], seg[0][1], height, 6000) - time.sleep(0.15) - for p in seg: - myRobot.goto_laser(p[0], p[1], height, draw_speed) - - - -# Back to the starting point (and turn the laser off) -myRobot.goto(coords[0][0][0], coords[0][0][1], height, 6000) - +for repetition in range(1,2): + print('Repetition: ',repetition) + # The starting point + myRobot.goto(coords[0][0][0], coords[0][0][1], height, 6000) + for seg in coords: + myRobot.goto(seg[0][0], seg[0][1], height, 6000) + time.sleep(0.15) + for p in seg: + myRobot.laser_goto(p[0], p[1], height, draw_speed) + # Back to the starting point (and turn the laser off) + myRobot.goto(coords[0][0][0], coords[0][0][1], height, 6000) + + +#Set Normal Mode go to Home Position and disconnect the robot +myRobot.mode(0) +myRobot.goto(225, 0, 150, 6000) +myRobot.goto(130, 0, 90, 6000) +myRobot.goto(97, 0, 30, 6000) +print('Disconnecting Robot') +myRobot.disconnect() +""" I used Inkscape to produce some test-files and everything seemed to work fine. One thing to do, is convert text to paths in Inkscape before saving. - Surely not an issue-free solution, but perhaps a starting point for something more advanced. One noticeable thing is that drawing the line segments is a bit stuttery, not sure how to improve this. Cheers, @@ -173,3 +179,4 @@ # Back to the starting point (and turn the laser off) myRobot.goto(coords[0][0][0], coords[0][0][1], height+move_lift*2, 6000) +""" \ No newline at end of file From 36910574f15c5fa643df226d3c73d3b86464ceb6 Mon Sep 17 00:00:00 2001 From: jfdzar Date: Sun, 27 Aug 2017 22:05:34 +0200 Subject: [PATCH 4/5] svg_drawings added --- svg_drawings/bird.svg | 24 +++++++++++++++++++ svg_drawings/bird1.svg | 24 +++++++++++++++++++ svg_drawings/circle.svg | 28 ++++++++++++++++++++++ svg_drawings/cuadrados.svg | 38 +++++++++++++++++++++++++++++ svg_drawings/estrella.svg | 29 ++++++++++++++++++++++ svg_drawings/test.svg | 8 +++++++ svg_drawings/text.svg | 49 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 200 insertions(+) create mode 100644 svg_drawings/bird.svg create mode 100644 svg_drawings/bird1.svg create mode 100644 svg_drawings/circle.svg create mode 100644 svg_drawings/cuadrados.svg create mode 100644 svg_drawings/estrella.svg create mode 100644 svg_drawings/test.svg create mode 100644 svg_drawings/text.svg diff --git a/svg_drawings/bird.svg b/svg_drawings/bird.svg new file mode 100644 index 0000000..88cd71f --- /dev/null +++ b/svg_drawings/bird.svg @@ -0,0 +1,24 @@ + + + + + + + + + + diff --git a/svg_drawings/bird1.svg b/svg_drawings/bird1.svg new file mode 100644 index 0000000..7776165 --- /dev/null +++ b/svg_drawings/bird1.svg @@ -0,0 +1,24 @@ + + + + + + + + + + diff --git a/svg_drawings/circle.svg b/svg_drawings/circle.svg new file mode 100644 index 0000000..879864c --- /dev/null +++ b/svg_drawings/circle.svg @@ -0,0 +1,28 @@ + + + + + + + + + + +]> + + + + + + + + + + + + diff --git a/svg_drawings/cuadrados.svg b/svg_drawings/cuadrados.svg new file mode 100644 index 0000000..a026ceb --- /dev/null +++ b/svg_drawings/cuadrados.svg @@ -0,0 +1,38 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/svg_drawings/estrella.svg b/svg_drawings/estrella.svg new file mode 100644 index 0000000..c39a352 --- /dev/null +++ b/svg_drawings/estrella.svg @@ -0,0 +1,29 @@ + + + + + + + + + + +]> + + + + + + + + + + + + diff --git a/svg_drawings/test.svg b/svg_drawings/test.svg new file mode 100644 index 0000000..4485807 --- /dev/null +++ b/svg_drawings/test.svg @@ -0,0 +1,8 @@ + + + + + + + diff --git a/svg_drawings/text.svg b/svg_drawings/text.svg new file mode 100644 index 0000000..f4b91d5 --- /dev/null +++ b/svg_drawings/text.svg @@ -0,0 +1,49 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + From 34c72f149383b95b132578a10d4b37c46fe389c1 Mon Sep 17 00:00:00 2001 From: jfdzar Date: Sun, 27 Aug 2017 22:11:33 +0200 Subject: [PATCH 5/5] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index a1f7da8..3ed5fa9 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,8 @@ Supports: - Drawing a circle More to follow :-) + +Note svg_example.py +In order to create svg files with paths in Adobe Ilustrator +Objekt -> Pfad -> Kontourlinien +With text, select the text and Ctrl+Shift+O