Developer

Ardupilot 2.5 preview part 4

Just like in the previous version of Ardupilot, throttle control maintains speed and altitude. I've made a little demo to help demystify the behavior of throttle control. This loop uses a special scaling feature that brings up the throttle to a high level when the airspeed dips below the desired cruising speed. Altitude of the plane is also maintained with the throttle by increasing the desired airspeed. Finally airspeed is scaled to match a throttle output %.Here is the Flash Source: PID Throttle.fla.zipNext installment: Events API
E-mail me when people leave their comments –

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

Join diydrones

Comments

  • Thanks Jason.
  • Developer
    Hi richard,
    I'll post an exe of the final set and you'll be able to run them like a local app.
  • Jason, Is there any way to save these animations (this one and Part 3) to hard disc so that I can run them off-line? I have downloaded the fla from the zip file but do not know how to run it. There was also not a zipfile for part 3.

    Keep up the good work

    Richard
  • OK I get it.

    A PID loop with a timer tick running that does the numerical integration.

    Input from controls and from mouse position (giving delta height and delta airspeed by mouse input)

    The code updates "text objects" that shows in the Flash application running.

    Some bounds checking as well and some number to string conversions etc.

    Very understandable, even if I am not a Java Script programmer.

    I like the possibilities that Flash gives since its way faster than Java applets (I know Jave is not the same as Java Script) that need to be downloaded. It is also much more responsive.

    I have some Flash and Flash programming on the future learning list.

    UFO_MAN
  • Developer
    I have this code inside the Flash file. It was quicker.
    This is the code:

    var e:Number;var err_I_a:Number = 0;
    var err_I:Number = 0;

    var airspeed_current:Number = 0;
    var altitude_current:Number = 0;
    var nav_airspeed:Number = 0;
    var throttle:Number = 0;
    var loopTimer:Number = 0;
    var deltaMiliSeconds:Number = 0;


    var THROTTLE_P:Number = 3;
    var THROTTLE_I:Number = 1;
    var THROTTLE_ABS:Number = 3;
    var altitude_throttle_P:Number = 1.33;

    var THROTTLE_CRUISE:Number = 30;

    var old_throttle_output:Number = 0;
    var ALTITUDE_AIRSPEED_MIN:Number = -15;
    var ALTITUDE_AIRSPEED_MAX:Number = 15;


    function calc_nav_airspeed(error:Number):Number
    {
    error = error * altitude_throttle_P;
    return constrain(error, ALTITUDE_AIRSPEED_MIN, ALTITUDE_AIRSPEED_MAX);// -15 : 15
    }

    function calc_attitude_throttle(error:Number):Number
    {
    input_TF.text = error.toString();

    var error_o:Number = error;
    var throttle_output:Number;

    err_I += (error * THROTTLE_I * deltaMiliSeconds)/1000.0;
    err_I = constrain(err_I, 0, 50);

    error_i_TF.text = err_I.toFixed(2);

    error = (THROTTLE_P * error) + err_I;
    error += (error_o * THROTTLE_ABS);
    error = constrain(error,0,88); //
    old_throttle_output = (old_throttle_output*.90) + (error *.10);

    return old_throttle_output; //Returns the result
    }



    stage.addEventListener(Event.ENTER_FRAME, update);


    stage.addEventListener(Event.ENTER_FRAME, update);

    function update(ev:Event){
    var now:Date = new Date();
    deltaMiliSeconds = now.time- loopTimer;
    loopTimer = now.time;

    THROTTLE_CRUISE = THROTTLE_CRUISE_input.value;
    THROTTLE_P = THROTTLE_P_input.value;
    THROTTLE_I = THROTTLE_I_input.value;
    THROTTLE_ABS = THROTTLE_ABS_input.value;

    altitude_throttle_P = altitude_throttle_P_input.value;

    var m_x:int = mouseX;
    var m_y:int = mouseY;
    m_x = Math.max(0,m_x);
    m_y = Math.min(100,m_y);

    airspeed_current = Math.round(m_x/10);
    altitude_current = Math.round(-m_y/5);
    airspeed_TF.text = airspeed_current.toString();

    e = Math.round(altitude_current);
    altitude_TF.text = e.toString()+" meters";

    airspeed_bar.x = m_x;
    altitude_bar.y = m_y;
    plane.x = m_x;
    plane.y = m_y;
    airspeed_TF.x = m_x + 5;
    altitude_TF.x = m_x + 30;
    altitude_TF.y = m_y + 30;


    nav_airspeed = calc_nav_airspeed(-altitude_current);
    throttle = THROTTLE_CRUISE + calc_attitude_throttle(THROTTLE_CRUISE + nav_airspeed - airspeed_current); // function located in control_attitude.pde

    e = Math.round((throttle/125)*100);
    throttle_TF.text = e.toString() +"% ";
    output_TF.text = old_throttle_output.toString();
    }


    function constrain(val:Number, low:Number, high:Number):Number
    {
    val = Math.max(val, low);
    val = Math.min(val, high);
    return val
    }
  • Nice! Thanks for sharing the code. Do I need he CS4 software to actually view the code? Tried top open it in a text editor, but no resemlance of Java Script in that editor :)

    UFO_MAN
  • Developer
    I posted the source above.
  • Developer
    This is done is Adobe Flash CS4. The inputs for the numbers are prebuilt components by adobe. Everything else is using the standard flash movieclip objects and textfield objects. It's written in javascript which is virtually the same as C++. I just copy in the control code from the ardupilot and tweak the data types.
    Unfortunately Flash is not a free tool and has a steep learning curve. But once you learn it, it is incredibly fast and graphically capable. I made this in about an hour.
  • Nice Flash software!

    Do you mind outlining the techniques you used to make the demo?
    How did you implement the controls?
    Are there existing class libraries available that programmers may reuse?


    UFO_MAN
This reply was deleted.