<!DOCTYPE flight_plan SYSTEM "flight_plan.dtd">

<flight_plan alt="170" ground_alt="68" lat0="52.26483" lon0="9.99394" max_dist_from_home="1500" name="Gross Lobke Demo" qfu="270" security_height="60">
  <header>
#include "subsystems/datalink/datalink.h"
</header>
  <waypoints>
    <waypoint name="HOME" x="15.0" y="5.0"/>
    <waypoint name="1" x="-180." y="35."/>
    <waypoint name="2" x="156.8" y="22.3"/>
    <waypoint name="CR" x="0.0" y="160.0"/>
    <waypoint name="S1" x="-200" y="-200"/>
    <waypoint name="S2" x="300" y="400"/>
    <waypoint alt="140.0" name="START" x="-180" y="-0.0"/>
    <waypoint alt="68.0" name="TARGET" x="-56.9" y="7.8"/>
    <waypoint alt="68.0" name="TD" x="-2.3" y="18.2"/>
    <waypoint alt="120.0" name="AF" x="170.0" y="45.0"/>
    <waypoint alt="120.0" name="BASELEG" x="40." y="-130."/>
    <waypoint alt="120.0" name="_BASELEG" x="40." y="-130."/>
    <waypoint alt="120.0" name="RELEASE" x="40." y="-110."/>
    <waypoint alt="160.0" name="CLIMB" x="40." y="-90."/>
  </waypoints>
  <blocks>
    <block name="start">
      <attitude pitch="20" roll="0" throttle="0.8" until="(autopilot_flight_time > 3)" vmode="throttle"/>
      <go wp="START"/>
    </block>
    <block name="wait" strip_button="wait">
      <circle radius="nav_radius" wp="CR"/>
    </block>
    <block name="survey">
      <survey_rectangle grid="150" wp1="S1" wp2="S2"/>
    </block>
    <block name="Line 1-2" strip_button="Line (wp 1-2)" strip_icon="line.png">
      <call fun="nav_line_setup()"/>
      <call fun="nav_line_run(WP_1, WP_2, nav_radius)"/>
    </block>
    <block name="Oval 1-2" strip_button="Oval (wp 1-2)" strip_icon="oval.png">
      <oval p1="1" p2="2" radius="nav_radius"/>
    </block>
    <block name="Survey S1-S2 NS" strip_button="Survey (wp S1-S2) NS" strip_icon="survey.png">
      <survey_rectangle grid="150" wp1="S1" wp2="S2"/>
    </block>
    <block name="Survey S1-S2 WE" strip_button="Survey (wp S1-S2) WE" strip_icon="survey_we.png">
      <survey_rectangle grid="150" orientation="WE" wp1="S1" wp2="S2"/>
    </block>
    <block name="Figure 8 around wp 1" strip_button="Figure 8 (wp 1-2)" strip_icon="eight.png">
      <eight center="1" radius="nav_radius" turn_around="2"/>
    </block>
    <block name="down" strip_button="Down" strip_icon="downdown.png">
      <set value="LATERAL_MODE_ROLL" var="lateral_mode"/>
      <set value="V_CTL_MODE_MANUAL" var="v_ctl_mode"/>
      <set value="TRUE" var="h_ctl_disabled"/>
      <set value="(-0.6*MAX_PPRZ)" var="h_ctl_aileron_setpoint"/>
      <set value="(0.9*MAX_PPRZ)" var="h_ctl_elevator_setpoint"/>
      <while cond="GetPosAlt() > GetAltRef() + 220"/>
      <set value="0" var="h_ctl_aileron_setpoint"/>
      <set value="0" var="h_ctl_elevator_setpoint"/>
    </block>
    <block name="down_end" strip_button="DownEnd" strip_icon="downdownend.png">
      <set value="0" var="h_ctl_aileron_setpoint"/>
      <set value="0" var="h_ctl_elevator_setpoint"/>
      <while cond="1.> stage_time"/>
      <set value="FALSE" var="h_ctl_disabled"/>
      <deroute block="wait"/>
    </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 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="NavQdrCloseTo(DegOfRad(baseleg_out_qdr)-(nav_radius/fabs(nav_radius))*10) && 20 > 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>

    <!--block name="Bomb Right">
      <set value="DEFAULT_CIRCLE_RADIUS" var="nav_radius"/>
      <deroute block="bomb"/>
    </block>
    <block name="bomb" strip_button="Bomb">
      <set value="NavDropComputeApproach(WP_TARGET, WP_START, nav_radius)" var="unit"/>
      <circle radius="nav_radius" until="NavQdrCloseTo(DegOfRad(nav_drop_start_qdr)-10)" wp="BASELEG"/>
    </block>
    <block name="align">
      <exception cond="NavDropUpdateRelease(WP_TARGET)" deroute="wait"/>
      <go approaching_time="nav_drop_trigger_delay" from="START" hmode="route" wp="RELEASE"/>
    </block>
    <block name="shoot">
      <set value="NavDropShoot()" var="unit"/>
      <go from="RELEASE" hmode="route" wp="CLIMB"/>
      <set value="NavDropCloseHatch()" var="unit"/>
      <deroute block="wait"/>
    </block>
    <block name="close">
      <set value="NavDropCloseHatch()" var="unit"/>
      <deroute block="wait"/>
    </block-->

    <!--block NAME="roll" strip_button="Roll">
     <set value="TRUE" var="h_ctl_disabled"/>
     <set value="(-0.75*MAX_PPRZ)" var="h_ctl_aileron_setpoint"/>
     <while cond="3.> stage_time && (stateGetNedToBodyEulers_f()->phi > 0 || -M_PI_2 > stateGetNedToBodyEulers_f()->phi)"/>
     <set value="FALSE" var="h_ctl_disabled"/>
     <return/>
    </block-->

  </blocks>
</flight_plan>
