Enable RTL even if landed
Describe problem solved by this pull request
While testing pacakge delivery mission with RTL as one of the mission items, I noticed the following:
- RTL doesn't work if the vehicle is landed
- As soon as the vehicle lands, the land disarm timeout
COM_DISARM_LANDisn't taken into account and vehicle disarms rightaway
Describe your solution
First, I added a condition where if the RTL destination is not where we are at (with the error margin of NAV_ACC_RAD in meters), to keep the original behavior of not doing RTL in case: we are landed at the RTL destination, but allowing RTL if the destination isn't where the vehicle is landed at.
This case can easily be imagined with a package delivery mission, where an operator puts LAND, RTL mission items in sequence and expects the vehicle to return automatically. With previous code, it would never allow RTL to happen since vehicle was landed. In this case, operator may lose the vehicle :exploding_head:
Second, during the test I found edge case where the vehicle's nav_state comes out of the NAVIGATION_STATE_AUTO_MISSION while landed, and enters the condition where automatic disarming while landed starts to count (hysteresis). Here, since the flag for the hysteresis was never getting reset to False.
And the hysteresis object is shared by two different "disarm when laded" conditions (Preflight & generic land after flight cases), the previous Preflight case' would already set the internal requested state to True (until the moment vehicle took off), and when vehicle landed again, there of course has been more than ~10 seconds (COM_DISARM_LAND value) of time in between, so the vehicle disarmed immediately.
I solved this by setting the state to False if we don't enter any of the hysteresis conditions.
Test data / coverage
Before the change:

After the change:
Vehicle doesn't disarm after landing, and RTLs automatically as part of the mission.
How to test
-
Build SITL
make px4_sitl jmavsim HEADLESS=1 -
Upload the Mission via QGC and execute the mission. Here's the mission plan I used:

How does this work on a fw vehicle? Would it still rtl and takeoff? That could be dangerous.
Where does this sit with https://github.com/PX4/PX4-Autopilot/pull/20172? Still wanted?
There was a discussion that this is dangerous in general from @MaEtUgR as well if I recall correctly. However, currently 'Waypoint' mission item when vehicle is landed will result in vehicle taking off.
I think it's a bit weird to just restrict RTL when the waypoint item works. Any thoughts on this? For Fixed-wing I agree that this shouldn't be the case.