-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphicstest.py
332 lines (296 loc) · 10.7 KB
/
graphicstest.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
from graphics import *
import time
import serial
import matplotlib.pyplot as plt
from datetime import datetime
import numpy as np
import random
# set up the serial line
ser = serial.Serial('COM4', 9600)
time.sleep(2)
# Read and record the data
data =[] # empty list to store the data
# define Position (x current, y current, x past, y past)
position = [0, 0, 0, 0]
win = GraphWin(width = 2560, height = 1440) # create a window
win.setBackground("black")
win.setCoords(0, 0, 2560, 1440) # set the coordinates of the window; bottom left is (0, 0) and top right is (10, 10)
circle = Circle(Point(1280, 720), 25)
circle.setFill("red")
circle.draw(win)
def readData(position, direction):
b = ser.readline() # read a byte string
string_n = b.decode() # decode byte string into Unicode
string = string_n.rstrip() # remove \n and \r
try:
flt = float(string) # convert string to float
# timeobj = datetime.now().time()
datapoint = np.array([position, direction, flt])
print(datapoint)
data.append(datapoint) # add to the end of data list
except:
None
time.sleep(0.01)
def readDataSaccade(displacement_x, displacement_y):
b = ser.readline() # read a byte string
string_n = b.decode() # decode byte string into Unicode
string = string_n.rstrip() # remove \n and \r
try:
flt = float(string) # convert string to float
# timeobj = datetime.now().time()
datapoint = np.array([displacement_x, displacement_y, flt])
print(datapoint)
data.append(datapoint) # add to the end of data list
except:
None
time.sleep(0.01)
def zoneCreator(x, y):
# Define borderchecks
if (x == 0 or y == 0):
return "border"
if (y > 0):
if (x > 0):
return "topright"
else:
return "topleft"
if (y < 0):
if (x > 0):
return "bottomright"
else:
return "bottomleft"
def directionCreator(x, y, xpast, ypast):
# define directionchecks
if (x > xpast):
if (y == ypast):
return "moveright"
elif (y > ypast):
return "movetopright"
elif (y < ypast):
return "movebottomright"
else:
return "dunno x > xpast"
elif (x < xpast):
if (y == ypast):
return "moveleft"
elif (y > ypast):
return "movetopleft"
elif (y < ypast):
return "movebottomleft"
else:
return "dunno x < xpast"
elif (x == xpast):
if (y == ypast):
return "standstill"
elif (y > ypast):
return "movetop"
elif (y < ypast):
return "movebottom"
else:
return "dunno x == xpast"
else:
return "dunno"
def displacementHelperX(displacement_x = 0):
if displacement_x == 0:
return ("0")
elif displacement_x > 0 and displacement_x <= 640:
return ("10")
elif displacement_x > 640 and displacement_x <= 1280:
return ("20")
elif displacement_x > 1280 and displacement_x <= 2560:
return ("40")
elif displacement_x < 0 and displacement_x >= -640:
return ("-10")
elif displacement_x < -640 and displacement_x >= -1280:
return ("-20")
elif displacement_x < -1280 and displacement_x >= -2560:
return ("-40")
def displacementHelperY(displacement_y = 0):
if displacement_y == 0:
return ("0")
elif displacement_y > 0 and displacement_y <= 360:
return ("5")
elif displacement_y > 360 and displacement_y <= 720:
return ("10")
elif displacement_y > 720 and displacement_y <= 1440:
return ("20")
elif displacement_y < 0 and displacement_y >= -360:
return ("-5")
elif displacement_y < -360 and displacement_y >= -720:
return ("-10")
elif displacement_y < -720 and displacement_y >= -1440:
return ("-20")
def displacementCreator(x, y, xpast, ypast):
displacement_x = abs(x - xpast)
displacement_y = abs(y - ypast)
return (displacementHelperX(displacement_x), displacementHelperY(displacement_y))
def getRandomDisplacement():
x = random.randint(-1280, 1280)
y = random.randint(-720, 720)
return x, y
def step(x, y):
circle.move(x, y)
position[2] = position[0]
position[3] = position[1]
position[0] += x
position[1] += y
def stepBack(x, y):
x = x * -1
y = y * -1
step(x, y)
def renderStandstill(time):
for i in range(time):
step(0,0)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
def renderStandstillSaccade(time):
for i in range(time):
step(0,0)
displacement = displacementCreator(position[0], position[1], position[2], position[3])
readDataSaccade(displacement[0], displacement[1])
def renderStandstillNoMeasurement(time):
for i in range(time):
step(0,0)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
# readData(zone, direction)
def renderPursuitTest():
renderStandstill(1000)
# 0,0
for i in range(640):
step(2,0)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
for i in range(1280):
step(-2,0)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
for i in range(640):
step(2,0)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
for i in range(360):
step(0,2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
for i in range(720):
step(0,-2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
for i in range(360):
step(0,2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
# 0,0
for i in range(360):
step(2, 2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
# (720,720)
for i in range(280):
step(2,-2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
# (1280,160)
for i in range(440):
step(-2,-2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
# (400,-720)
for i in range(720):
step(-2,2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
# (-1040,720)
for i in range(120):
step(-2,-2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
# (-1280, 480)
for i in range(600):
step(2,-2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
# (-80, -720)
for i in range(680):
step(2,2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
# (1280, 640)
for i in range(40):
step(-2,2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
# (1200, 720)
for i in range(720):
step(-2,-2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
# (-240,-720)
for i in range(520):
step(-2,2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
# (-1280, 320)
for i in range(200):
step(2,2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
# (-880, 720)
for i in range(720):
step(2,-2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
# (560, -720)
for i in range(360):
step(2,2)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
# (1280, 0)
for i in range(640):
step(-2,0)
zone = zoneCreator(position[0], position[1])
direction = directionCreator(position [0], position[1], position[2], position[3])
readData(zone, direction)
renderStandstill(1000)
def renderSaccadetest():
renderStandstillSaccade(500)
for i in range(0, 125):
#Saccade
x, y = getRandomDisplacement()
step(x,y)
displacement = displacementCreator(position[0], position[1], position[2], position[3])
#MeasureSaccade
for j in range(0,50):
readDataSaccade(displacement[0], displacement[1])
#Standstill
step(0,0)
displacement = displacementCreator(position[0], position[1], position[2], position[3])
#MeasureStandstill
for j in range (0, 50):
readDataSaccade(displacement[0], displacement[1])
#ResetPosition
stepBack(position[0], position[1])
#renderPursuitTest()
renderSaccadetest()
np.savetxt('testfile.csv', data, delimiter=',', fmt="%s")
# dc.convertWindow(25)