create_boolean_listener()
  • 1 Minute to read

create_boolean_listener()


Article summary

Create a listener triggered when the value of one (or multiple) boolean sensor(s) go(es) into a specific logic state.

Note: This method only works with boolean sensors. Remember the types of sensors in the Sensors page.

Reference

Arguments

ArgumentsType
listener_namestringUnique listener identifier
callbackCallable objectCallback
sensor_pathslist of stringsList of sensors paths, see the list of sensors
logic_stateboolLogic state to trigger the listener

Return

None

Exceptions

ExceptionCondition
RayaListenerAlreadyCreatedProvided listener name already used to create another listener.
RayaInvalidCallbackInvalid or not callable callback.
RayaSensorsUnknownPathUnknown sensor path.
RayaSensorsIncompatiblePathSensor path not compatible with current robot.
RayaSensorsInvalidPathIncorrect sensor path.

See the Full List of Exceptions

Callback Arguments

Callback does not receive any arguments.

Examples

1. Line detection

Detect a line by any of the line sensors:

async def setup(self):
    ...
    self.sensors = await self.enable_controller('sensors')
    self.sensors.create_boolean_listener(listener_name='line',
                                           callback = self.line_callback,
                                           sensor_paths = ['/line_sensor/1', '/line_sensor/2', '/line_sensor/3'],
                                           logic_state = True)
    ...
    
async def loop(self):
    # Doing other stuff
    ...
    
def line_callback(self):
        print('line detected!')

Was this article helpful?