<!DOCTYPE flight_plan SYSTEM "flight_plan.dtd">

<flight_plan alt="260" ground_alt="185" lat0="43.4622" lon0="1.2729" max_dist_from_home="1500" name="Dynamic sectors demo" qfu="270" security_height="25" home_mode_height="50">
  <header>
#include "subsystems/datalink/datalink.h"
</header>
  <waypoints>
    <waypoint name="HOME" x="0" y="0"/>
    <waypoint name="STDBY" x="20" y="80"/>
    <waypoint name="1" x="44.8" y="102.2"/>
    <waypoint alt="215.0" name="AF" x="200" y="-10"/>
    <waypoint alt="185.0" name="TD" x="80.0" y="20.0"/>
    <waypoint name="BASELEG" x="26.9" y="-23.0"/>
    <waypoint name="C1" x="-100" y="0"/>
    <waypoint name="C2" x="-100" y="200"/>
    <waypoint name="C3" x="100" y="200"/>
    <waypoint name="C4" x="100" y="0"/>
    <waypoint name="CLIMB" x="-122.5" y="35.4"/>
  </waypoints>
  <sectors>
    <sector name="Square" type="dynamic">
      <corner name="C1"/>
      <corner name="C2"/>
      <corner name="C3"/>
      <corner name="C4"/>
    </sector>
  </sectors>
  <exceptions/>
  <blocks>
    <block name="Wait GPS">
      <set value="1" var="autopilot.kill_throttle"/>
      <while cond="!GpsFixValid()"/>
    </block>
    <block name="Geo init">
      <while cond="LessThan(NavBlockTime(), 10)"/>
      <call_once fun="NavSetGroundReferenceHere()"/>
      <!--call_once fun="NavSetAltitudeReferenceHere()"/-->
    </block>
    <block name="Holding point">
      <set value="1" var="autopilot.kill_throttle"/>
      <attitude roll="0" throttle="0" vmode="throttle"/>
    </block>
    <block name="Takeoff" strip_icon="takeoff.png" strip_button="Takeoff (wp CLIMB)">
      <exception cond="GetPosAlt() > GetAltRef()+25" deroute="Standby"/>
      <set value="0" var="autopilot.kill_throttle"/>
      <go wp="CLIMB"/>
    </block>
    <block name="Standby" strip_button="Standby" strip_icon="home.png">
      <circle radius="nav_radius" wp="STDBY"/>
    </block>
    <block name="Fly in Square">
      <exception cond="! InsideSquare(GetPosX(), GetPosY())" deroute="Come back wp 1"/>
      <attitude alt="GetAltRef()+75" roll="0" vmode="alt"/>
    </block>
    <block name="Come back wp 1">
      <exception cond="InsideSquare(GetPosX(), GetPosY())" deroute="Fly in Square"/>
      <go wp="1"/>
      <deroute block="Fly in Square"/>
    </block>
    <block name="Land Right AF-TD" strip_button="Land right (wp AF-TD)" strip_icon="land-right.png">
      <set value="DEFAULT_CIRCLE_RADIUS" var="nav_radius"/>
      <deroute block="land"/>
    </block>
    <block name="Land Left AF-TD" strip_button="Land left (wp AF-TD)" strip_icon="land-left.png">
      <set value="-DEFAULT_CIRCLE_RADIUS" var="nav_radius"/>
      <deroute block="land"/>
    </block>
    <block name="land">
      <call_once fun="nav_compute_baseleg(WP_AF, WP_TD, WP_BASELEG, nav_radius)"/>
      <circle radius="nav_radius" until="NavCircleCount() > 0.5" wp="BASELEG"/>
      <set value="V_CTL_AUTO_THROTTLE_MIN_CRUISE_THROTTLE" var="v_ctl_auto_throttle_cruise_throttle"/>
      <circle radius="nav_radius" until="NavQdrCloseTo(DegOfRad(baseleg_out_qdr)-(nav_radius/fabs(nav_radius))*10) && 10 > fabs(GetPosAlt() - WaypointAlt(WP_BASELEG))" wp="BASELEG"/>
    </block>
    <block name="final">
      <exception cond="GetAltRef() + 10 > GetPosAlt()" deroute="flare"/>
      <go from="AF" hmode="route" vmode="glide" wp="TD"/>
    </block>
    <block name="flare">
      <go approaching_time="0" from="AF" hmode="route" throttle="0.0" vmode="throttle" wp="TD"/>
      <attitude roll="0.0" throttle="0.0" until="FALSE" vmode="throttle"/>
    </block>
  </blocks>
</flight_plan>
