<?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://okeanids.mbari.org/tethys/Xml/Tethys.xsd
                           Tethys/Control http://okeanids.mbari.org/tethys/Xml/Control.xsd
                           Tethys/Guidance http://okeanids.mbari.org/tethys/Xml/Guidance.xsd
                           Tethys/Units http://okeanids.mbari.org/tethys/Xml/Units.xsd
                           Tethys/Universal http://okeanids.mbari.org/tethys/Xml/Universal.xsd"
       Id="ZigZagLane">

    <DefineArg Name="MassDefault"><Control:VerticalControl.massDefault/></DefineArg>

    <DefineArg Name="Bearing"><Units:degree/><Value>300</Value></DefineArg>

    <DefineArg Name="LaneDistance"><Units:meter/><Value>3000</Value></DefineArg>

    <DefineArg Name="LaneWidth"><Units:meter/><Value>500</Value></DefineArg>

    <DefineArg Name="LaneOffset1"><Units:meter/><Value>0</Value></DefineArg>

    <DefineArg Name="LaneOffset2"><Units:meter/><Value>250</Value></DefineArg>

    <DefineArg Name="LaneOffset3"><Units:meter/><Value>-250</Value></DefineArg>

    <DefineArg Name="ZigZagAngle"><Units:degree/><Value>65</Value></DefineArg>

    <DefineArg Name="NorthingsDelta"><Units:meter/><Value>250</Value></DefineArg>

    <DefineArg Name="EastingsDelta"><Units:meter/><Value>-433</Value></DefineArg>

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

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

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

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

    <Timeout Duration="P480M"/>

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

    <Guidance:DepthEnvelope>
        <Parallel/>
        <Setting><Guidance:DepthEnvelope.maxDepth/><Units:meter/><Value>300</Value></Setting>
    </Guidance:DepthEnvelope>

    <Guidance:OffshoreEnvelope>
        <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></Gt>
            <And><Elapsed><Universal:time_fix/></Elapsed><Gt><Units:minute/><Value>45</Value></Gt></And>
            <Or><Elapsed><Universal:time_fix/></Elapsed><Gt><Units:minute/><Value>50</Value></Gt></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>
        <Parallel/>
        <Setting><Guidance:Buoyancy.position /><Arg Name="BuoyancyNeutral"/></Setting>
    </Guidance:Buoyancy>

    <Guidance:Pitch>
        <Parallel/>
        <Setting><Guidance:Pitch.massPosition/><Arg Name="MassDefault"/></Setting>
    </Guidance:Pitch>

    <Aggregate Id="ZigZag">

        <Sequence/>

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

        <Guidance:DepthEnvelope>
            <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>
            <Parallel/>
            <Setting><Guidance:YoYo.downPitch/><Arg Name="YoYoDownPitch"/></Setting>
            <Setting><Guidance:YoYo.upPitch/><Arg Name="YoYoUpPitch"/></Setting>
        </Guidance:YoYo>

        <Guidance:Lane Id="Lane1">
            <Sequence/>
            <Setting><Guidance:Lane.bearing/><Arg Name="Bearing"/></Setting>
            <Setting><Guidance:Lane.distance/><Arg Name="LaneDistance"/></Setting>
            <Setting><Guidance:Lane.width/><Arg Name="LaneWidth"/></Setting>
            <Setting><Guidance:Lane.offset/><Arg Name="LaneOffset1"/></Setting>
        </Guidance:Lane>

        <Guidance:Point Id="Wp1">
            <Sequence/>
            <Setting><Guidance:Point.northingsDelta/><Arg Name="NorthingsDelta"/></Setting>
            <Setting><Guidance:Point.eastingsDelta/><Arg Name="EastingsDelta"/></Setting>
        </Guidance:Point>

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

        <Guidance:Lane Id="Lane2">
            <Sequence/>
            <Setting><Guidance:Lane.bearing/><Arg Name="Bearing"/></Setting>
            <Setting><Guidance:Lane.distance/><Arg Name="LaneDistance"/></Setting>
            <Setting><Guidance:Lane.width/><Arg Name="LaneWidth"/></Setting>
            <Setting><Guidance:Lane.offset/><Arg Name="LaneOffset2"/></Setting>
        </Guidance:Lane>

        <Guidance:Point Id="Wp2">
            <Sequence/>
            <Setting><Guidance:Point.northingsDelta/><Arg Name="NorthingsDelta"/></Setting>
            <Setting><Guidance:Point.eastingsDelta/><Arg Name="EastingsDelta"/></Setting>
        </Guidance:Point>

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

        <Guidance:Lane Id="Lane3">
            <Sequence/>
            <Setting><Guidance:Lane.bearing/><Arg Name="Bearing"/></Setting>
            <Setting><Guidance:Lane.distance/><Arg Name="LaneDistance"/></Setting>
            <Setting><Guidance:Lane.width/><Arg Name="LaneWidth"/></Setting>
            <Setting><Guidance:Lane.offset/><Arg Name="LaneOffset3"/></Setting>
        </Guidance:Lane>

        <Guidance:ZigZag>
            <Parallel/>
            <Setting><Guidance:ZigZag.bearing/><Arg Name="Bearing"/></Setting>
            <Setting><Guidance:ZigZag.angle/><Arg Name="ZigZagAngle"/></Setting>
        </Guidance:ZigZag>

    </Aggregate>

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

</Mission>
