Add SlamController stuff

This commit is contained in:
Piv
2020-02-03 19:00:50 +10:30
parent 03f8485bd5
commit 35f35622cf
6 changed files with 522 additions and 3 deletions

View File

@@ -10,8 +10,9 @@ import grpc
import MotorControl.motorService_pb2 as motorService_pb2
import MotorControl.motorService_pb2_grpc as motorService_pb2_grpc
from MotorControl.gpiozero.motor_session import Motor
from SlamController.slam_streamer import SlamStreamer
import SlamController.SlamController_pb2_grpc as SlamController_pb2_grpc
servo_pin = 18
class MotorServicer(motorService_pb2_grpc.CarControlServicer):
def __init__(self, motor, servo):
@@ -53,13 +54,17 @@ class MotorServicer(motorService_pb2_grpc.CarControlServicer):
def start_server(self):
server = grpc.server(futures.ThreadPoolExecutor(max_workers=8))
motorService_pb2_grpc.add_CarControlServicer_to_server(self, server)
# Disable security for local testing.
SlamController_pb2_grpc.add_SlamControlServicer_to_server(self.create_slam_servicer(), server)
# Disable tls for local testing.
# server.add_secure_port('[::]:50051', self.create_credentials())
server.add_insecure_port('[::]:50051')
server.start()
while True:
time.sleep(60*60)
def create_slam_servicer(self):
return SlamStreamer()
def create_credentials(self):
pvtKeyPath = '/home/pi/tls/device.key'
pvtCertPath = '/home/pi/tls/device.crt'
@@ -70,7 +75,7 @@ class MotorServicer(motorService_pb2_grpc.CarControlServicer):
return grpc.ssl_server_credentials([[pvtKeyBytes, pvtCertBytes]])
motor = Motor()
servo = Servo(servo_pin)
servo = Servo(18)
servicer = MotorServicer(motor, servo)
service_thread = Thread(target=servicer.start_server)