Understanding anafi inner loop control and PCMD commands

I am working on a project to develop a controller which can reject wind or gust if we know its direction and magnitude. I used the parrot sphinx wind option to generate wind in the simulation. When I analysed the parrot anafi drone behavior in different wind conditions by just hovering it, I saw it has a very good inner loop autopilot, it can reject the wind pretty well and stay at the same position. But once I give some some PCMD commands it starts drifting away. What my understanding is drone is trying to achieve the pose we give as arguments in the PCMD command. Because of the presence of the wind it is unable to do that and hence it drifts. But my concern is the way it drifts. So for example I give a crosswind, and 0,0,0,0 PCMD command, I hope the drone to drift sidewards in the direction of wind, but what I saw is surprising, the drone makes random circular motion. Same case with headwind. Infact what I saw is, irrespective of wind direction, the drone kinda makes random circular motion. I cannot understand what’s happening. Can someone explain what exactly PCMD commands try to do and what is the inner loop autopilot trying to achieve? Why do we see this random circular motion for all wind direction. Any help is appreciated.

PS: This is all in parrot sphinx simulation

1 Like

Hi @vishnu02saj,

This is an interesting question. I hope you understand that I can’t enter in the details of how our control algorithm are designed, but I can give you a few hints on how PCMD and wind compensation work :slight_smile:

When no specific command are sent to the anafi, it is in hovering mode, where the target is to stay at the same position. Hence this is a position control mode, which explains why the position is well controlled, even in presence of wind.

But if you sent a PCMD, 0,0,0,0 for example, to the drone control loops it means : " maintain a 0° roll angle, a 0° pitch angle, a 0m/s vertical velocity and a 0°/s yaw angular speed". But the trick is that then, a given angle is added to the pitch/roll command to compensate the wind, but this compensation is an estimation of how much angle is needed to counter the wind, and is not perfectly precise, which explains the random displacements of the drone you can witness. The wind compensation is designed so you will get the same behaviour for a given input whatever the wind direction and/or magnitude.

In brief : when you use a pcmd, you directly order the drone a pitch/roll angle, but the wind compensation is automatically added so you won’t necessarily get the exact pitch/roll you asked for, but its equivalent to have the same speed as if there was no wind. And by doing this, you bypass the precise position estimation and control, so this is more of an “open-loop” position control.
The random circular motion you get simply is the residual error of the wind compensation algorithm, which doesn’t really depend on the wind direction, that is why you see this behaviour for any wind direction.

Hope this answer your question,
Best regards,


@cdardas Thanks for the detailed answer!

May be you have an idea what is the most correct way to implement anafi “manual” control from the app, when commands from app reflects control sticks position instead of raw target RPY? When i first looked at PCMD i did hope that it would be analog of mavlinks RC_CHANNELS_OVERRIDE or “virtual sticks” of dji.

Now i use MoveBy for this task but it lacks of smoothness.

Best regards,
Mike Charikov

I use SkyControl connected to PC for communication. Not direct WIFI Network. As i read here (PCMD is repeated automatically with SkyController) there is a difference between SkyControl and WIFI

Thank you for the detailed answer. This is exactly what I observed when I give a constant magnitude, constant direction wind. The inner loop autopilot can sense the wind and fight against it.