Taking photos with Olympe and Sphinx

Hi. I recently got into the Olympe API and I’m trying to understand how it works by writing some programs, since I’m working with a Parrot drone for a project. However, I need to process a image taken with the drone but I can’t make it work in the simulation to try it later with the physical drone. I’ve tried several things but none of them worked, I always get AssertionError when using the set_camera_mode event. This is the latest code I’ve tried:

import olympe
import os
import time
from olympe.messages.ardrone3.Piloting import TakeOff, Landing, moveBy
from olympe.messages.ardrone3.PilotingState import FlyingStateChanged
from olympe.messages.camera import set_photo_mode, take_photo, photo_state, set_camera_mode, photo_progress, camera_mode

DRONE_IP = os.environ.get("DRONE_IP", "10.202.0.1")


def photoTest():
    drone = olympe.Drone(DRONE_IP)
    drone.connect()
    assert drone(TakeOff()).wait().success()
    assert drone(set_camera_mode(cam_id=0, value='photo'))
    print('-------------------------------------------------')
    print('Camera mode is ', drone.get_state(camera_mode)['mode'])
    print('-------------------------------------------------')
    assert drone(set_photo_mode(cam_id=0,
                            mode='single',
                            format='full_frame',
                            file_format='jpeg',
                            burst='burst_14_over_4s',
                            bracketing='preset_1ev',
                            capture_interval=0.0)
                 ).wait()
    if drone.get_state(photo_state()) == 'active':
        print('Photo mode is active. Taking Photo.')
        assert drone(take_photo(cam_id=0, _timeout=500)).wait()
    else:
        print('Error in photo. Status is: ', drone.get_state(photo_state))

    assert drone(Landing()).wait().success()
    drone.disconnect()


if __name__ == '__main__':
    photoTest()

I’ve also tried adding >> FlyingStateChanged(state="hovering", _timeout=100) thinking that the problem could be that the drone can only change the camera status when hovering but I get the same result. Changing the timeout to a huge number to prevent any delays, since the simulation really never works on real time, doesn’t work.

Hello,

With ANAFI Ai you have to use the Camera2 API:

import os
import olympe
from olympe.messages.camera2.Command import Configure, StartPhoto
from olympe.messages.camera2.Event import Photo

DRONE_IP = os.environ.get('DRONE_IP', '10.202.0.1')


def test_photo():
    with olympe.Drone(DRONE_IP) as drone:
        drone.connect()
        drone(
            Configure(camera_id=0,
                      config=dict(
                          camera_mode='photo',
                          photo_mode='single',
                          photo_format='full_frame',
                          photo_file_format='jpeg',
                          photo_dynamic_range='standard',
                          exposure_mode='automatic',
                          white_balance_mode='automatic',
                          ev_compensation='0_00',
                      )) >> StartPhoto(camera_id=0) >> Photo(
                          camera_id=0,
                          type='taking_photo',
                      ) >> Photo(
                          camera_id=0,
                          type='stop',
                          stop_reason='capture_done',
                      )).wait()
        drone.disconnect()


if __name__ == '__main__':
    test_photo()
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.