<!DOCTYPE flight_plan SYSTEM "flight_plan.dtd">

<flight_plan alt="150" ground_alt="10" lat0="78.202961" lon0="15.8310" max_dist_from_home="3000" name="Nordlysstasjonen" qfu="270" security_height="60">
  <header>
#include "subsystems/navigation/nav_line.h"
#include "subsystems/datalink/datalink.h"
</header>
  <waypoints>
    <waypoint name="HOME" x="-0.3" y="-66.4"/>
    <waypoint name="1" x="23.4" y="122.0"/>
    <waypoint name="2" x="264.0" y="-6.8"/>
    <waypoint name="S1" x="-428.5" y="-438.0"/>
    <waypoint name="S2" x="352.9" y="376.6"/>
    <waypoint name="MOB" x="39.9" y="-90.3"/>
    <waypoint alt="131.0" name="CR" x="67.6" y="18.0"/>
    <waypoint alt="100.0" name="START" x="140.0" y="-156.5"/>
    <waypoint alt="130.0" name="_BASELEG" x="10.2" y="-220.3"/>
    <waypoint alt="130.0" name="AF" x="185.9" y="-47.2"/>
    <waypoint alt="20.0" name="TD" x="29.8" y="45.8"/>
    <waypoint name="PROF_LAND" x="168.6" y="36.4"/>
  </waypoints>
  <exceptions>
    <exception cond="GetPosAlt() > 5000"  deroute="wait"/>
    <exception cond="datalink_time > 140"  deroute="wait"/>
    <exception cond="10 > PowerVoltage()" deroute="wait"/>
  </exceptions>
  <blocks>
    <block name="start">
      <attitude pitch="20" roll="0" throttle="0.7" 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="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() > ground_alt + 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="Line 1-2" strip_button="Line (wp 1-2)" strip_icon="line.png">
      <call fun="nav_line_init()"/>
      <call fun="nav_line(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="200" 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="200" orientation="WE" wp1="S1" wp2="S2"/>
    </block>
    <block name="MOB" strip_button="Circle here" strip_icon="mob.png">
      <call fun="NavSetWaypointHere(WP_MOB)"/>
      <set value="DEFAULT_CIRCLE_RADIUS" var="nav_radius"/>
      <circle radius="nav_radius" wp="MOB"/>
    </block>
    <block name="profile_up land" strip_button="Profile Up Land" strip_icon="up_profile.png">
      <circle radius="nav_radius" wp="PROF_LAND"/>
    </block>
    <block name="profile_down land" strip_button="Profile Down Land" strip_icon="down_profile.png">
      <circle pitch="RadOfDeg(-10)" radius="nav_radius" throttle="0" until="(ground_alt+100 > GetPosAlt())" vmode="throttle" wp="PROF_LAND"/>
      <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="ground_alt + 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>
