Use change listener rather than direct message factory for lidar.

This commit is contained in:
michaelpivato
2020-03-30 12:32:31 +10:30
parent 3fd6830f6b
commit 685f2ad35b
2 changed files with 18 additions and 9 deletions

View File

@@ -2,7 +2,6 @@ from threading import Thread
from tracking import algorithms
import tracking.lidar_tracker_pb2 as tracker_pb
import zmq
import messaging.messages as messages
class LidarCache():
@@ -25,17 +24,17 @@ class LidarCache():
self.thread = Thread(target=self.do_scanning, args=[sender])
self.thread.start()
def do_scanning(self, sender):
def do_scanning(self, listener):
"""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.
listener:
Any object that includes the onGroupsChanged method.
"""
# Create the 0MQ socket first. This should not be passed between threads.
self._mFactory = sender
self._mFactory = listener
# Batch over scans, so we don't need to do our own batching to determine groups
# TODO: Implement custom batching, as iter_scans can be unreliable
@@ -66,8 +65,7 @@ class LidarCache():
pointScan.points.append(tracker_pb.Point(
angle=point[1], distance=point[2], group_number=group.number))
self._mFactory.send_message_topic(
"lidar_map", messages.ProtoMessage(message=pointScan.SerializeToString()))
self._mFactory.onGroupsChanged(pointScan)
def stop_scanning(self):
self.run = False