-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (44 loc) · 1.17 KB
/
main.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
import time
from scrap.util import read_config, wait_till_done, ScrapException, UserInput
from comm.serialcomm import SerialComm
from scrap.scrapinterface import ScrapInterface
conf_dict = read_config("conf.txt")
# create ScrapInterface
scrap = ScrapInterface(conf_dict)
# for now, enter x and y coordinate to go to
# start user input thread
userInput = UserInput()
userInput.start()
while True:
# wait a little
time.sleep(0.05)
# read message; if None, received nothing
user_inp = userInput.returnMessage()
if user_inp == None:
continue
if user_inp.lower().startswith("exit"):
break
else:
try:
doneYet = False
inp = user_inp.strip()
if inp.lower() == 'r':
wait_till_done(scrap.reset())
doneYet = True
if not doneYet:
comm,coords = inp.split()
coords = coords.strip().split(",")
if len(coords) < 2:
raise ValueError("use a comma to seperate coords")
if comm == 's':
wait_till_done(scrap.set_coords(coords))
elif comm == 'sp':
wait_till_done(scrap.set_coords(coords,passive=True))
except ValueError,e:
print str(e)
except ScrapException,e:
print str(e)
else:
print 'done!'
scrap.stop()
time.sleep(0.25)