Files
picar/MotorControl/PythonRemoteController.py
2019-11-14 18:50:26 +10:30

35 lines
797 B
Python

print("Connecting to pi")
import grpc
from concurrent import futures
import motorService_pb2_grpc
from motorService_pb2 import ThrottleRequest
import time
throttle = 0
timer = None
class ThrottleIterator:
'''
Class to get the current throttle for the car.
Will return a random throttle between
'''
def __iter__(self):
return self
def __next__(self):
if throttle > 1 or throttle < -1:
raise StopIteration
time.sleep(1)
return ThrottleRequest(throttle=throttle)
channel = grpc.insecure_channel('10.0.0.53:50051')
stub = motorService_pb2_grpc.CarControlStub(channel)
stub.SetThrottle(ThrottleIterator())
while True:
inp = int(input('Please enter a value for the throttle between -100 and 100'))
throttle = inp / 100