-
Notifications
You must be signed in to change notification settings - Fork 0
/
Robot.py
37 lines (29 loc) · 882 Bytes
/
Robot.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
# Sends instructions to robot via serial port
import serial as serial_module
from time import sleep
# Input filename for file with coordinate set
input = raw_input("Filename: ")
# Open coordinate file
try:
with open(input, "r") as fo:
file = fo.read().split("\n")
fo.close()
except IOError:
raise ValueError("File could not be opened")
# Serial interface with robot
serial = serial_module.Serial("/dev/cu.HB-01-DevB", 9600, timeout=2)
print("Connected to: " + serial.portstr)
# this will store the line
line = []
# Send all coordinates in file
for i, x in enumerate(file):
if x != "":
serial.write(x + "#")
read = serial.read()
print x
if i != len(file) - 1:
while read.find("%") == -1:
#if read != "":
#print read
read = serial.read()
# serial.close()