PX4 / PX4-Autopilot

PX4 Autopilot Software
https://px4.io
BSD 3-Clause "New" or "Revised" License
8.57k stars 13.55k forks source link

Takeoff setpoint position not set as current position #18155

Open edbyy opened 3 years ago

edbyy commented 3 years ago

Describe the bug Not sure if this is intended behavior or not but I’ve noticed that when moving the vehicle after initialization but prior to takeoff it will always try to return to the position it was initialized at instead of where the takeoff command was triggered. So basically I put the drone down, let Pixhawk initialize, then when everything is running and ready to fly I move the drone say a meter to the left, then when I trigger a takeoff command the drone will fly 1 meter back to the right. It happens every time in all directions. I am able to replicate this in SITL if I move the model a short enough distance that it doesn’t cause the position estimate to fail and reset. Upon takeoff the drone will immediately tilt and travel in the direction it was originally located at. For reference I am controlling the drone through mavlink using only VIO without a GPS.

To Reproduce

  1. Turn drone on
  2. Move drone
  3. Launch drone using takeoff mode
  4. Drone will fly back to where it was moved form

Expected behavior Drone should lock on to current position where takeoff mode was triggered.

dagar commented 3 years ago

What state is the vehicle in when you move it? Which mode? Is it armed or disarmed? Are you sending MAV_CMD_NAV_TAKEOFF or simply switching the vehicle to takeoff mode?

edbyy commented 3 years ago

@dagar I tried moving it in manual and position modes, always disarmed. I tried launching it with commander takeoff as well as using the mavsdk command drone.getAction().takeoff() which I believe sends MAV_CMD_NAV_TAKEOFF?

dagar commented 3 years ago

Do you happen to have a log? https://logs.px4.io/

edbyy commented 3 years ago

Sure: https://logs.px4.io/plot_app?log=e04a4cc6-1fa3-44ed-869c-bee3b297b43d

edbyy commented 3 years ago

Here is another log, this one shows the second flight on the same battery; it was flown once, landed, then another takeoff was triggered without moving the drone from where it landed and it still shot back without locking on to the new position: https://review.px4.io/plot_app?log=a15d9457-1ab1-4c2f-baee-30f668b91319

edbyy commented 3 years ago

It seems that it's just simply going back to (0, 0). I've been digging through the code to try and understand how takeoff works so pardon if this is a dumb question as I'm still wrapping my head around it all, but is this where the takeoff position is set? https://github.com/PX4/PX4-Autopilot/blob/v1.11.3/src/modules/navigator/navigator_main.cpp#L344:L386 It seems to only use latitude and longitude which means during takeoff no other position sources besides GPS are used? This might explain the issue I'm experiencing.