-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
81 lines (62 loc) · 1.75 KB
/
Copy pathtest.py
File metadata and controls
81 lines (62 loc) · 1.75 KB
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
#!/usr/bin/env python3
'''Records measurments to a given file. Usage example:
$ ./record_measurments.py out.txt'''
import sys
from rplidar import RPLidar
PORT_NAME = '/dev/ttyUSB0'
class Reading (object) :
def __init__ (self, angle, distance) :
self.angle = angle
self.distance = distance
def __lt__ (self, other) :
return self.angle < other.angle
def get_distances():
distances = []
reading = False
try:
for measurement in lidar.iter_measurments() :
if measurement[0] :
reading = True
if reading :
reading = not measurement[0]
a = measurement[2]
d = measurement[3]
read = Reading(a, d)
distances.append(read)
else :
lidar.stop()
break
gottenTrue = False
toggle = 0
try:
for measurement in lidar.iter_measurments() :
if (measurement[0]):
gottenTrue = not gottenTrue
toggle += 1
if (gottenTrue):
a = measurement[2]
d = measurement[3]
read = Reading(a, d)
distances.append(read)
if (toggle == 2):
break
except:
pass
distances.sort()
return distances
def run():
'''Main function'''
lidar = RPLidar(PORT_NAME)
# outfile = open(path, 'w')
while True:
try:
for measurment in lidar.iter_measurments():
line = '\t'.join(str(v) for v in measurment)
# outfile.write(line + '\n')
except:
pass
lidar.stop()
lidar.disconnect()
# outfile.close()
if __name__ == '__main__':
run()