Difference in positions between dronekit and SITL


I’m having a problem with dronekit and SITL: the localization (local location, wrt home location) that I get with SITL is different from the one I have with dronekit. And it’s very important for the application I’m trying to develop that both are identical.

To test this out, I’ve modified the file ~/ardupilot/libraries/SITL/SIM_Plane.cpp and added a simple line:
printf(“position NED from start: N:%f E:%f D:%f \n”, position.x, position.y, position.z);

In dronekit, I’ve modified the example “vehicle_state.py” to just always print the local position:
print " Local Location: %s" % vehicle.location.local_frame

And when I check the outputs of both files, I get a significant difference between both positions:

Do you guys have an idea of what causes this, and how I could fix it ?

Thx !

Up! I checked but it’s not due to a delay between SITL and dronekit. I tried to output the other types of locations (global, local in lat/long/alt form) but it doesn’t work either…

No ideas ?

I need to double check that later, but you are comparing two differents position : the first one is the internal position on SITL (simulation part) and the second is the local position calculated by the EKF (vehicle part).

Is there a way to access one of these positions in the other “part” ? So having the internal position in dronekit or the EKF in SITL ?

For the record, I am actually trying to simulate two drones flying in formation, so what I do is that I have an non-existing “leader” drone which position I hardcoded in SITL and I added the physics of the wake it generates and it’s effect on the “real” (=simulated by SITL) drone, which is the follower. So in dronekit (which is the follower drone), I was thinking to hardcode the same position, to “emulate” the follower’s sensors detecting the leader. But if the Location of the drone in SITL and dronekit are not identical, this “sensor” will detect that the leader is in a completely different location wrt to the follower, and it will therefore think that it is at some precise place in the wake, while it’s actually (in SITL) totally elsewhere.

I don’t know if that’s very clear, but I really need to have the exact position of the drone in dronekit and I can’t figure out how to do that. :pensive:

Hey khancyr,

Have you by any chance had the tim to check what you were talking about ? And is there a way to share one of these locations between the two ?

For anybody who would face the same problem, in dronekit you can create a MAVLink message listener for ‘SIMSTATE’, in which you will find the exact position (and much more) of the simulated drone in SITL.