<?xml version="1.0" encoding="UTF-8"?>
<!--
    Copyright (c) 2008 Monterey Bay Aquarium Research Institute (MBARI)
    MBARI Proprietary Information. All Rights Reserved
-->
<Aggregate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns="Tethys"
           xmlns:Units="Tethys/Units"
           xmlns:Universal="Tethys/Universal"
           xmlns:Guidance="Tethys/Guidance"
           xsi:schemaLocation="Tethys http://okeanids.mbari.org/tethys/Xml/Tethys.xsd
                               Tethys/Units http://okeanids.mbari.org/tethys/Xml/Units.xsd
                               Tethys/Universal http://okeanids.mbari.org/tethys/Xml/Universal.xsd
                               Tethys/Guidance http://okeanids.mbari.org/tethys/Xml/Guidance.xsd"
       Id="NeedComms">

    <DefineArg Name="DiveInterval"><Description>
        Elapsed time after most recent surfacing when vehicle will begin to
        ascend to the surface again. The timing is actually based on the
        variable Universal:time_fix instead of the variable
        Universal:platform_communications because the latter is not toggled
        until the message queue is clear. As a result, there are situations
        where the vehicle might dive for the first half of a yo, then return to
        the surface to continue communications, rendering the communications
        timeout useless. When adjusting this parameter, do not use "set", use
        Assign in a mission, or set NeedComms:DiveInterval from the command
        line.
    </Description><Units:hour/><Value>3</Value></DefineArg>

    <DefineArg Name="WaitForPitchUp"><Description>
        Extra time to wait for the vehicle to pitch up (avoid truncating a yo).
    </Description><Units:minute/><Value>10</Value></DefineArg>

    <DefineArg Name="SurfacePitch"><Description>
        Pitch to maintain while ascending
    </Description><Units:degree/><Value>20</Value></DefineArg>

    <DefineArg Name="SurfaceDepthRate"><Description>
        Depth rate to maintain while ascending. Set to NaN if using pitch
    </Description><Units:meter_per_second/><Value>NaN</Value></DefineArg>

    <DefineArg Name="SurfaceSpeed"><Description>
        Standard speed during surfacing. Don't reduce this too much below 1 m/s
        -- the elevators can stall. (At 0.5 m/s, we have observed evidence of
        stall in the past.)
    </Description><Units:meter_per_second/><Value>1</Value></DefineArg>

    <DefineArg Name="SurfacingTimeout"><Description>
        The maximum time allowed for the ascent to surface.
    </Description><Units:second/><Value>1000</Value></DefineArg>

    <DefineArg Name="GPSTimeout"><Description>
        Maximum amount of time to spend trying to get each GPS fix.
    </Description><Units:minute/><Value>7</Value></DefineArg>

    <DefineArg Name="CommsTimeout"><Description>
        Maximum amount of time to spend on the surface trying to communicate
        before giving up, getting another GPS fix, and diving again.
    </Description><Units:minute/><Value>30</Value></DefineArg>

    <When>
        <Called/>
        <Or><Elapsed><Universal:time_fix/></Elapsed><Gt><Arg Name="DiveInterval"/> <Add><Arg Name="WaitForPitchUp"/></Add></Gt></Or>
        <Or><Elapsed><Universal:time_fix/></Elapsed><Gt><Arg Name="DiveInterval"/></Gt><And><Universal:platform_pitch_angle/><Gt><Units:degree/><Value>0</Value></Gt></And></Or>
    </When>

    <Syslog Severity="Info">last time_fix was: <Universal:time_fix/><Units:epoch_second/></Syslog>

    <Guidance:GoToSurface>
        <Progression/>
        <Setting><Guidance:GoToSurface.pitch/><Arg Name="SurfacePitch"/></Setting>
        <Setting><Guidance:GoToSurface.depthRate/><Arg Name="SurfaceDepthRate"/></Setting>
        <Setting><Guidance:GoToSurface.speed/><Arg Name="SurfaceSpeed"/></Setting>
        <Setting><Guidance:GoToSurface.surfaceTimeout/><Arg Name="SurfacingTimeout"/></Setting>
    </Guidance:GoToSurface>

    <ReadDatum>
        <Timeout Duration="GPSTimeout">
            <Syslog Severity="Important">first GPS update timeout</Syslog>
        </Timeout>
        <Universal:time_fix/>
    </ReadDatum>

    <ReadDatum>
        <Timeout Duration="CommsTimeout">
            <Syslog Severity="Important">Comms timed out after <Arg Name="CommsTimeout"/><Units:minute/>minutes</Syslog>
        </Timeout>
        <Universal:platform_communications/>
    </ReadDatum>

    <ReadDatum>
        <Timeout Duration="GPSTimeout">
            <Syslog Severity="Important">second GPS update timeout</Syslog>
        </Timeout>
        <Universal:time_fix/>
    </ReadDatum>

</Aggregate>
