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

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

    <DefineArg Name="BuoyancyNeutral"><Description>
        Buoyancy bladder position while performing the YoYo behavior. Defaults
        to buoyancyNeutral setting in the Config/Control.cfg file. Set to NaN cc
        for active buoyancy
    </Description><Control:VerticalControl.buoyancyNeutral/></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>

    <DefineArg Name="HeadingEast"><Units:degree/><Value>90.0</Value></DefineArg>

    <DefineArg Name="SearchHeading"><Description>
        Initialized to the starting heading (default 270.0). Will be updated
        when detecting front or hitting wall.
    </Description><Units:degree/><Value>270.0</Value></DefineArg>

    <DefineArg Name="LonWestWall"><Units:degree/><Value>-121.85</Value></DefineArg>

    <Timeout Duration="P12H"/>

    <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="TrackFront">

        <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:FrontTracking Id="tracking">
            <Sequence/>
            <Setting><Guidance:FrontTracking.searchHeading/><Arg Name="SearchHeading"/></Setting>
            <Setting><Guidance:FrontTracking.eastHeading/><Arg Name="HeadingEast"/></Setting>
            <Setting><Guidance:FrontTracking.lonWestWall/><Arg Name="LonWestWall"/></Setting>
        </Guidance:FrontTracking>

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

    </Aggregate>

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

</Mission>
