Implement throttle stream in MotoServer

This commit is contained in:
Piv
2019-09-22 20:24:31 +09:30
parent 177cc209a1
commit 0f83080c75

View File

@@ -15,12 +15,17 @@ class MotorServicer(motorService_pb2_grpc.CarControlServicer):
self.servo = Servo(servo_pin) self.servo = Servo(servo_pin)
self._timer = None self._timer = None
def SetThrottle(self, request, context): def SetThrottle(self, request_iterator, context):
# If we don't get a response every 3 seconds, stop the car. # If we don't get a response every 3 seconds, stop the car.
# This isn't a stream right now, however may change it to be so since we'll constantly # This isn't a stream right now, however may change it to be so since we'll constantly
# be sending values... # be sending values...
throttleFailed = False
for throttleRequest in request_iterator:
self.set_timeout(timeout_length) self.set_timeout(timeout_length)
return motorService_pb2.ThrottleResponse(throttleSet = (True if self.motor.set_throttle(request.throttle) else False)) throttleFailed = self.motor.set_throttle(throttleRequest.throttle)
if throttleFailed:
break
return motorService_pb2.ThrottleResponse(throttleSet = throttleFailed)
def SetSteering(self, request, context): def SetSteering(self, request, context):
# TODO: Fix this to use the motor object as well to check for bounds. # TODO: Fix this to use the motor object as well to check for bounds.