create_boolean_listener()
- 1 Minute to read
create_boolean_listener()
- 1 Minute to read
Article summary
Did you find this summary helpful?
Thank you for your feedback
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
Arguments | Type | |
---|---|---|
listener_name | string | Unique listener identifier |
callback | Callable object | Callback |
sensor_paths | list of strings | List of sensors paths, see the list of sensors |
logic_state | bool | Logic state to trigger the listener |
Return
None
Exceptions
Exception | Condition |
---|---|
RayaListenerAlreadyCreated | Provided listener name already used to create another listener. |
RayaInvalidCallback | Invalid or not callable callback. |
RayaSensorsUnknownPath | Unknown sensor path. |
RayaSensorsIncompatiblePath | Sensor path not compatible with current robot. |
RayaSensorsInvalidPath | Incorrect 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?