# PX4 SITL target loses global position when the drone is being moved before takeoff

**URL:** <https://discuss.px4.io/t/px4-sitl-target-loses-global-position-when-the-drone-is-being-moved-before-takeoff/26101>\
**Category:** PX4 Autopilot\
**Created:** [February 8, 2022, 6:48pm UTC](https://discuss.px4.io/t/px4-sitl-target-loses-global-position-when-the-drone-is-being-moved-before-takeoff/26101 "2022-02-08T18:48:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![max11gen](https://discuss.px4.io/letter_avatar_proxy/v4/letter/m/db5fbb/32.png) [@max11gen](https://discuss.px4.io/u/max11gen)\
**Post date:** [February 8, 2022, 6:48pm UTC](https://discuss.px4.io/t/px4-sitl-target-loses-global-position-when-the-drone-is-being-moved-before-takeoff/26101/1 "2022-02-08T18:48:04Z")

</div>

I’m spawning an Iris MC controlled by a px4\_sitl\_default target in gazebo on a conveyor belt which is 10m long. Then I use a MAVSDK script to make the drone arm and fly a mission as soon as it was moved 7m by the conveyor belt. Unfortunately, when the drone takes off, it reports this:

```auto
|[07:36:31|Debug] MAVLink: emergency: Navigation failure! Land and recalibrate sensors| (system_impl.cpp:239)|
|---|---|
|[07:36:31|Debug] MAVLink: critical: Failsafe enabled: no global position| (system_impl.cpp:239)|
|[07:36:31|Debug] MAVLink: info: Failsafe mode activated| (system_impl.cpp:239)|
|[07:36:37|Debug] MAVLink: critical: Compass needs calibration - Land now!| (system_impl.cpp:239)|

```

And since the global position is lost, the drone doesn’t fly the mission properly. Instead it just drifts out of sight or sometimes crashes into the ground.  
The MAVSDK Script that I’m using, is basically just the `fly_mission` example from the MAVSDK repo. I only added a few lines to make the drone wait before taking off.  
Does anyone know what is happening here? Do I need to reset the EKF somehow before taking off?

EDIT:  
Here is a flight log of doing the same thing, but instead of using `fly_mission` I used `takeoff_and_land` , because in `fly_mission` no log is created, because the drone never lands.  
[https://logs.px4.io/plot\_app?log=f8b1659e-3987-436e-aa25-cbbaafd2ca22](https://logs.px4.io/plot_app?log=f8b1659e-3987-436e-aa25-cbbaafd2ca22)

---

<div class="post-metadata">

**Author:** ![bresch](https://discuss.px4.io/user_avatar/discuss.px4.io/bresch/32/2343_2.png) [@bresch](https://discuss.px4.io/u/bresch)\
**Post date:** [February 10, 2022, 9:19am UTC](https://discuss.px4.io/t/px4-sitl-target-loses-global-position-when-the-drone-is-being-moved-before-takeoff/26101/2 "2022-02-10T09:19:01Z")

</div>

Hi @max11gen,  
On the log you shared, the drone isn’t moving horizontally (looking at the GNSS velocity report) and the local/global position is always valid. I don’t see the failure you mentioned.  
The log should be there even if you don’t land.

---

<div class="post-metadata">

**Author:** ![max11gen](https://discuss.px4.io/letter_avatar_proxy/v4/letter/m/db5fbb/32.png) [@max11gen](https://discuss.px4.io/u/max11gen)\
**Post date:** [February 10, 2022, 1:37pm UTC](https://discuss.px4.io/t/px4-sitl-target-loses-global-position-when-the-drone-is-being-moved-before-takeoff/26101/3 "2022-02-10T13:37:46Z")

</div>

Hi @bresch , Thanks a lot for answering. You are right, in that log there is no problem with the global position, sorry for that. And I also figured out why I couldn’t find the logs of the `fly_mission` flights. So here is another log showing my problem: [https://logs.px4.io/plot\_app?log=1a486ae1-bc59-44bd-9a21-ac72bdd5ddfa](https://logs.px4.io/plot_app?log=1a486ae1-bc59-44bd-9a21-ac72bdd5ddfa)

The corresponding messages I received on the console this time are the following:

```auto
[02:31:42|Info] MAVSDK version: v1.0.8 (mavsdk_impl.cpp:28)
Waiting to discover system...
[02:31:42|Info] New system on: 127.0.0.1:14580 (with sysid: 1) (udp_connection.cpp:192)
[02:31:42|Debug] New: System ID: 1 Comp ID: 1 (mavsdk_impl.cpp:484)
[02:31:42|Debug] Component Autopilot (1) added. (system_impl.cpp:360)
[02:31:43|Debug] Discovered 1 component(s) (system_impl.cpp:528)
Discovered autopilot
Waiting for system to be ready
[02:31:43|Warn] command denied (512). (mavlink_commands.cpp:180)
System ready
Creating and uploading mission
Uploading mission...
[02:31:44|Debug] Falling back to gimbal protocol v1 (mission_impl.cpp:124)
Arming...
Armed.
[02:31:44|Debug] MAVLink: info: Armed by external command (system_impl.cpp:239)
[02:31:44|Debug] current: 0, total: 6 (mission_impl.cpp:931)
Mission status update: 0 / 6
[02:31:44|Debug] MAVLink: info: Takeoff to 10.0 meters above home (system_impl.cpp:239)
[02:31:45|Debug] MAVLink: info: Takeoff detected (system_impl.cpp:239)
[02:32:06|Debug] MAVLink: critical: Compass needs calibration - Land now! (system_impl.cpp:239)
[02:32:12|Debug] MAVLink: critical: Compass needs calibration - Land now! (system_impl.cpp:239)
[02:32:36|Debug] MAVLink: critical: Failsafe enabled: no global position (system_impl.cpp:239)
[02:32:36|Debug] MAVLink: info: Failsafe mode activated (system_impl.cpp:239)
[02:32:46|Debug] MAVLink: info: Landing detected (system_impl.cpp:239)
[02:32:46|Debug] MAVLink: info: Failsafe mode deactivated (system_impl.cpp:239)
[02:32:47|Debug] MAVLink: info: Takeoff to 10.0 meters above home (system_impl.cpp:239)
[02:32:47|Debug] MAVLink: info: Takeoff detected (system_impl.cpp:239)

```

For this experiment I used the plain example code from MAVSDK `fly_mission` and just waited a couple of seconds until the conveyor had moved the drone approximately 7m before starting `fly_mission`. If I do not wait and just instantly launch `fly_mission` and the drone is still very close to the starting position, there are no problems.  
Do you think uploading a screen video would help in making the problem more clear?

Here I uploaded another log of the same thing: [https://logs.px4.io/plot\_app?log=61889352-74cb-458c-b1dd-3c9c9a449c19](https://logs.px4.io/plot_app?log=61889352-74cb-458c-b1dd-3c9c9a449c19) . As you can see, the drone does different things every time, but the reason seems to be a loss of the global position.

---

<div class="post-metadata">

**Author:** ![bresch](https://discuss.px4.io/user_avatar/discuss.px4.io/bresch/32/2343_2.png) [@bresch](https://discuss.px4.io/u/bresch)\
**Post date:** [February 18, 2022, 9:53am UTC](https://discuss.px4.io/t/px4-sitl-target-loses-global-position-when-the-drone-is-being-moved-before-takeoff/26101/4 "2022-02-18T09:53:33Z")

</div>

To me it looks like the drone doesn’t even takeoff at the end of the conveyor belt. The estimate seems good until that point, then the drone falls off and the collisions in the sim are probably making the whole thing go nuts. Have you tried to do the takeoff manually (i.e.: using a gamepad or virtual joysticks)?
