forked from anshuln/ITSP-2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main_Laptop.py
58 lines (54 loc) · 1.66 KB
/
Main_Laptop.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
import serial
import Sliding_Windows as SWL
import pyautogui
import os
ser = serial.Serial('COM4',9600,timeout=None)
dictionary = {b'1':'crocin', b'2':'digene', b'3':'flagyl', b'4':'norflox', b'5':'wikoryl'}
size=[1687,1362] #Hardcoded in SLW, change if changed here
steps_x = 1700 #no. of steps the CNC moves over a complete traversal
steps_y = 1500
def capture():
'''
Basically switches the window to capture a photograph of the table
'''
pyautogui.hotkey('alt', 'tab')
pyautogui.PAUSE=2.5
pyautogui.click(x=722,y=481)
pyautogui.PAUSE=7
pyautogui.click(x=910,y=754)
pyautogui.PAUSE=3
pyautogui.click(x=1344,y=297)
def get_string_from_coords(coords):
x = int((coords[0][0]/size[0])*steps_x)
y = int((coords[0][1]/size[1])*steps_y)
str = 'r'*(x+40) + 'u'*y + 'p' + 'l'*(x+40) + 'd'*y + 'x'
return str
def getName():
#name = dictionary[ser.read()]
print("Awaiting Input...")
while(ser.in_waiting == 0):
pass
inString = ser.read(1)
print("Input received")
return dictionary[inString]
def moveMotors(dir):
i = 0
for i in range(0, len(dir)):
ser.write(dir[i].encode()) #the string is passed one character at a time since Arduino serial buffer is only 64 bytes long
print("Waiting for response from Arduino...")
while (ser.in_waiting == 0):
pass
print("Arduino's response: ", ser.read(1))
if __name__ == "__main__":
print("Give Input")
name=getName()
print("Capturing Image...")
#capture()
path='Picture 17.jpg' #Fix path here
print("Extracting coordinates")
coords = SWL.main(path,name)
print(coords)
# os.remove(path)
dir = get_string_from_coords(coords)
print("Moving Arm")
moveMotors(dir)