<?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="doest">

<!-- Wpt1 d=42m; Wpt2 d=95m; Wpt3 d=121m -->

    <DefineArg Name="ApproachDepth"><Units:meter/><Value>5.0</Value></DefineArg>

    <DefineArg Name="YoYoMinDepth"><Units:meter/><Value>5.0</Value></DefineArg>

    <DefineArg Name="YoYoMaxDepth"><Units:meter/><Value>15.0</Value></DefineArg>

    <DefineArg Name="YoYoUpPitch"><Units:degree/><Value>20.0</Value></DefineArg>

    <DefineArg Name="YoYoDownPitch"><Units:degree/><Value>-20.0</Value></DefineArg>

    <DefineArg Name="Wpt1Lat"><Units:degree/><Value>36.80732</Value></DefineArg>

    <DefineArg Name="Wpt1Lon"><Units:degree/><Value>-121.826513</Value></DefineArg>

    <DefineArg Name="Wpt2Lat"><Units:degree/><Value>36.80732</Value></DefineArg>

    <DefineArg Name="Wpt2Lon"><Units:degree/><Value>-121.827194</Value></DefineArg>

    <DefineArg Name="Wpt3Lat"><Units:degree/><Value>36.80732</Value></DefineArg>

    <DefineArg Name="Wpt3Lon"><Units:degree/><Value>-121.830331</Value></DefineArg>

    <DefineArg Name="Wpt4Lat"><Units:degree/><Value>36.80732</Value></DefineArg>

    <DefineArg Name="Wpt4Lon"><Units:degree/><Value>-121.831280</Value></DefineArg>

    <Timeout Duration="P160M"/>

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

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

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

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

<!-- GPS Update.  Don't go too long w/o a GPS fix. -->

    <Aggregate Id="NeedComms">

        <When><Universal:platform_pitch_angle/>
            <Gt/><Units:degree/><Value>0</Value>
            <And>
                <Elapsed><Universal:time_fix/></Elapsed>
                <Gt/><Units:minute/><Value>15</Value>
            </And>
            <Or>
                <Elapsed><Universal:time_fix/></Elapsed>
                <Gt/><Units:minute/><Value>17</Value>
            </Or>
        </When>

        <Call Id="NEEDCOMMS" RefId="SURFACECOMMS"/>

    </Aggregate>

<!-- If we're executing here or below, lets' get science data! -->

    <Insert Filename="Insert/Science.xml"/>

    <Guidance:Buoyancy RunIn="Parallel">
        <Setting><Guidance:Buoyancy.position/><Units:cubic_centimeter/><Value>100</Value></Setting>
    </Guidance:Buoyancy>

    <Aggregate Id="WaypointOne">

<!-- Go to Wpt1 and start from there -->

        <Guidance:Pitch RunIn="Parallel">
            <Setting><Guidance:Pitch.depth/><Arg Name="ApproachDepth"/></Setting>
        </Guidance:Pitch>

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

        <Guidance:Waypoint Id="WaypointW1" RunIn="Sequence">
            <Setting><Guidance:Waypoint.latitude/><Arg Name="Wpt1Lat"/></Setting>
            <Setting><Guidance:Waypoint.longitude/><Arg Name="Wpt1Lon"/></Setting>
        </Guidance:Waypoint>

        <Call Id="PHONEHOMEWPT1" RefId="SURFACECOMMS"/>

    </Aggregate>

    <Aggregate Id="TestDrive" >

        <Aggregate Id="ApprchWpt2">

            <Guidance:Pitch RunIn="Parallel">
                <Setting><Guidance:Pitch.depth/><Arg Name="ApproachDepth"/></Setting>
            </Guidance:Pitch>

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

            <Guidance:Waypoint Id="WaypointW2" RunIn="Sequence">
                <Setting><Guidance:Waypoint.latitude/><Arg Name="Wpt2Lat"/></Setting>
                <Setting><Guidance:Waypoint.longitude/><Arg Name="Wpt2Lon"/></Setting>
            </Guidance:Waypoint>

        </Aggregate>

        <Aggregate Id="YoyoToWpt3">

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

            <Guidance:DepthEnvelope RunIn="Parallel">
                <Setting><Guidance:DepthEnvelope.minDepth/><Arg Name="YoYoMinDepth"/></Setting>
                <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="YoYoMaxDepth"/></Setting>
                <Setting><Guidance:DepthEnvelope.downPitch/><Arg Name="YoYoDownPitch"/></Setting>
                <Setting><Guidance:DepthEnvelope.upPitch/><Arg Name="YoYoUpPitch"/></Setting>
            </Guidance:DepthEnvelope>

            <Guidance:YoYo RunIn="Parallel">
                <Setting><Guidance:YoYo.downPitch/><Arg Name="YoYoDownPitch"/></Setting>
                <Setting><Guidance:YoYo.upPitch/><Arg Name="YoYoUpPitch"/></Setting>
            </Guidance:YoYo>

            <Guidance:Waypoint Id="Wpt3" RunIn="Sequence">
                <Setting><Guidance:Waypoint.latitude/><Arg Name="Wpt3Lat"/></Setting>
                <Setting><Guidance:Waypoint.longitude/><Arg Name="Wpt3Lon"/></Setting>
            </Guidance:Waypoint>

            <Aggregate Id="ApprchWpt4">

                <Guidance:Pitch RunIn="Parallel">
                    <Setting><Guidance:Pitch.depth/><Arg Name="ApproachDepth"/></Setting>
                </Guidance:Pitch>

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

                <Guidance:Waypoint Id="WaypointW2" RunIn="Sequence">
                    <Setting><Guidance:Waypoint.latitude/><Arg Name="Wpt4Lat"/></Setting>
                    <Setting><Guidance:Waypoint.longitude/><Arg Name="Wpt4Lon"/></Setting>
                </Guidance:Waypoint>

            </Aggregate>

            <Call Id="PHONEHOMEWPT4" RefId="SURFACECOMMS"/>

        </Aggregate>

        <Aggregate Id="ApprchWpt3">

            <Guidance:Pitch RunIn="Parallel">
                <Setting><Guidance:Pitch.depth/><Arg Name="ApproachDepth"/></Setting>
            </Guidance:Pitch>

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

            <Guidance:Waypoint Id="WaypointW2" RunIn="Sequence">
                <Setting><Guidance:Waypoint.latitude/><Arg Name="Wpt3Lat"/></Setting>
                <Setting><Guidance:Waypoint.longitude/><Arg Name="Wpt3Lon"/></Setting>
            </Guidance:Waypoint>

        </Aggregate>

<!--End of <Aggregate Id="YoyoToWpt2"> -->

        <Aggregate Id="YoYoToWpt2">

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

            <Guidance:DepthEnvelope RunIn="Parallel">
                <Setting><Guidance:DepthEnvelope.minDepth/><Arg Name="YoYoMinDepth"/></Setting>
                <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="YoYoMaxDepth"/></Setting>
                <Setting><Guidance:DepthEnvelope.downPitch/><Arg Name="YoYoDownPitch"/></Setting>
                <Setting><Guidance:DepthEnvelope.upPitch/><Arg Name="YoYoUpPitch"/></Setting>
            </Guidance:DepthEnvelope>

            <Guidance:YoYo RunIn="Parallel">
                <Setting><Guidance:YoYo.downPitch/><Arg Name="YoYoDownPitch"/></Setting>
                <Setting><Guidance:YoYo.upPitch/><Arg Name="YoYoUpPitch"/></Setting>
            </Guidance:YoYo>

            <Guidance:Waypoint Id="Wpt2" RunIn="Sequence">
                <Setting><Guidance:Waypoint.latitude/><Arg Name="Wpt2Lat"/></Setting>
                <Setting><Guidance:Waypoint.longitude/><Arg Name="Wpt2Lon"/></Setting>
            </Guidance:Waypoint>

            <Aggregate Id="ApprchWpt1">

                <Guidance:Pitch RunIn="Parallel">
                    <Setting><Guidance:Pitch.depth/><Arg Name="ApproachDepth"/></Setting>
                </Guidance:Pitch>

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

                <Guidance:Waypoint Id="WaypointW2" RunIn="Sequence">
                    <Setting><Guidance:Waypoint.latitude/><Arg Name="Wpt1Lat"/></Setting>
                    <Setting><Guidance:Waypoint.longitude/><Arg Name="Wpt1Lon"/></Setting>
                </Guidance:Waypoint>

            </Aggregate>

            <Call Id="PHONEHOMEWPT1" RefId="SURFACECOMMS"/>

        </Aggregate>

<!--  End of <Aggregate Id="YoYoToWpt1"> -->

    </Aggregate>

<!-- End of <Aggregate Id="TestDrive">-->

    <Aggregate Id="MAIN" Repeat="15">

        <Call RefId="TestDrive"/>

    </Aggregate>

<!-- End of <Aggregate Id="MAIN"> -->

</Mission>
