import time import compLib.CompLib_pb2 as CompLib_pb2 from compLib.CompLibClient import CompLibClient class IRSensor(object): """Access the different IR Sensors of the robot """ @staticmethod def read_all(): """Read all IR sensors at once. :return: Array of all current ir sensors """ request = CompLib_pb2.IRSensorsReadAllRequest() request.header.message_type = request.DESCRIPTOR.full_name response = CompLib_pb2.IRSensorsReadAllResponse() response.ParseFromString(CompLibClient.send( request.SerializeToString(), request.ByteSize())) return [i for i in response.data] @staticmethod def enable(): """Turn on all IR emitters """ request = CompLib_pb2.IRSensorsEnableRequest() request.header.message_type = request.DESCRIPTOR.full_name CompLibClient.send(request.SerializeToString(), request.ByteSize()) time.sleep(0.1) # IR sensor reading is async -> Wait a bit @staticmethod def disable(): """Turn off all IR emitters """ request = CompLib_pb2.IRSensorsDisableRequest() request.header.message_type = request.DESCRIPTOR.full_name CompLibClient.send(request.SerializeToString(), request.ByteSize()) time.sleep(0.1) # IR sensor reading is async -> Wait a bit