-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp.py
130 lines (98 loc) · 3.69 KB
/
temp.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
122
123
124
125
126
127
128
129
130
import serial
import serial.tools.list_ports
import time
#List writing.
from datetime import datetime
import csv
actual_path = [[1,1,1,1],[2,1,2,2],[3,1,3,4]]
target_path = [[2,2,2,3],[4,1,4,1],[4,1,6,4]]
cur_date = datetime.now()
cur_date = cur_date.timetuple()
folder_name = "test_results/"
test_name = "adapting"
test_time = "-{}-{}:{}.csv".format(cur_date[2],cur_date[3],cur_date[4])
file_name = folder_name + test_name + test_time
with open(file_name, 'w') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=' ',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
for i in range(len(actual_path)):
spamwriter.writerow([str(actual_path[i]), str(target_path[i])])
#List reading.
actual_list = []
target_list = []
with open(file_name, 'r') as csvfile:
spamwriter = csv.reader(csvfile, delimiter=' ',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
for row in spamwriter:
actual = row[0]
target = row[1]
actual = actual.translate({ord(i):None for i in '[] '}).split(',') #[1,1,1,1]
target = target.translate({ord(i):None for i in '[] '}).split(',')
actual_list.append([int(x) for x in actual])
target_list.append([int(x) for x in target])
print(actual_list)
print(target_list)
# print([comport.device for comport in serial.tools.list_ports.comports()])
# ser1 = serial.Serial(str(serial.tools.list_ports.comports()[0]).split()[0], 9600, timeout = 0.01)
# print(str(serial.tools.list_ports.comports()[0]))
# #Convert int to the string format. (Round the val to a speed btwn -255-255. Add leading zeros)
# #str(1).zfill(2)
# time.sleep(3)
# #get_feedback (put into get_feedback function)
# for i in range(100):
# print("loop" + str(i))
# prevtime = time.time()
# ser1.write("1111\n".encode())
# #get_feedback; allow tiny amount of time for arduino to respond
# time.sleep(0.005)
# vals = ser1.readline().decode("utf-8")
# print("r: " + ser1.readline().decode("utf-8"))
# if vals != '': #or else you'll mess up the state machine
# ser1.write("00000000\n".encode())
# # print(str(serial.tools.list_ports.comports()[0]).split()[0])
# print(time.time()-prevtime)
# time.sleep(0.095)
# def read_serial(): Requires thread; not worth.
# buffer_string = ''
# while True:
# # buffer_string = buffer_string + ser.read(ser.inWaiting())
# buffer_string = buffer_string + ser.readline()
# if '\n' in buffer_string:
# lines = buffer_string.split('\n') # Guaranteed to have at least 2 entries
# last_received = lines[-2]
# #If the Arduino sends lots of empty lines, you'll lose the
# #last filled line, so you could make the above statement conditional
# #like so: if lines[-2]: last_received = lines[-2]
# buffer_string = lines[-1]
# break
# print(buffer_string)
# while(True):
# prevtime = time.time()
# # ser1.read(20)
# print(ser1.readline())
# print("dt = " + str(time.time()-prevtime))
# # while True:
# # feedback = ser1.readline()
# # print(type(feedback))
# # print(feedback)
# # ser1.write('Python') #why is this repeating??
# #Current communication method takes 50 ms
# direction = 1;
# #Communication experiment:
# while True:
# for i in range(255):
# # i = i*10
# start_time = time.time()
# ser1.write(str(i*direction).encode());
# feedback = ser1.readline()
# print(feedback)
# end_time = time.time()
# print("TIME ELAPSED: " + str(end_time-start_time))
# # delay(0.01)
# direction = direction*-1
# # for i in range(100, -1):
# # ser1.write(str(i*direction).encode());
# # feedback = ser1.readline()
# # print(feedback)
# # direction = direction*-1
# ser1.write("00000000\n".encode())