Olympe API Reference Documentation#

class olympe.Drone#
__init__(*args, video_buffer_queue_size=8, **kwds)#
connect(**kwds)#

Make all step to make the connection between the device and the controller

Parameters
  • timeout – the global connection timeout in seconds (including the retried connection attempt duration when retry > 1)

  • retry – the number of connection attempts (default to 1)

Return type

bool

disconnect(*, timeout=5)#

Disconnects current device (if any) Blocks until it is done or abandoned

Return type

bool

connection_state()#

Returns the state of the connection to the drone

Return type

bool

__call__(expectations)#

This method can be used to:

  • send command messages and waiting for their associated expectations

  • monitor spontaneous drone event messages

  • check the state of the drone

It asynchronously process arsdk command and event message and expectations.

Please refer to the Olympe User Guide for more information.

Parameters

expectations – An SDK message expectation expression

Return type

ArsdkExpectationBase

Please refer to the Olympe user guide for more information.

get_state(message)#

Returns the drone current state for the event message given in parameter

Parameters

message (ArsdkMessage) – an event message type

Returns

an ordered dictionary containing the arguments of the last received event message that matches the message ID provided in parameter

check_state(message, *args, **kwds)#

Returns True if the drone state associated to the given message is already reached. Otherwise, returns False

query_state(query)#

Query the drone current state return a dictionary of every drone state whose message name contains the query string :return: dictionary of drone state :param: query, the string to search for in the message received from the drone.

subscribe(*args, **kwds)#

See: subscribe()

unsubscribe(subscriber)#

Unsubscribe a previously registered subscriber

Parameters

subscriber (Subscriber) – the subscriber previously returned by subscribe()

start_piloting()#

Start interface to send piloting commands

Return type

bool

piloting(roll, pitch, yaw, gaz, piloting_time)#

Send manual piloting commands to the drone. This function is a non-blocking.

Parameters
  • roll (int) – roll consign for the drone (must be in [-100:100])

  • pitch (int) – pitch consign for the drone (must be in [-100:100])

  • yaw (int) – yaw consign for the drone (must be in [-100:100])

  • gaz (int) – gaz consign for the drone (must be in [-100:100])

  • piloting_time (float) – The time of the piloting command

Return type

bool

stop_piloting()#

Stop interface to send piloting commands

Return type

bool

class olympe.EventListener#

EventListener base class

This class implements the visitor pattern and is meant to be overridden to dispatch drone event messages to the correct class method.

To start/stop listening to event messages EventListener.subscribe() EventListener.unsubscribe() methods should be called. Alternatively, this class can be used as a context manager.

Example:

import olympe
from olympe.messages.ardrone3.Piloting import TakeOff, Landing, moveBy
from olympe.messages.ardrone3.PilotingState import (
    PositionChanged,
    AlertStateChanged,
    FlyingStateChanged,
    NavigateHomeStateChanged,
)

class FlightListener(olympe.EventListener):

    @olympe.listen_event(FlyingStateChanged() | AlertStateChanged() |
        NavigateHomeStateChanged())
    def onStateChanged(self, event, scheduler):
        print("{} = {}".format(event.message.name, event.args["state"]))

    @olympe.listen_event(PositionChanged())
    def onPositionChanged(self, event, scheduler):
        print(
            "latitude = {latitude} longitude = {longitude} altitude = {altitude}".format(
                **event.args
            )
        )


drone = olympe.Drone("10.202.0.1")
with FlightListener(drone):
    drone.connect()
    drone(
        FlyingStateChanged(state="hovering")
        | (TakeOff() & FlyingStateChanged(state="hovering"))
    ).wait()
    drone(moveBy(10, 0, 0, 0)).wait()
    drone(Landing()).wait()
    drone(FlyingStateChanged(state="landed")).wait()
    drone.disconnect()
__init__(*contexts, timeout=10)#
Parameters
  • scheduler – an olympe.Drone or an olympe.expectations.Scheduler object for which this listener will subscribe to event messages.

  • timeout – the listener callbacks timeout in seconds

subscribe()#

Start to listen to the scheduler event messages

unsubscribe()#

Stop from listening scheduler event messages

class olympe.Pdraw#
__init__(name=None, device_name=None, server_addr=None, buffer_queue_size=8, pdraw_thread_loop=None)#
Parameters
  • name (str) – (optional) pdraw client name (used by Olympe logs)

  • device_name (str) – (optional) the drone device name (used by Olympe logs)

  • buffer_queue_size (int) – (optional) video buffer queue size (defaults to 8)

play(url=None, media_name='DefaultVideo', resource_name='live', timeout=5)#

Play a video

By default, open and play a live video streaming session available from rtsp://192.168.42.1/live where “192.168.42.1” is the default IP address of a physical (Anafi) drone. The default is equivalent to Pdraw.play(url=”rtsp://192.168.42.1/live”)

For a the live video streaming from a simulated drone, you have to specify the default simulated drone IP address (10.202.0.1) instead: Pdraw.play(url=”rtsp://10.202.0.1/live”).

The url parameter can also point to a local file example: Pdraw.play(url=”file://~/Videos/100000010001.MP4”).

Parameters
  • url (str) – rtsp or local file video URL

  • media_name (str) – name of the media/track (defaults to “DefaultVideo”). If the provided media name is not available from the requested video stream, the default media is selected instead.

pause()#

Pause the currently playing video

close()#

Close a playing or paused video stream session

set_output_files(video=None, metadata=None, info=None)#

Records the video stream session to the disk

  • video: path to the video stream mp4 recording file

  • metadata: path to the video stream metadata json output file

  • info: path to video stream frames info json output file

This function MUST NOT be called when a video streaming session is active. Setting a file parameter to None disables the recording for the related stream part.

set_callbacks(h264_cb=None, h264_avcc_cb=None, h264_bytestream_cb=None, raw_cb=None, start_cb=None, end_cb=None, flush_h264_cb=None, flush_raw_cb=None)#

Set the callback functions that will be called when a new video stream frame is available, when the video stream starts/ends or when the video buffer needs to get flushed.

Video frame callbacks

  • h264_cb is associated to the H264 encoded video (AVCC) stream

  • h264_avcc_cb is associated to the H264 encoded video (AVCC) stream

  • h264_bytestream_cb is associated to the H264 encoded video

    (ByteStream) stream

  • raw_cb is associated to the decoded video stream

Each video frame callback function takes an VideoFrame() parameter whose lifetime ends after the callback execution. If this video frame is passed to another thread, its internal reference count need to be incremented first by calling ref(). In this case, once the frame is no longer needed, its reference count needs to be decremented so that this video frame can be returned to memory pool.

Video flush callbacks

  • flush_h264_cb is associated to the H264 encoded video stream

  • flush_raw_cb is associated to the decoded video stream

Video flush callback functions are called when a video stream reclaim all its associated video buffer. Every frame that has been referenced

Start/End callbacks

The start_cb/end_cb callback functions are called when the video stream start/ends. They don’t accept any parameter.

The return value of all these callback functions are ignored. If a callback is not desired, leave the parameter to its default value or set it to None explicitly.

get_session_metadata()#

Returns a dictionary of video stream session metadata

property state#

Return the current Pdraw state

Return type

PdrawState

wait(state, timeout=None)#

Wait for the provided Pdraw state

This function returns True when the requested state is reached or False if the timeout duration is reached.

If the requested state is already reached, this function returns True immediately.

This function may block indefinitely when called without a timeout value.

Parameters

timeout (float) – the timeout duration in seconds or None (the default)

Return type

bool

class olympe.Media#

Drone Media API class

This class automatically connects to the drone web media interface (REST and websocket API) and synchronizes the drone media information in a background thread.

Media info:
Media monitoring with the Subscriber/listener API:

See usage example in doc/examples/media.py

__init__(hostname=None, version=1, name=None, device_name=None, scheduler=None, download_dir=None, integrity_check=None)#
connect(*, timeout=5, **kwds)#
disconnect(*, timeout=5)#
shutdown()#

Properly close and stop the websocket connection and the media API background thread

media_info(media_id=None)#

Returns a media info object if media_id is None or a list of all available media info otherwise.

Return type

list(MediaInfo) or MediaInfo

resource_info(media_id=None, resource_id=None, with_md5=False, with_signature=False, timeout=None)#

Returns a list resources info associated to a media_id or a specific resource info associated to a resource_id. This function raises a ValueError if media_id and resource_id are both left to None.

Return type

list(ResourceInfo) or ResourceInfo

list_media()#

Returns a list of all available media id

list_resources(media_id=None)#

Returns a list of all available resource id if media_id is None or a list of resource id associated to the given media_id otherwise.

property indexing_state#

Returns the current media indexing state :rtype IndexingState:

__call__(expectations)#

Olympe expectation DSL handler

subscribe(*args, **kwds)#

See: subscribe()

unsubscribe(subscriber)#

Unsubscribe a previously registered subscriber

Parameters

subscriber (Subscriber) – the subscriber previously returned by subscribe()

class olympe.MediaInfo#

Namedtuple class MediaInfo(media_id, type, datetime, size, run_id, custom_id, resources, duration, thumbnail, gps, video_mode, photo_mode, panorama_type, expected_count, replay_url, thermal)

  • media_id (str): unique id of the media

  • type ( MediaType): type of the media

  • datetime (str) :iso8601 datetime of the media

  • size (int): size (in bytes) of the media (total size of all its resources)

  • duration (int): duration (in milliseconds) of the video media (total duration of all its resources)

  • run_id (str): run id of the media

  • thumbnail (str): relative url to be used in a GET request to download the media thumbnail (if available)

  • gps (GPS): gps coordinates of the media (if available)

  • photo_mode (PhotoMode): photo mode of the media (if available and media is a photo)

  • panorama_type (panorama_type enum): panorama type of the media (if available, media is a photo and photo_mode is panorama)

  • expected_count (int): expected number of resources in the media ( if available, media is a photo and photo_mode is panorama)

  • replay_url (str): media rtsp replay url (prefixed by rtsp://drone.ip.address:rtsp_port/)

  • resources (list( ResourceInfo )): resource list of the media

  • thermal (bool): media includes resources with thermal metadata (if value is true)

class olympe.ResourceInfo#

Namedtuple class ResourceInfo(media_id, resource_id, type, format, datetime, size, url, width, height, duration, thumbnail, signature, gps, video_mode, replay_url, thermal, md5, storage, download_path, download_md5_path, thumbnail_download_path, thumbnail_download_md5_path) - media_id (str): unique id of the media - resource_id (str): unique id of the resource - type ( MediaType): type of the resource - format ( ResourceFormat): format of the resource - datetime (str) :iso8601 datetime of the media - size (int): size (in bytes) of the media (total size of all its resources) - duration (int): duration (in milliseconds) of the video media (total

duration of all its resources)

  • url (str): relative url to be used in a GET request to download the resource

  • thumbnail (str): relative url to be used in a GET request to download the resource thumbnail (if available)

  • signature (str): resource signature (optional)

  • gps (GPS): gps coordinates of the media (if available)

  • width (int): width (in pixels) of the resource

  • height (int): height (in pixels) of the resource

  • replay_url (str): media rtsp replay url (prefixed by rtsp://drone.ip.address:rtsp_port/)

  • thermal (bool): media includes resources with thermal metadata (if value is true)

  • md5 (str): media md5 checksum (if resource is photo)

  • video_mode (str): video mode of the resource (if available and resource is a video)

  • storage (str): storage where the resource is located

class olympe.media.MediaType#

An enumeration.

photo = 'PHOTO'#
video = 'VIDEO'#
class olympe.media.PhotoMode#

An enumeration.

bracketing = 'BRACKETING'#
burst = 'BURST'#
gpslapse = 'GPSLAPSE'#
panorama = 'PANORAMA'#
single = 'SINGLE'#
timelapse = 'TIMELAPSE'#
class olympe.media.IndexingState#

An enumeration.

indexed = 'INDEXED'#
indexing = 'INDEXING'#
not_indexed = 'NOT_INDEXED'#
class olympe.media.GPS#

Namedtuple class GPS(latitude, longitude, altitude)

altitude#

Alias for field number 2

latitude#

Alias for field number 0

longitude#

Alias for field number 1

class olympe.VideoFrame#
ref()#

This function increments the reference counter of the underlying buffer(s)

unref()#

This function decrements the reference counter of the underlying buffer(s)

info()#

Returns a dictionary of video frame info

vmeta()#

Returns a 2-tuple (VMetaFrameType, dictionary of video frame metadata)

as_ctypes_pointer()#

This function return a 2-tuple (frame_pointer, frame_size) where frame_pointer is a ctypes pointer and frame_size the frame size in bytes.

See: https://docs.python.org/3/library/ctypes.html

as_ndarray()#

This function returns an non-owning numpy 1D (h264) or 2D (YUV) array on this video frame

class olympe.PdrawState#

An enumeration.

Created = 1#
Closing = 2#
Closed = 3#
Opening = 5#
Opened = 6#
Playing = 7#
Paused = 8#
Error = 9#
class olympe.MissionController#
from_path(url_or_path: Union[Path, str], feature_name_from_file=False)#

Creates and returns an olympe.Mission object from a local path or an URL to an AirSDK mission archive.

class olympe.Mission#
install(allow_overwrite=None, is_default=None, timeout=30, **kwds)#

Install this mission onto the remote drone. The drone must be rebooted before this mission becomes available.

messages#

Returns a dictionary of mission (non-protobuf) messages usable with the Olympe DSL API.

enums#

Returns a dictionary of mission enums usable with the Olympe DSL API.

wait_ready(timeout=None)#

Wait for this mission to become ready to communicate with the drone. This method waits for the associated drone to send this mission instance recipient ID.

send(proto_message, service_name, msg_num, proto_args=None, recipient_id=None, quiet=False)#

Send an AirSDK mission custom protobuf message to the drone.

Parameters
  • proto_message – An AirSDK protocol buffer message

  • service_name – the associated custom message service

  • msg_num – the associated custom message number

  • proto_args – an optional mapping of arguments to merge into the protocol buffer message

  • recipient_id – specify or override the associated recipient ID

  • quiet – optional boolean flag to decrease log verbosity (defaults to False)

subscribe(callback, service_name=None, msg_num=None, recipient_id=None)#

Subscribe a callback function to every event messages associated to this mission.

See: subscribe()

class olympe.Expectation#
abstract received_events()#

Returns a collection of events that have matched at least one of the messages ID monitored by this expectation.

abstract matched_events()#

Returns a collection of events that have matched this expectation (or a child expectation)

abstract unmatched_events()#

Returns a collection of events object that are still expected

explain()#

Returns a debug string that explain this expectation current state.

olympe.log.update_config(update, on_update=None)#

Update (recursively) the current logging configuration dictionary.

See: Logging config dictionary schema