Asyncaction.py example with moveTo instead of moveBy

I have been trying to implement the asyncaction.py example (from the user guide, under “Advanced Usage Examples”) with the moveTo command in place of the moveBy command. While the unmodified code performs as expected both in simulation and in reality, after the substitution the drone takes off and suddenly lands. I am asking the drone to fly 15 meters above the home position. The changes made to the code are the following:

at line 11 added:

drone(GPSFixStateChanged(fixed=1, _timeout=10, _policy='check_wait'))
drone_home = drone.get_state(HomeChanged)

in place of line 16 (the moveBy command):

>> moveTo(drone_home['latitude'], drone_home['longitude'], 15, MoveTo_Orientation_mode.NONE, 0.0)

Goes without saying that all the required messages and events are imported at the beginning of the file.

I verified in the logs that I am receiving the correct home position and sending the command as supposed. I receive the event MoveToChanged with status RUNNING. What seems to happen next is that the code sends the Landing command right after receiving the event MoveToChanged (RUNNING), triggering the event MoveToChanged with status CANCELED and making the drone land.
I am reporting the mentioned log section here:

05/09/2019 22:47:20.606607      _send_command                   Ardrone3.Piloting.MoveTo(c_double( 48.87890000000001), c_double(2.3677799999999998), c_double(15.0), c_uint(0), c_double(0.0)): has been sent asynchronously
05/09/2019 22:47:20.609058      _recv_cmd_cb                    ardrone3.GPSState.HomeTypeAvailabilityChanged(type=HomeTypeAvailabilityChanged_Type.TAKEOFF, available=1)
05/09/2019 22:47:20.610563      _recv_cmd_cb                    ardrone3.GPSState.HomeTypeChosenChanged(type=HomeTypeChosenChanged_Type.TAKEOFF)
05/09/2019 22:47:20.612524      _recv_cmd_cb                    ardrone3.PilotingState.NavigateHomeStateChanged(state=NavigateHomeStateChanged_State.available, reason=NavigateHomeStateChanged_Reason.enabled)
05/09/2019 22:47:20.614039      _recv_cmd_cb                    animation.availability(values='horizontal_panorama|dronie|horizontal_reveal|vertical_reveal|twist_up')
05/09/2019 22:47:20.661230      _recv_cmd_cb                    ardrone3.PilotingState.moveToChanged(latitude=48.87890000000001, longitude=2.3677799999999998, altitude=15.0, orientation_mode=MoveToChanged_Orientation_mode.NONE, heading=88.3249740600586, status=MoveToChanged_Status.RUNNING)
05/09/2019 22:47:20.663077      _send_command                   Ardrone3.Piloting.Landing(): has been sent asynchronously
05/09/2019 22:47:20.668825      _recv_cmd_cb                    animation.availability(values='')
05/09/2019 22:47:20.689465      _recv_cmd_cb                    ardrone3.PilotingState.moveToChanged(latitude=48.87890000000001, longitude=2.3677799999999998, altitude=15.0, orientation_mode=MoveToChanged_Orientation_mode.NONE, heading=88.3249740600586, status=MoveToChanged_Status.CANCELED)
05/09/2019 22:47:20.691268      _destroy_pomp_loop              Pomp loop has been destroyed
05/09/2019 22:47:20.692668      destroy_timer                   Pomp loop timer has been destroyed
05/09/2019 22:47:20.694023      destroy_timer                   Pomp loop timer has been destroyed
E pomp: fd=23, cb=0x7ff10a3b0700 not removed from loop
E pomp: fd=22, cb=0x7ff10a3b0700 not removed from loop
E pomp: fd=20, cb=0x7ff10ac134e0 not removed from loop
E pomp: fd=19, cb=0x7ff10a3b0700 not removed from loop
E pomp: fd=18, cb=0x7ff10a3b0700 not removed from loop
E pomp: fd=17, cb=0x7ff10a3a5f10 not removed from loop
E pomp: fd=16, cb=0x7ff10a3b0700 not removed from loop
E pomp: fd=15, cb=0x7ff10a3b0700 not removed from loop
05/09/2019 22:47:20.695940      _destroy_pomp_loop              Error while destroying pomp loop: -16
I arsdkctrl: discovery 'net': remove device name='ANAFI-0000000' id='000000000000000000'
I arsdkctrl: internally disconnect device name='ANAFI-0000000' type=ANAFI4K id='000000000000000000'
05/09/2019 22:47:20.697338      _disconnected_cb                Disconnected from device: ANAFI-0000000
05/09/2019 22:47:20.699350      _device_removed_cb              Device has been removed
I arsdkctrl: discovery 'net': stop
05/09/2019 22:47:20.700092      _stop_discovery                 Discovery has been stopped
05/09/2019 22:47:20.700604      _stop_discovery                 Discovery object has been destroyed
05/09/2019 22:47:20.703845      _destroy_net_backend            Net backend has been destroyed
05/09/2019 22:47:20.704341      _destroy_manager                Manager has been destroyed
05/09/2019 22:47:20.793137      _destroy_pomp_loop              Pomp loop has been destroyed

Hello,

Can you please share your modified script ?
I suspect that you are missing some “.wait()” call here and there. For example:

Should be :

drone(GPSFixStateChanged(fixed=1, _timeout=10, _policy='check_wait')).wait()
drone_home = drone.get_state(HomeChanged)

Without the .wait() here the whole line is a no-op / non-blocking statement.

Hi, thanks for the heads up.
Unfortunately, being a new user, I cannot upload any file, so I pasted it here:

import olympe
from olympe.messages.ardrone3.Piloting import TakeOff, moveTo, Landing
from olympe.enums.ardrone3.Piloting import MoveTo_Orientation_mode
from olympe.messages.ardrone3.PilotingState import FlyingStateChanged
from olympe.messages.ardrone3.GPSSettingsState import GPSFixStateChanged, HomeChanged
from olympe.messages.camera import start_recording, stop_recording
from olympe.messages import gimbal

with olympe.Drone("10.202.0.1") as drone:
    drone.connection()
    drone(GPSFixStateChanged(fixed=1, _timeout=10, _policy='check_wait'))
    drone_home = drone.get_state(HomeChanged)
    # Start a flying action asynchronously
    flyingAction = drone(
        TakeOff()
        >> FlyingStateChanged(state="hovering", _timeout=5)
        >> moveTo(drone_home['latitude'], drone_home['longitude'], 15, MoveTo_Orientation_mode.NONE, 0.0)
        >> FlyingStateChanged(state="hovering", _timeout=5)
        >> Landing()
    )

    # Start video recording while the drone is flying
    if not drone(start_recording(cam_id=0)).wait().success():
        raise RuntimeError("Cannot start video recording")

    # Send a gimbal pitch velocity target while the drone is flying
    cameraAction = drone(gimbal.set_target(
        gimbal_id=0,
        control_mode="velocity",
        yaw_frame_of_reference="none",
        yaw=0.0,
        pitch_frame_of_reference="none",
        pitch=0.1,
        roll_frame_of_reference="none",
        roll=0.0,
    )).wait()

    if not cameraAction.success():
        raise RuntimeError("Cannot set gimbal velocity target")

    # Wait for the end of the flying action
    if not flyingAction.wait().success():
        raise RuntimeError("Cannot complete the flying action")

    # Stop video recording while the drone is flying
    if not drone(stop_recording(cam_id=0)).wait().success():
        raise RuntimeError("Cannot stop video recording")

    # Leaving the with statement scope: implicit drone.disconnection()

Solved substituting the FlyingStateChanged call with the MoveToChanged call as follows:

flyingAction = drone(
    TakeOff()
    >> FlyingStateChanged(state="hovering", _timeout=5)
    >> moveTo(drone_home['latitude'], drone_home['longitude'], 15, MoveTo_Orientation_mode.NONE, 0.0)
    >> MoveToChanged(status="DONE")
    >> Landing()
)
1 Like