Provision lidar servicer to support recording data without streaming.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user