-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript_lidar.py
35 lines (31 loc) · 988 Bytes
/
script_lidar.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
#!/usr/bin/env python3
'''Records scans to a given file in the form of numpy array.
Usage example:
$ ./record_scans.py out.npy'''
import sys
from rplidar import RPLidar
PORT_NAME = '/dev/ttyUSB0' # should be 1 if running with roomba
NUMBER_BEAMS = 19 #for model
def run(path):
'''Main function'''
lidar = RPLidar(PORT_NAME)
outfile = open(path, 'r+')
try:
print('Recording measurments... Press Crl+C to stop.')
for scan in lidar.iter_scans():
count = 0
outfile.seek(0)
outfile.truncate(0)
line = ''
for measurment in scan:
if (count < NUMBER_BEAMS):
line = line + '\t'.join(str(v) for v in measurment)
line = line + '\n'
count = count + 1
outfile.write(line )
except KeyboardInterrupt:
print('Stoping.')
lidar.stop()
lidar.disconnect()
if __name__ == '__main__':
run(sys.argv[1])