Local positions initialized not at zero

Good day

I am playing a bit with the Flight Tasks and as a starter I am trying to write my own HOLD controller. The image below is the results of a physical flight test with this controller and the green area is where my controller starts.

As you can see, the drone does not hold its altitude. Now I have a bit of confidence in my controller logic, as it does work perfectly in SITL, therefore, there must by something deeper going on. This is what I think is happening.

  1. For some reason, the drone starts at an altitude of z = 7.
  2. When the drone takes off using commander, it moves to z = 4 ( takeoff height is set to 3 m)
  3. At this moment the drone is at EKF local position z=4, but actual local position z=-3.
  4. Now I tell it to hold position (my HOLD mode). It therefore now moves to z = -3 (because according to the current controller it is at an altitude of 3 meters), which is actually 10 meters high.

This of course leads to some questions.

  • Why does the EKF initialize the local position at such a random place?
  • Is it possible to zero the local position before taking off?
  • If the local position is not the position used by the PX4 controllers, where can I find the position used.
  • For controlling my drone. What is the best way to get an accurate position estimate relative to my starting position?

To ensure that this weird initialization was not due to something else, I wanted to see what would happen if I just armed and disarmed the drone while it stood still on a table, and here is that result.

Once again it starts at a random height, but there is also a clear drift in the estimate.

If anyone has had similar problems or has an idea on how to fix it, I would greatly appreciate it.

The EKF initializes at 0 but it might drift from there. Generally, if you want to give local position setpoints, you will have to take the current position and then add your setpoint to that, rather than to 0.

The drift depends on what sensors you use and how good the signal is.