Provision lidar servicer to support recording data without streaming.

This commit is contained in:
Piv
2020-04-23 21:13:54 +09:30
parent 807921b58f
commit 9a16f02d77

View File

@@ -14,36 +14,36 @@ import os
class LidarServicer(PersonTrackingServicer): class LidarServicer(PersonTrackingServicer):
def __init__(self, vehicle=None): def __init__(self, vehicle=None):
# TODO: Put the rplidar creation in a factory or something, to make it possible to test this servicer. self._lidar = RecordingLidarDecorator(
# Also, it would allow creating the service without the lidar being connected. lidar_factory.get_lidar())
self.cache = LidarCache(RecordingLidarDecorator( self.cache = LidarCache(self._lidar, measurements=100)
lidar_factory.get_lidar()), measurements=100)
self.cache.add_groups_changed_listener(self) self.cache.add_groups_changed_listener(self)
self._mFactory = None self._mFactory = None
self._port = 50052 if 'CAR_ZMQ_PORT' not in os.environ else os.environ[ self._port = 50052 if 'CAR_ZMQ_PORT' not in os.environ else os.environ[
'CAR_ZMQ_PORT'] 'CAR_ZMQ_PORT']
self._vehicle = vehicle self._vehicle = vehicle
self._tracked_group = None self._tracked_group = None
self._should_stream = False
def set_tracking_group(self, request, context): def set_tracking_group(self, request, context):
# Invalid groups should stop tracking # Invalid groups should stop tracking
self._tracked_group = None if request.value < 0 else request.value self._tracked_group = None if request.value < 0 else request.value
def stop_tracking(self, request, context): def stop_tracking(self, request, context):
self._should_stream = False
self.cache.stop_scanning() self.cache.stop_scanning()
def start_tracking(self, request, context): def start_tracking(self, request, context):
"""Starts the lidar cache, streaming on the provided port.""" """Starts the lidar cache, streaming on the provided port."""
self._should_stream = True
self.cache.start_cache() self.cache.start_cache()
def setRecordData(self, request, context):
# Set the vehicles to record their changes.
pass
def onGroupsChanged(self, message): def onGroupsChanged(self, message):
if self._mFactory is None: if self._mFactory is None:
# Create the zmq socket in the thread that it will be used, just to be safe. # Create the zmq socket in the thread that it will be used, just to be safe.
self._mFactory = mf.getZmqPubSubStreamer(self._port) self._mFactory = mf.getZmqPubSubStreamer(self._port)
if self._should_stream:
self._mFactory.send_message_topic( self._mFactory.send_message_topic(
"lidar_map", messages.ProtoMessage(message=message.SerializeToString())) "lidar_map", messages.ProtoMessage(message=message.SerializeToString()))