<?xml version="1.0" encoding="UTF-8"?>
<Mission xmlns="Tethys"
       xmlns:Control="Tethys/Control"
       xmlns:Guidance="Tethys/Guidance" 
       xmlns:Units="Tethys/Units"
       xmlns:Universal="Tethys/Universal"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="Tethys http://aosn.mbari.org/tethys/Xml/Tethys.xsd
                           Tethys/Control http://aosn.mbari.org/tethys/Xml/Control.xsd
                           Tethys/Guidance http://aosn.mbari.org/tethys/Xml/Guidance.xsd
                           Tethys/Units http://aosn.mbari.org/tethys/Xml/Units.xsd
                           Tethys/Universal http://aosn.mbari.org/tethys/Xml/Universal.xsd"
       Id="Hawaii">

<!-- some high priority behaviors -->

    <Guidance:AltitudeEnvelope RunIn="Parallel">
        <Setting><Guidance:AltitudeEnvelope.minAltitude/><Units:meter/><Value>20</Value></Setting>
    </Guidance:AltitudeEnvelope>

    <Guidance:OffshoreEnvelope RunIn="Parallel">
        <Setting><Guidance:OffshoreEnvelope.minOffshore/><Units:kilometer/><Value>1</Value></Setting>
        <Setting><Guidance:OffshoreEnvelope.maxOffshore/><Units:kilometer/><Value>4000</Value></Setting>
    </Guidance:OffshoreEnvelope>

    <Guidance:DepthEnvelope RunIn="Parallel">
        <Setting><Guidance:DepthEnvelope.minDepth/><Units:meter/><Value>0</Value></Setting>
        <Setting><Guidance:DepthEnvelope.maxDepth/><Units:meter/><Value>300</Value></Setting>
    </Guidance:DepthEnvelope>

<!--    Run at high speed -->

    <Guidance:SetSpeed RunIn="Parallel">
        <Setting><Guidance:SetSpeed.period/><Units:millisecond/><Value>2000</Value></Setting>
    </Guidance:SetSpeed>

<!-- GPS (and Iridium) Update 
     Once an hour or once every kilometer, if we're near the surface, 
     Or once every two hours or once every two km if we are deeper 
     Iridium kicks off approximately every four hours -->

    <Insert Filename="Insert/Surface.xml" Id="SurfaceComms" />

    <Aggregate Id="NeedSatFix">

<!--    Going to the surface is preemptive only if fix is very old or uninitialized
        This is a workaround for something that should be handled in the code...  
        i.e., avoiding executing the Waypoint command before we know where we are -->

        <Preemptive><Elapsed><Universal:time_fix/></Elapsed><Gt/><Units:day/><Value>30</Value></Preemptive>

        <When><Universal:platform_pitch_angle/>
            <Gt/><Units:degree/><Value>0</Value>
            <And>
                <Elapsed><Universal:time_fix/></Elapsed>
                <Gt/><Units:minute/><Value>30</Value>
                <Or>
                    <Elapsed><Universal:platform_communications/></Elapsed>
                    <Gt/><Units:minute/><Value>30</Value>
                </Or>
            </And>
            <Or>
                <Elapsed><Universal:time_fix/></Elapsed>
                <Gt/><Units:minute/><Value>60</Value>
            </Or>
            <Or>
                <Elapsed><Universal:platform_communications/></Elapsed>
                <Gt/><Units:minute/><Value>60</Value>
            </Or>
        </When>

        <Call RefId="SurfaceComms"/>

    </Aggregate>

<!-- A set of commands to repeat over and over -->

    <Aggregate Id="RepeatOps" Repeat="1" >

        <ReadData>
            <Universal:sea_water_salinity/>
            <Universal:sea_water_temperature/>
        </ReadData>

        <Guidance:DepthEnvelope RunIn="Parallel">
            <Setting><Guidance:DepthEnvelope.minDepth/><Units:meter/><Value>5</Value></Setting>
        </Guidance:DepthEnvelope>

        <Guidance:SetSpeed RunIn="Parallel">
            <Setting><Guidance:SetSpeed.speed/><Units:meter_per_second/><Value>1</Value></Setting>
        </Guidance:SetSpeed>

        <Guidance:YoYo RunIn="Parallel"/>

<!--    head west -->

        <Aggregate Id="West">

            <Guidance:Waypoint Id="WaypointW1" RunIn="Sequence">
                <Setting><Guidance:Waypoint.latitude/><Units:degree/><Value>20.7</Value></Setting>
                <Setting><Guidance:Waypoint.longitude/><Units:degree/><Value>-155.5</Value></Setting>
            </Guidance:Waypoint>

        </Aggregate>

<!--    head through -->

        <Aggregate Id="BigIsland">

            <Guidance:Waypoint Id="WaypointW2" RunIn="Sequence">
                <Setting><Guidance:Waypoint.latitude/><Units:degree/><Value>19.95</Value></Setting>
                <Setting><Guidance:Waypoint.longitude/><Units:degree/><Value>-156.8</Value></Setting>
            </Guidance:Waypoint>

        </Aggregate>

<!--    head around -->

        <Aggregate Id="Around">

            <Guidance:Waypoint Id="WaypointW3" RunIn="Sequence">
                <Setting><Guidance:Waypoint.latitude/><Units:degree/><Value>18.3</Value></Setting>
                <Setting><Guidance:Waypoint.longitude/><Units:degree/><Value>-156.0</Value></Setting>
            </Guidance:Waypoint>

        </Aggregate>

<!--    head around -->

        <Aggregate Id="SouthEast">

            <Guidance:Waypoint Id="WaypointW4" RunIn="Sequence">
                <Setting><Guidance:Waypoint.latitude/><Units:degree/><Value>19.3</Value></Setting>
                <Setting><Guidance:Waypoint.longitude/><Units:degree/><Value>-153.6</Value></Setting>
            </Guidance:Waypoint>

        </Aggregate>

<!--    head home -->

        <Aggregate Id="East">

            <Guidance:Waypoint Id="WaypointW5" RunIn="Sequence">
                <Setting><Guidance:Waypoint.latitude/><Units:degree/><Value>36.737845</Value></Setting>
                <Setting><Guidance:Waypoint.longitude/><Units:degree/><Value>-121.8904227</Value></Setting>
            </Guidance:Waypoint>

        </Aggregate>

    </Aggregate>

</Mission>
