32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
import slam.SlamController_pb2_grpc as grpc
|
|
import slam.SlamController_pb2 as proto
|
|
import slam.slam_streamer as slam
|
|
from multiprocessing import Process
|
|
|
|
|
|
class SlamServicer(grpc.SlamControlServicer):
|
|
slam_thread = None
|
|
|
|
def __init__(self, lidar_connection):
|
|
print('Servicer initialised')
|
|
self.slam = slam.SlamStreamer(lidar_connection=lidar_connection)
|
|
|
|
def start_map_streaming(self, request, context):
|
|
print('Received Map Start Streaming Request')
|
|
if self.slam_thread is None:
|
|
print('initialising slam_thread')
|
|
# Don't bother creating and starting slam more than once.
|
|
self.slam.port = request.port
|
|
self.slam.map_pixels = request.map_size_pixels
|
|
self.slam.map_meters = request.map_size_meters
|
|
self.slam_thread = Process(target=self.slam.start)
|
|
self.slam_thread.start()
|
|
return proto.Empty()
|
|
|
|
def stop_streaming(self, request, context):
|
|
if self.slam_thread is not None:
|
|
self.slam.stop_scanning()
|
|
self.slam_thread.join()
|
|
self.slam = None
|
|
return proto.Empty()
|