Tidy up some lidar stuff for testing and clarity.

This commit is contained in:
Piv
2020-03-09 23:02:19 +10:30
parent ef83365fd8
commit 50d8923ad0
5 changed files with 85 additions and 28 deletions

View File

@@ -1,5 +1,3 @@
import rplidar
from rplidar import RPLidar
from threading import Thread
from tracking import algorithms
import tracking.lidar_tracker_pb2 as tracker_pb
@@ -8,14 +6,14 @@ import Messaging.messages as messages
class LidarCache():
'''
"""
A class that retrieves scans from the lidar,
runs grouping algorithms between scans and
keeps a copy of the group data.
'''
"""
def __init__(self, measurements=100):
self.lidar = RPLidar('/dev/ttyUSB0')
def __init__(self, lidar, measurements=100):
self.lidar = lidar
self.measurements = measurements
print('Info: ' + self.lidar.get_info())
print('Health: ' + self.lidar.get_health())
@@ -29,14 +27,19 @@ class LidarCache():
self.thread.start()
def do_scanning(self, sender):
'''
Performs a scan for the given number of iterations.
'''
"""Performs scans whilst cache is running, and will pass calculated groups data to the sender.
Parameters
----------
sender:
Any class given in messaging.message_factory. This acts as a listener.
"""
# Create the 0MQ socket first. This should not be passed between threads.
self._mFactory = sender
for i, scan in enumerate(self.lidar.iter_scans(min_len=self.measurements)):
print('%d: Got %d measurments' % (i, len(scan)))
for scan in self.lidar.iter_scans(min_len=self.measurements):
print('Got %d measurments' % (len(scan)))
if(not self.run):
break