<!DOCTYPE flight_plan SYSTEM "flight_plan.dtd">

<flight_plan ground_alt="0" alt="75" lat0="43.2375" lon0="1.3277" max_dist_from_home="3500" name="Intelligent Surveillance" qfu="270" security_height="35">
<header>
#include "chemo_detect.h"
#include "anemotaxis.h"
#include "chemotaxis.h"
#include "discsurvey.h"
#include "nav_line.h"
#include "bomb.h"
#include "datalink.h"
</header>
  <waypoints>
    <waypoint name="HOME" x="0" y="0"/>
    <waypoint name="AF" x="200" y="-10" alt="215"/>
    <waypoint name="TOD" x="-150" y="0"/>
    <waypoint name="TD" x="80" y="20" alt="185"/>
    <waypoint name="1" x="-75" y="75"/>
    <waypoint name="2" x="75" y="75"/>
    <waypoint name="MOB" x="200" y="200"/>
    <waypoint name="S1" x="-200" y="-200"/>
    <waypoint name="S2" x="300" y="400"/>
    <waypoint name="C" x="-250" y="-200"/>
    <waypoint name="C1" x="-250" y="-200"/>
    <waypoint name="C2" x="350" y="400"/>
    <waypoint name="PLUME" x="400" y="300"/>
    <waypoint name="BASELEG" x="400" y="350"/>
    <waypoint name="CAM_TARGET" x="100" y="-200" alt="0"/>
  </waypoints>
  <blocks>
    <block name="wait GPS">
      <while cond="!GpsFixValid()"/>
    </block>

    <block name="init">
      <while cond="LessThan(NavBlockTime(), 10)"/>
      <call fun="NavSetGroundReferenceHere()"/>
      <deroute block="wait"/>
    </block>

    <block name="wait" strip_button="0">
      <circle radius="nav_radius" wp="1"/>
    </block>

    <block name="ground speed">
<!--      <exception cond="nav_ground_speed_loop()" deroute="ground speed"/> -->
      <circle radius="nav_radius" wp="1"/>
    </block>

    <block name="eight 1" strip_button="8">
      <eight radius="nav_radius" center="1" turn_around="2"/>
    </block>

    <block name="Line">
         <call fun="nav_line_init()"/>
         <call fun="nav_line(WP_1, WP_2, nav_radius)"/>
    </block>


    <block name="oval">
      <oval p1="1" p2="2" radius="nav_radius"/>
    </block>

    <block name="MOB" strip_button="MOB">
      <call fun="NavSetWaypointHere(WP_MOB)"/>
      <circle wp="MOB" radius="nav_radius"/>
    </block>

    <block name="Anemotaxis" strip_button="Anem">
      <call fun="nav_anemotaxis_downwind(WP_C, 300)"/>
      <go from="HOME" wp="C" hmode="route" approaching_time="0"/>
      <call fun="nav_anemotaxis_init(WP_C)"/>
      <call fun="nav_anemotaxis(WP_C, WP_C1, WP_C2, WP_PLUME)"/>
    </block>

    <block name="Chemotaxis">
      <call fun="nav_chemotaxis_init(WP_C, WP_PLUME)"/>
      <call fun="nav_chemotaxis(WP_C, WP_PLUME)"/>
    </block>

    <block name="ChemotaxisHere">
      <set var="waypoints[WP_C].x" value="estimator_x"/>
      <set var="waypoints[WP_C].y" value="estimator_y"/>
      <deroute block="Chemotaxis"/>
    </block>

    <block name="Disc survey" strip_button="DS">
      <exception cond="chemo_sensor > 0" deroute="ChemotaxisHere"/>
      <call fun="disc_survey_init(150)"/>
      <call fun="disc_survey(WP_HOME, 350)"/>
    </block>

<!--
    <block name="circle 1 auto pitch">
      <circle radius="75" wp="1" pitch="auto" throttle="0.7"/>
    </block>
-->

    <block name="far away">
      <exception cond="datalink_time > 22" deroute="wait"/>
      <go approaching_time="0" from="1" hmode="route" wp="2"/>
      <go approaching_time="0" from="2" hmode="route" wp="1"/>
    </block>

    <block name="circle left 1">
      <circle radius="-75" wp="1"/>
    </block>

    <block name="climb 75">
      <circle radius="50+(estimator_z-ground_alt)/2" wp="1" throttle="0.75" pitch="15" vmode="throttle" until="10 > PowerVoltage()"/>
    </block>

    <block name="climb 1">
      <circle radius="50+(estimator_z-ground_alt)/2" wp="1" climb="1" pitch="5" vmode="climb" until="10 > PowerVoltage()"/>
    </block>

    <block name="descent 0">
      <circle radius="50+(estimator_z-ground_alt)/2" wp="1" throttle="0.0" pitch="-15" vmode="throttle" until="ground_alt+50 > estimator_z"/>
      <deroute block="wait"/>
    </block>

    <block name="route12">
      <go approaching_time="0" from="1" hmode="route" wp="2"/>
    </block>

    <block name="glide12">
      <go from="1" hmode="route" vmode="glide" wp="2"/>
    </block>

    <block name="stack 2">
      <circle radius="75" wp="2"/>
    </block>

    <block name="route21">
      <go approaching_time="0" from="2" hmode="route" wp="1"/>
    </block>

    <block name="stack 1">
      <circle radius="75" wp="1"/>
    </block>

    <block name="survey">
      <survey_rectangle grid="nav_survey_shift" wp1="S1" wp2="S2"/>
    </block>

   <block name="land">
      <call fun="nav_compute_baseleg(WP_AF, WP_TD, WP_BASELEG)"/>
      <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)-10) && 10 > fabs(estimator_z - WaypointAlt(WP_BASELEG))"
              wp="BASELEG"/>
    </block>

    <block name="final">
      <exception cond="ground_alt + 10 > estimator_z" 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>
