<!DOCTYPE flight_plan SYSTEM "flight_plan.dtd">

<flight_plan alt="260" ground_alt="185" lat0="43.46223" lon0="1.27289" max_dist_from_home="1500" name="Fixed wing basic (Muret)" security_height="25">
  <header>

</header>
  <waypoints>
    <waypoint name="HOME" x="0" y="0"/>
    <waypoint alt="235" name="STDBY" x="49.5" y="100.1"/>
    <waypoint alt="215.0" name="AF" x="177.4" y="45.1"/>
    <waypoint alt="185.0" name="TD" x="28.8" y="57.0"/>
    <waypoint name="_BASELEG" x="168.8" y="-13.8"/>
    <waypoint name="CLIMB" x="-114.5" y="162.3"/>
    <waypoint alt="235.0" name="ELLIPSE" x="0.5" y="109.0"/>
    <waypoint alt="235.0" name="S1" x="-14.8" y="157.8"/>
    <waypoint alt="235.0" name="S2" x="175.7" y="85.2"/>
    <waypoint alt="235.0" name="S3" x="140.0" y="-2.3"/>
    <waypoint alt="235.0" name="S4" x="-49.6" y="66.3"/>
  </waypoints>

  <sectors>
    <sector color="orange" name="Survey">
      <corner name="S1"/>
      <corner name="S2"/>
      <corner name="S3"/>
      <corner name="S4"/>
    </sector>
  </sectors>

  <variables>
    <variable var="angle_ps" init="0" min="-180" max="179" step="1"/>
  </variables>

  <modules> 
    <module name="gvf_module"/>
  </modules>

  <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()"/>
    </block>
    <block name="Holding point">
      <set value="1" var="autopilot.kill_throttle"/>
      <attitude roll="0" throttle="0" vmode="throttle"/>
    </block>
    <block group="home" key="t" name="Takeoff" strip_button="Takeoff (wp CLIMB)" strip_icon="takeoff.png">
      <exception cond="GetPosAlt() > GetAltRef()+25" deroute="Standby"/>
      <set value="0" var="autopilot.kill_throttle"/>
      <set value="0" var="autopilot.flight_time"/>
      <go from="HOME" pitch="15" throttle="1.0" vmode="throttle" wp="CLIMB"/>
    </block>
    <block group="home" key="Ctrl+a" name="Standby" strip_button="Standby" strip_icon="home.png">
      <call_once fun="NavVerticalAutoThrottleMode(0.0)"/>
      <call_once fun="NavVerticalAltitudeMode(flight_altitude, 0.0)"/>
      <call fun="gvf_ellipse_wp(WP_STDBY, nav_radius, nav_radius, 0)"/>
    </block>
    <block name="ellipse">
      <call fun="gvf_ellipse_wp(WP_ELLIPSE, gvf_ellipse_par.a, gvf_ellipse_par.b, gvf_ellipse_par.alpha)"/>
    </block>
    <block name="segment_loop">
      <call fun="gvf_segment_loop_wp1_wp2(WP_ELLIPSE, WP_STDBY, gvf_segment_par.d1, gvf_segment_par.d2)"/>
    </block>
    <block name="segment">
      <call fun="gvf_segment_wp1_wp2(WP_ELLIPSE, WP_STDBY)"/>
    </block>
    <block name="line">
      <call fun="gvf_line_wp_heading(WP_ELLIPSE, gvf_line_par.heading)"/>
    </block>
    <block name="Sinusoidal">
    <call fun="gvf_sin_wp_alpha(WP_ELLIPSE, gvf_sin_par.alpha, gvf_sin_par.w, gvf_sin_par.off, gvf_sin_par.A)"/>
    </block>
    <block name="Poly Survey">
      <call_once fun="gvf_nav_survey_polygon_setup(WP_S1, 4, angle_ps, 30, 30, 40, flight_altitude)"/>
      <call fun="gvf_nav_survey_polygon_run()"/>
    </block>
    <block group="land" 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 group="land" 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"/>
      <circle radius="nav_radius" until="And(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>
