Listen and subscribe to an event¶
Objective:
Listen to a specific event message from the drone, and react to its reception.
Listener¶
The example below illustrates how to listen to an Event message from the drone:
Body¶
The decorator @olympe.listen_event takes as argument the ARSDK Event message to monitor.
This very event takes as argument ExpectPolicy, as explained here.
The function decorated is named after the event listened to: def onEventListenedTo(self, event, scheduler).
The body of this function can log or process any kind of action, especially when it affects
olympe.Event and its API.
Using with affixed to an olympe.EventListener does subscribe and unsubscribe
on its own, but you can also decide to explicitly call olympe.EventListener.subscribe()
and olympe.EventListener.unsubscribe().
Or use a ‘subscriber’ instead of a ‘listener’.
Subscriber¶
The example below illustrates how to subscribe to an Event message from the drone:
The purpose is the same, but the actions to be taken are quite different.
Body¶
The subscription has to be done directly onto the olympe.Drone API. Do not
forget to unsubscribe when done, or use with statement!
For the rest, instead of a method to define, use a lambda when you subscribe to the Event you want to monitor.