Refactor python module structure
This commit is contained in:
31
slam/slam_servicer.py
Normal file
31
slam/slam_servicer.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user