Wrong Parameter Configuration caused ArduCopter do not landing in RTL Mode

----------------------------------------------------- Bug Description -----------------------------------------------------
Dear developers,
We are security researchers. We have found a bug in ArduCopter. The bug causes the ArduCopter to move around and don’t descend for landing in RTL mode.
Here are the reproduction steps in SITL(software in the Loop).

  1. Set configuration parameters into these values
PSC_VELXY_P = 0.1
PSC_VELXY_I = 1.0
PSC_VELXY_D = 0.5
WPNAV_RADIUS = 200
  1. Arm the ArduCopter, set the ArduCopter into Guided Mode, and let the Copter fly from the HOME LOCATION to the target mission point P = (-35.36167886683688, 149.16288293978604) 100.0.
  2. After the Copter has reached the target mission point P, turn the Copter into RTL(Return From Home) mode.

Then the bug shows. Here are detailed buggy behaviors of the ArduCopter. After step 2, the ArduCopter is in Guided mode, it moves in a straight line at the beginning but gradually moves in a winding track. After step 3, the ArduCopter flies back to the home location on a winding track and nears the point right above the home location. As the document says, the ArduCopter will hover above the home location within RTL_LOIT_TIME seconds, then descend and land. However, the ArduCopter moves around the point above the home location and doesn’t descend for landing.

------------------------------------------------- Root Cause Analysis -------------------------------------------------
We examine the source code of ArduCopter RTL mode to find the root cause of that bug. The root cause of that bug can be summarized as follows:

  1. The ArduCopter RTL mode follows a state machine model. When the state switch condition is satisfied, the ArduCopter switches its state from approaching the waypoint above the HOME location to descending and landing.
  2. The Arducopter flying control module calculates the distance between the current location of the Arducopter to the target waypoint and compares the distance with a predefined threshold. The state switch condition is satisfied if the distance is less than or equal to the threshold.
  3. In our bug case, we have set the PID parameter of the flight controller to a valid but inappropriate value. The inappropriate PID setting makes the control of ArduCopter unstable so that the ArduCopter oscillates around the target waypoint.
  4. The oscillation of ArduCopter causes the distance from the current location to the waypoint target to always be greater than the predefined threshold. Since the state switch condition never be satisfied, the ArduCopter sticks at the waypoint approaching the state and does not descend.

-----------------------------------------Bug fix suggestion----------------------------------------------------------------
We suggest developers to add a timeout mechanism to the check of switch condition. For example, a constant value rtl_timeout represents the timeout of RTL mode. After rtl_timeout seconds has passed, the climb_return_run state complete and the ArduCopter begins to descend.

``` Code snippet climb_return_run()
void ModeRTL::climb_return_run()
{
    // ...
    // check if we've completed this stage of RTL
    _state_complete = (current_time - climb_return_begin_time > rtl_timeout) || wp_nav->reached_wp_destination();
}

Thatks, but please do understand that we will not fix bugs in ArduCopter 4.1.x version.

If you can reproduce that “bug” in ArduCopter 4.4.4 or on ArduCopter master branch, we will look at it.

We are sorry that we have used an old version of ArduCopter. This morning we have reproduced the found bug in the ArduCopter master branch. Here is the screenshot of the bug case.

Welcome to the community and thanks for the report.