import time import compLib.CompLib_pb2 as CompLib_pb2 from compLib.CompLibClient import CompLibClient class IRSensor(object): """Ermöglicht den Zugriff auf die einzelnen IRSensoren des Roboters """ @staticmethod def read_all(): """Auslesen aller Sensoren gleichzeitig :return: Array aller Sensorwerte """ 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(): """Aktivieren Infrarot-Sender. Muss bei jedem Programmstart ausgeführt werden. """ 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(): """Deaktivieren der Infrarot-Sender """ 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