def run(): with grpc.insecure_channel("localhost:50052") as channel: stub = imu_pb2_grpc.ImuServiceStub(channel) print("-------------- GetStatus --------------") status = get_status(stub) print(repr(status)) if not status.mpu_calibrated: stub.CalibrateMPU(imu_pb2.EmptyRequest()) stub.Configure(imu_pb2.EmptyRequest()) if not status.is_updating and not status.has_position: print("-------------- StartUpdating --------------") start_updating(stub) status = get_status(stub) print("-------------- GetPosition --------------") while True: get_position(stub) time.sleep(1)
def configure(self): with grpc.insecure_channel(self.service_address) as channel: stub = imu_pb2_grpc.ImuServiceStub(channel) stub.Configure(imu_pb2.EmptyRequest())
def position(self): with grpc.insecure_channel(self.service_address) as channel: stub = imu_pb2_grpc.ImuServiceStub(channel) return stub.GetPosition(imu_pb2.EmptyRequest())
def stop(self): with grpc.insecure_channel(self.service_address) as channel: stub = imu_pb2_grpc.ImuServiceStub(channel) return stub.StopUpdating(imu_pb2.EmptyRequest())
def calibrate_mpu(self): with grpc.insecure_channel(self.service_address) as channel: stub = imu_pb2_grpc.ImuServiceStub(channel) return stub.CalibrateMPU(imu_pb2.EmptyRequest())