Skip to content

Commit aefe065

Browse files
committed
commit message 1
1 parent ec55f55 commit aefe065

File tree

4 files changed

+332
-1
lines changed

4 files changed

+332
-1
lines changed

python.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88

99
/* Begin PBXFileReference section */
1010
0758C2DA1F1C4E4E00A69097 /* samplepy.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = samplepy.py; sourceTree = "<group>"; };
11+
0758C2DB1F1C54B600A69097 /* basic_example.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = basic_example.py; sourceTree = "<group>"; };
12+
0758C2DC1F1C57CF00A69097 /* uArmRobot.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = uArmRobot.py; sourceTree = "<group>"; usesTabs = 0; wrapsLines = 0; };
1113
/* End PBXFileReference section */
1214

1315
/* Begin PBXGroup section */
1416
0758C2CF1F1C4DCB00A69097 = {
1517
isa = PBXGroup;
1618
children = (
19+
0758C2DC1F1C57CF00A69097 /* uArmRobot.py */,
1720
0758C2DA1F1C4E4E00A69097 /* samplepy.py */,
21+
0758C2DB1F1C54B600A69097 /* basic_example.py */,
1822
);
1923
sourceTree = "<group>";
2024
};

python.xcodeproj/xcuserdata/Eric.xcuserdatad/xcschemes/python.xcscheme

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
33
LastUpgradeVersion = "0830"
4-
version = "1.3">
4+
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"
77
buildImplicitDependencies = "YES">
@@ -64,6 +64,10 @@
6464
</CommandLineArguments>
6565
<AdditionalOptions>
6666
</AdditionalOptions>
67+
<LocationScenarioReference
68+
identifier = "com.apple.dt.IDEFoundation.CurrentLocationScenarioIdentifier"
69+
referenceType = "1">
70+
</LocationScenarioReference>
6771
</LaunchAction>
6872
<ProfileAction
6973
buildConfiguration = "Release"

samplepy.py

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,163 @@
11
print "Hello, World!"
2+
3+
# uArm Swift Pro - Python Library
4+
# Created by: Richard Garsthagen - [email protected]
5+
# V0.2 - June 2017 - Still under development
6+
7+
import serial
8+
import time
9+
import protocol_swiftpro as protocol
10+
import threading
11+
import sys
12+
import math
13+
from math import pi
14+
15+
16+
class robot:
17+
serid = 100
18+
num_of_robots = 0
19+
baud = 115200
20+
serial_timeout = 1
21+
connect_timeout = 1
22+
debug = False
23+
baseThreadCount = threading.activeCount()
24+
delay_after_move = 0.1
25+
26+
def __init__(self, serialport):
27+
self.serialport = serialport
28+
self.connected = False
29+
robot.num_of_robots += 1
30+
self.moving = False
31+
self.pumping = False
32+
33+
def connect(self):
34+
try:
35+
if (self.debug): print ("trying to connect to: " + self.serialport)
36+
self.ser = serial.Serial(self.serialport, 115200, timeout=1)
37+
time.sleep(self.connect_timeout)
38+
39+
Ready = False
40+
while (not Ready):
41+
line = self.ser.readline()
42+
if (self.debug): print (line)
43+
if line.startswith("@5"):
44+
Ready = True
45+
self.connected = True
46+
if (self.debug): print ("Connected!")
47+
return True
48+
line = self.ser.readline() # Ignore if @6 response is given
49+
print (line)
50+
51+
except Exception as e:
52+
if (self.debug): print ("Error trying to connect to: " + self.serialport + " - " + str(e))
53+
self.connected = False
54+
return False
55+
56+
def disconnect(self):
57+
if self.connected:
58+
if (self.debug): print ("Closing serial connection")
59+
self.connected = False
60+
self.ser.close()
61+
else:
62+
if (self.debug): print ("Disconnected called while not connected")
63+
64+
def sendcmd(self, cmnd, waitresponse):
65+
if (self.connected):
66+
id = self.serid
67+
self.serid += 1
68+
cmnd = "#{} {}".format(id,cmnd)
69+
cmndString = bytes(cmnd + "\n")
70+
if (self.debug): print ("Serial send: {}".format(cmndString))
71+
self.ser.write(cmndString)
72+
if (waitresponse):
73+
line = self.ser.readline()
74+
while not line.startswith("$" + str(id)):
75+
line = self.ser.readline()
76+
if (self.debug): print ("Response {}".format(line))
77+
if (self.moving):
78+
self.moving = False
79+
time.sleep(self.delay_after_move)
80+
return line
81+
else:
82+
if (self.debug):
83+
print ("error, trying to send command while not connected")
84+
self.moving = False
85+
86+
def goto(self,x,y,z,speed):
87+
self.moving = True
88+
x = str(round(x, 2))
89+
y = str(round(y, 2))
90+
z = str(round(z, 2))
91+
s = str(round(speed, 2))
92+
cmd = protocol.SET_POSITION.format(x,y,z,s)
93+
self.sendcmd(cmd, True)
94+
95+
def async_goto(self,x,y,z, speed):
96+
self.moving = True
97+
t = threading.Thread( target=self.goto , args=(x,y,z,speed) )
98+
t.start()
99+
100+
def pump(self, state):
101+
self.pumping = state
102+
cmd = protocol.SET_PUMP.format(int(state))
103+
self.sendcmd(cmd,True)
104+
105+
def mode(self, modeid):
106+
# 0= Normal
107+
# 1= Laser
108+
# 2= 3D Printer
109+
# 3= Universal holder
110+
cmd = protocol.SET_MODE.format(modeid)
111+
self.sendcmd(cmd,True)
112+
113+
@staticmethod
114+
def PointsInCircum(r,n):
115+
return [(math.cos(2*pi/n*x)*r,math.sin(2*pi/n*x)*r) for x in xrange(0,n+1)]
116+
117+
118+
def drawCircle(self, centerX, centerY, Radius, Resolution, Speed, DrawingHeight, StartFinishedHeight):
119+
if (Resolution < 4):
120+
#ignore drwaing circle, to low resoution
121+
if (self.debug): print ("Ignoring drwaing circle, to low resolution requested")
122+
return
123+
if (self.debug): print ("Drwaing circle of {} radius in {} steps".format(Radius,Resolution))
124+
offsetx = centerX
125+
offsety = centerY
126+
c = self.PointsInCircum(Radius,Resolution)
127+
bx,by = c[0]
128+
self.goto(offsetx+bx,offsety+by,StartFinishedHeight,Speed)
129+
130+
for p in range(0,Resolution):
131+
x,y = c[p]
132+
self.goto(offsetx+x,offsety+y,DrawingHeight,Speed)
133+
134+
self.goto(offsetx+bx,offsety+by,DrawingHeight,Speed)
135+
time.sleep(0.5)
136+
self.goto(offsetx+bx,offsety+by,StartFinishedHeight,Speed)
137+
138+
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
149+
150+
151+
152+
153+
154+
155+
156+
157+
158+
159+
160+
161+
162+
163+

uArmRobot.py

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# uArm Swift Pro - Python Library
2+
# Created by: Richard Garsthagen - [email protected]
3+
# V0.2 - June 2017 - Still under development
4+
5+
import serial
6+
import time
7+
import protocol_swiftpro as protocol
8+
import threading
9+
import sys
10+
import math
11+
from math import pi
12+
13+
14+
class robot:
15+
serid = 100
16+
num_of_robots = 0
17+
baud = 115200
18+
serial_timeout = 1
19+
connect_timeout = 1
20+
debug = False
21+
baseThreadCount = threading.activeCount()
22+
delay_after_move = 0.1
23+
24+
def __init__(self, serialport):
25+
self.serialport = serialport
26+
self.connected = False
27+
robot.num_of_robots += 1
28+
self.moving = False
29+
self.pumping = False
30+
31+
def connect(self):
32+
try:
33+
if (self.debug): print ("trying to connect to: " + self.serialport)
34+
self.ser = serial.Serial(self.serialport, 115200, timeout=1)
35+
time.sleep(self.connect_timeout)
36+
37+
Ready = False
38+
while (not Ready):
39+
line = self.ser.readline()
40+
if (self.debug): print (line)
41+
if line.startswith("@5"):
42+
Ready = True
43+
self.connected = True
44+
if (self.debug): print ("Connected!")
45+
return True
46+
line = self.ser.readline() # Ignore if @6 response is given
47+
print (line)
48+
49+
except Exception as e:
50+
if (self.debug): print ("Error trying to connect to: " + self.serialport + " - " + str(e))
51+
self.connected = False
52+
return False
53+
54+
def disconnect(self):
55+
if self.connected:
56+
if (self.debug): print ("Closing serial connection")
57+
self.connected = False
58+
self.ser.close()
59+
else:
60+
if (self.debug): print ("Disconnected called while not connected")
61+
62+
def sendcmd(self, cmnd, waitresponse):
63+
if (self.connected):
64+
id = self.serid
65+
self.serid += 1
66+
cmnd = "#{} {}".format(id,cmnd)
67+
cmndString = bytes(cmnd + "\n")
68+
if (self.debug): print ("Serial send: {}".format(cmndString))
69+
self.ser.write(cmndString)
70+
if (waitresponse):
71+
line = self.ser.readline()
72+
while not line.startswith("$" + str(id)):
73+
line = self.ser.readline()
74+
if (self.debug): print ("Response {}".format(line))
75+
if (self.moving):
76+
self.moving = False
77+
time.sleep(self.delay_after_move)
78+
return line
79+
else:
80+
if (self.debug):
81+
print ("error, trying to send command while not connected")
82+
self.moving = False
83+
84+
def goto(self,x,y,z,speed):
85+
self.moving = True
86+
x = str(round(x, 2))
87+
y = str(round(y, 2))
88+
z = str(round(z, 2))
89+
s = str(round(speed, 2))
90+
cmd = protocol.SET_POSITION.format(x,y,z,s)
91+
self.sendcmd(cmd, True)
92+
93+
def async_goto(self,x,y,z, speed):
94+
self.moving = True
95+
t = threading.Thread( target=self.goto , args=(x,y,z,speed) )
96+
t.start()
97+
98+
def pump(self, state):
99+
self.pumping = state
100+
cmd = protocol.SET_PUMP.format(int(state))
101+
self.sendcmd(cmd,True)
102+
103+
def mode(self, modeid):
104+
# 0= Normal
105+
# 1= Laser
106+
# 2= 3D Printer
107+
# 3= Universal holder
108+
cmd = protocol.SET_MODE.format(modeid)
109+
self.sendcmd(cmd,True)
110+
111+
@staticmethod
112+
def PointsInCircum(r,n):
113+
return [(math.cos(2*pi/n*x)*r,math.sin(2*pi/n*x)*r) for x in xrange(0,n+1)]
114+
115+
116+
def drawCircle(self, centerX, centerY, Radius, Resolution, Speed, DrawingHeight, StartFinishedHeight):
117+
if (Resolution < 4):
118+
#ignore drwaing circle, to low resoution
119+
if (self.debug): print ("Ignoring drwaing circle, to low resolution requested")
120+
return
121+
if (self.debug): print ("Drwaing circle of {} radius in {} steps".format(Radius,Resolution))
122+
offsetx = centerX
123+
offsety = centerY
124+
c = self.PointsInCircum(Radius,Resolution)
125+
bx,by = c[0]
126+
self.goto(offsetx+bx,offsety+by,StartFinishedHeight,Speed)
127+
128+
for p in range(0,Resolution):
129+
x,y = c[p]
130+
self.goto(offsetx+x,offsety+y,DrawingHeight,Speed)
131+
132+
self.goto(offsetx+bx,offsety+by,DrawingHeight,Speed)
133+
time.sleep(0.5)
134+
self.goto(offsetx+bx,offsety+by,StartFinishedHeight,Speed)
135+
136+
137+
138+
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
149+
150+
151+
152+
153+
154+
155+
156+
157+
158+
159+
160+
161+

0 commit comments

Comments
 (0)