This repository has been archived on 2025-06-01. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
compLIB/client/compLib/IRSensor.py
Konstantin Lampalzer af3aaf7998 update documentation
2022-10-13 00:31:43 +02:00

45 lines
1.4 KiB
Python

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