-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharudino.py
121 lines (110 loc) · 3.79 KB
/
arudino.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import time
import warnings
import serial
import serial.tools.list_ports
class MotorMove(object):
def __init__(self, parent=None):
ser_ports = [
p.device
for p in serial.tools.list_ports.comports()
if 'Arduino' in p.description
]
if not ser_ports:
raise IOError("No ser found")
if len(ser_ports) > 1:
warnings.warn('Multiple sers found - using the first')
print ser_ports[0]
self.ser = serial.Serial(ser_ports[0], 9600)
time.sleep(5)
if self.ser is None:
print 'Device not found'
def _set_initial_position(self):
print 'Moving to initial position...'
self.ser.write('M0,0')
motorStatus = 0
while motorStatus == 0:
status = self.ser.readline()
print status
if status[0] == 'D':
motorStatus = 1
print 'Read to take measurement...'
self.currentWell = '1_12'
time.sleep(1)
def _get_current_position(self):
self.ser.write('X')
positionX = int(self.ser.readline())
self.ser.write('Y')
positionY = int(self.ser.readline())
return positionX, positionY
def _convert_labels_to_numericals(self, toRead):
well_letters = ['A','B','C','D','E','F','G','H']
toReadNum = []
for well in toRead:
wellRow = well[0]
wellCol = int(well[1:len(well)])
for index in range(0,len(well_letters)):
if wellRow == well_letters[index]:
toReadNum.append(str(index+1)+'_'+ str(wellCol))
return toReadNum
def _set_new_position(self,well):
y_done = 0
x_done = 0
wellDistanceY = 64
wellDistanceX = 94
currentRow = int(self.currentWell.split('_')[0])
currentCol = int(self.currentWell.split('_')[1])
newRow = int(well.split('_')[0])
print 'newRow: ', newRow
newCol = int(well.split('_')[1])
rowsToMove = int(newRow-currentRow)
colsToMove = int(newCol-currentCol)
currentX, currentY = self._get_current_position()
if rowsToMove < 0:
newY = currentY-(abs(rowsToMove*wellDistanceY))
y_done = 1
elif rowsToMove > 0:
newY = currentY + (abs(rowsToMove*wellDistanceY))
y_done = 1
else:
newY = currentY
y_done = 1
if colsToMove < 0:
newX = currentX-(abs(colsToMove*wellDistanceX))
x_done = 1
elif colsToMove > 0:
newX = currentX + (abs(colsToMove*wellDistanceX))
x_done = 1
else:
newX = currentX
x_done = 1
if x_done == 1 & y_done == 1:
newPosition = 'M'+str(abs(newX))+','+str(newY)
return newPosition
def _move_to_new_position(self,well):
motorStatus = 0
newPosition = self._set_new_position(well)
print newPosition
self.currentWell = well
self.ser.write(newPosition)
while motorStatus == 0:
status = self.ser.readline()
if status[0] == 'D':
time.sleep(1)
#Take Camera Reading
motorStatus = 1
return motorStatus
def _set_led_in_position(self,color):
self.ser.write('S'+color)
def _toggle_led(self,color):
self.ser.write('L'+color)
time.sleep(1)
#m = MotorMove()
#m._set_initial_position()
#m._get_current_position()
#toReadNum = m._convert_labels_to_numericals(['B10','C12'])
##print toReadNum
##m._move_to_new_position(toReadNum)
##m.ser.close() #NECESSARY TO MAINTAIN PROPER POTENTIOMETER VALUE CONVENTION
#toRead = ['A12']
#toReadNum = m._convert_labels_to_numericals(toRead)
#m._move_to_new_position(toReadNum)