PCMD usage practices for closed loop tracking with ANAFI


I am trying to control the trajectory of drone to track a reference unit square with rotation. The pose of the drone is coming from an external motion tracking sensor at 100 Hz. So PCMD is the right method. However, there are few implementation issues that I am missing. I did go through the forums and found solutions to similar problems, but some of these problems still exist. I was wondering if someone can kindly clarify these for me:

  1. I am trying to move from point 1 to point 2. I have a thread that runs the PCMD control loop

def drone_move(self):
while true:
drone(PCMD(1, UR, UP, UYr, UTh , 1)).wait()

Where the U’s are calculated based on the pose error. But when I run the code, the drone runs off and crashes into a wall. Even if I issue a land/ kill command in between, the drone is still executing PCMD commands. It looks like there is a running buffer of commands that the drone is trying to execute. Is this the correct usage of the command?

  1. Waiting for a drone hover expectation, i.e.,

drone(PCMD(1, UR, UP, UYr, UTh , 1)
>> FlyingStateChanged(state="hovering", _timeout=5)).wait()

works, but the motion is now very jagged, So I think this is not the right usage.

  1. How do we set the maximum rotation speed for ANAFI. I wrote a code that looks like:
    maxYawRate = drone(setAutonomousFlightMaxRotationSpeed(22)).wait()
    if maxYawRate .success():
    print(“max Yaw rate set to 22 deg/sec”)
    elif maxYawRate .timedout():
    print(“Yaw action timed out”)
    print(“Yaw rate action action is still in progress”)

This always ends in Yaw action timed out, so clearly something is wrong here.

Any sample codes/ inputs on these issues will be really helpful. Thank you for your time,

First thing first, you should really test your script with Sphinx the Parrot Drone simulator!

“time.sleep(.5)” ??
500 millisecond is at eternity for a UAV closed loop control. I think you should probably use a smaller update rate (5ms-15ms would seem more appropriate).
Also, there is no point in waiting for the PCMD command here, it’s slowing your control loop for nothing. You should remove the “.wait()” for the PCMD message.

It’s difficult for me to explain what might have gone wrong without much context, could you please share a more complete example? Thanks

I don’t understand why you would want to wait for the hovering state after sending just one piloting command. Anyway, with this code in the worst case scenario you will send a PCMD message every 5 seconds.

For manual piloting command, I think you should rather use the MaxRotationSpeed command message.

The closest Olympe sample code I have on hand is for controlling a drone with the keyboard.


Thank you very much for the inputs here. They were really helpful in solving all the issues. I realized that the issues mostly arose due to poor programming, and bad control design. Here are the final findings:

Issue 1: This was a purely a gain tuning issue. The drone was flying off because of a large proportional gain, which made the drone overshoot. The drone has satisfactory performance when PCMD command loop is run in between 10-50 Hz.
Issue 2: As suggested, the wait and event functions were slowing down the execution of the commands.
Issue 3: MaxRotationSpeed did the trick. Thank you for this.