<?xml version="1.0" encoding="UTF-8"?>
<Mission xmlns="Tethys"
       xmlns:Derivation="Tethys/Derivation" 
       xmlns:Guidance="Tethys/Guidance" 
       xmlns:Trigger="Tethys/Trigger" 
       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/Derivation http://aosn.mbari.org/tethys/Xml/Derivation.xsd
                           Tethys/Guidance http://aosn.mbari.org/tethys/Xml/Guidance.xsd
                           Tethys/Trigger http://aosn.mbari.org/tethys/Xml/Trigger.xsd
                           Tethys/Units http://aosn.mbari.org/tethys/Xml/Units.xsd
                           Tethys/Universal http://aosn.mbari.org/tethys/Xml/Universal.xsd"
       Id="Oceans2010Test1">

    <DefineArg Name="UpPitch"><Units:degree/><Value>15.0</Value></DefineArg>

    <DefineArg Name="DownPitch"><Units:degree/><Value>-15.0</Value></DefineArg>

    <DefineArg Name="latitudeDelta"><Units:degree/><Value>0.0</Value></DefineArg>

    <DefineArg Name="longitudeDelta"><Units:degree/><Value>-0.1</Value></DefineArg>

    <Timeout Duration="P80M"/>

    <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>40</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" />

    <Guidance:Buoyancy RunIn="Progression">
        <Setting><Guidance:Buoyancy.position/><Units:cubic_centimeter/><Value>300</Value></Setting>
    </Guidance:Buoyancy>

    <Aggregate Id="RunTest">

        <Timeout Duration="P30M"/>

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

        <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/><Units:meter/><Value>5</Value></Setting>
        </Guidance:DepthEnvelope>

        <Aggregate Id="InitialYoYo">

            <Until>
                <Elapsed><Derivation:TempGradientCalculator.targetDepth/></Elapsed>
                <Lt/><Units:second/><Value>1</Value>
            </Until>

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

            <Guidance:Wait RunIn="Sequence"/>

        </Aggregate>

        <Aggregate Id="Notify">

            <When>
                <Elapsed><Derivation:TempGradientCalculator.targetDepth/></Elapsed>
                <Lt/><Units:second/><Value>0.4</Value>
            </When>

            <Syslog>Depth=<Universal:depth/><Units:meter/>, Thermocline Depth = <Derivation:TempGradientCalculator.thermoclineDepth/><Units:meter/>, Target depth = <Derivation:TempGradientCalculator.targetDepth/><Units:meter/>
            </Syslog>

        </Aggregate>

        <Guidance:Pitch Id="PitchDown" RunIn="Parallel">
            <While><Universal:depth/>
                <Lt/><Derivation:TempGradientCalculator.targetDepth/>
            </While>
            <Setting><Guidance:Pitch.pitch/><Arg Name="DownPitch"/></Setting>
        </Guidance:Pitch>

        <Guidance:Pitch Id="PitchUp" RunIn="Parallel">
            <While><Universal:depth/>
                <Gt/><Derivation:TempGradientCalculator.targetDepth/>
            </While>
            <Setting><Guidance:Pitch.pitch/><Arg Name="UpPitch"/></Setting>
        </Guidance:Pitch>

        <Guidance:Waypoint RunIn="Sequence">
            <Setting><Guidance:Waypoint.latitudeDelta/><Arg Name="latitudeDelta"/></Setting>
            <Setting><Guidance:Waypoint.longitudeDelta/><Arg Name="longitudeDelta"/></Setting>
        </Guidance:Waypoint>

    </Aggregate>

    <Call RefId="SURFACECOMMS" />

    <Syslog>Done</Syslog>

</Mission>
