From 9a16f02d77acaad1d19219f5dae5389f0b7540a3 Mon Sep 17 00:00:00 2001 From: Piv <18462828+Piv200@users.noreply.github.com> Date: Thu, 23 Apr 2020 21:13:54 +0930 Subject: [PATCH] Provision lidar servicer to support recording data without streaming. --- car/src/car/tracking/lidar_servicer.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/car/src/car/tracking/lidar_servicer.py b/car/src/car/tracking/lidar_servicer.py index 391d649..552da00 100644 --- a/car/src/car/tracking/lidar_servicer.py +++ b/car/src/car/tracking/lidar_servicer.py @@ -14,38 +14,38 @@ import os class LidarServicer(PersonTrackingServicer): def __init__(self, vehicle=None): - # TODO: Put the rplidar creation in a factory or something, to make it possible to test this servicer. - # Also, it would allow creating the service without the lidar being connected. - self.cache = LidarCache(RecordingLidarDecorator( - lidar_factory.get_lidar()), measurements=100) + self._lidar = RecordingLidarDecorator( + lidar_factory.get_lidar()) + self.cache = LidarCache(self._lidar, measurements=100) self.cache.add_groups_changed_listener(self) self._mFactory = None self._port = 50052 if 'CAR_ZMQ_PORT' not in os.environ else os.environ[ 'CAR_ZMQ_PORT'] self._vehicle = vehicle self._tracked_group = None + self._should_stream = False def set_tracking_group(self, request, context): # Invalid groups should stop tracking self._tracked_group = None if request.value < 0 else request.value def stop_tracking(self, request, context): + self._should_stream = False self.cache.stop_scanning() def start_tracking(self, request, context): """Starts the lidar cache, streaming on the provided port.""" + self._should_stream = True self.cache.start_cache() - def setRecordData(self, request, context): - # Set the vehicles to record their changes. - pass - 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())) + + if self._should_stream: + self._mFactory.send_message_topic( + "lidar_map", messages.ProtoMessage(message=message.SerializeToString())) if self._tracked_group is not None and self._vehicle is not None: # Update vehicle to correctly follow the tracked group.