Use change listener rather than direct message factory for lidar.
This commit is contained in:
@@ -4,12 +4,16 @@ from tracking.lidar_cache import LidarCache
|
||||
from multiprocessing import Process
|
||||
import messaging.message_factory as mf
|
||||
from rplidar import RPLidar
|
||||
from Messaging import messages
|
||||
|
||||
|
||||
class LidarServicer(PersonTrackingServicer):
|
||||
|
||||
def __init__(self):
|
||||
#TODO: Put the rplidar creation in a factory or something, to make it possible to test this servicer.
|
||||
# TODO: Put the rplidar creation in a factory or something, to make it possible to test this servicer.
|
||||
self.cache = LidarCache(RPLidar('/dev/ttyUSB0'), measurements=100)
|
||||
self._mFactory = None
|
||||
self._port = None
|
||||
|
||||
def set_tracking_group(self, request, context):
|
||||
pass
|
||||
@@ -19,4 +23,11 @@ class LidarServicer(PersonTrackingServicer):
|
||||
|
||||
def start_tracking(self, request, context):
|
||||
"""Starts the lidar cache, streaming on the provided port."""
|
||||
self.cache.start_cache(mf.getZmqPubSubStreamer(request.value))
|
||||
self._port = request.value
|
||||
self.cache.start_cache(self)
|
||||
|
||||
def onGroupsChanged(self, message):
|
||||
if self._mFactory is None:
|
||||
# Create the zmq socket in the thread that it will be used, just to be safe.
|
||||
self._mFactory = mf.getZmqPubSubStreamer(self._port)
|
||||
self._mFactory.send_message_topic("lidar_map", messages.ProtoMessage(message=message.SerializeToString()))
|
||||
|
||||
Reference in New Issue
Block a user