about the part of code on auto landing

Hi Everyone:

I am looking at the arducopter 2.0.55 code, trying to know in detail how the auto landing works. The following is verify_land function.

I found it difficult to understand the blue sentences.  It says "land at 1 meter per second", but the first equation does not seem so.  Also, in the second equation, why the velocity_land is updated like that? what is the physical meaning? In my understanding, the velocity_land drops gradually when it approaches the ground, is that correct?

Thank you in advance.

static bool verify_land()
    // land at 1 meter per second
    next_WP.alt  = original_alt - ((millis() - land_start) / 20);            // condition_value = our initial

    velocity_land  = ((old_alt - current_loc.alt) *.2) + (velocity_land * .8);
    old_alt = current_loc.alt;

        // decide which sensor we're using
        if(sonar_alt < 300){
            next_WP = current_loc; // don't pitch or roll
            next_WP.alt = -200; // force us down
        if(sonar_alt < 40){
            land_complete = true;
            //return true;

    if(velocity_land <= 0){
        land_complete = true;
        //return true;
    //Serial.printf("N, %d\n", velocity_land);
    //Serial.printf("N_alt, %ld\n", next_WP.alt);

    return false;

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –


  • Developer

    The landing code has changed/ improved a bit in the latest 2.1.

    Now it works without sonar.

    It doesn't try to hold a position as it doe the last two meters. This was causing minor flips as it hit the ground while tilted.

    Instead, it simply levels out and drops.

    Velocity land is just filtered climb rate calculation. It's filtered so the numbers don't jump too much and if it settles into 0 it's prob on the ground. The Baro is almost too noisy though to truly detect this. 

    The function does not return true right now until we get a better landing notification system in place to shut off the motors etc. This makes it the defacto end of a mission as this step will never return finished.

    If we had a better and more reliable landing sensor, we could takeoff and continue a mission. RIght now it's not worth the false positives and 95% of missions would end anyway in a landing.


  • I wrote some Mathematica code to visualize the math for myself:

    c1 is the 0.2 in the code:

     velocity_land  = ((old_alt - current_loc.alt) *.2) + (velocity_land * .8); 

    Plot below shows why it is that value, the yellow meshed surface is the landing velocity, it is guaranteed to be 1 if c1 is less 0.5 actually around 0.25 or so :


    For full visualization and code see:


    You need to download the Mathematica pluggin:


  • I have not looked at the code at large, but this might help to explain the math:

    Set velocity_land =1 in eq below

       velocity_land  = ((old_alt - current_loc.alt) *.2) + (velocity_land * .8); 


        1  = ((old_alt - current_loc.alt) *.2) + (1 * .8); 


    .2 = ((old_alt - current_loc.alt) *.2) 

    1 = old_alt - current_loc.alt 

    u get the desired speed of landing  1 meter per second:

    old_alt - current_loc.alt = 1

    For the last if to work, i.e. if(velocity_land <= 0),  same equation applies

    Set velocity_land =0 in eq below

       velocity_land  = ((old_alt - current_loc.alt) *.2) + (velocity_land * .8); 

    You get

     0  = ((old_alt - current_loc.alt) *.2) + 0; 


    old_alt - current_loc.alt = 0

    or you already landed!


    velocity_land  = ((old_alt - current_loc.alt) *.2) + (velocity_land * .8); 

    is used because there is no exact equation for controlling landing in general, so you use an iterative approximation to the three  final solutions which are 1 and 0 and < 0 for velocity_land. These are known as heuristic solutions e.g. newton-raphson. 

    As for .8 and .2, you could have chosen any two numbers a and b such that a + b = 1. But the .8 i.e. the larger number yields smaller velocity_land so the copter can land with lower velocity or the iterative method yield a solution faster (in less iterations).

    I could be wrong but I am sure others here know a lot better explanation than this. 


  • I am missing out your express. The landings has alway been good. However the Auto take off's can wipe away an observer if in th wrong position.

This reply was deleted.