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

    <Timeout Duration="P200M"/>

    <Guidance:VerticalControlConfig RunIn="Parallel">
        <Setting><Guidance:VerticalControlConfig.kiDepthOff/><Units:radian_per_meter/><Value>.1</Value></Setting>
        <Setting><Guidance:VerticalControlConfig.kdPitchMass/><Units:second/><Value>.2</Value></Setting>
    </Guidance:VerticalControlConfig>

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

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

    <Aggregate Id="GPSFIX" >

        <When>
            <Called/>
        </When>

        <Guidance:GoToSurface RunIn="Progression"/>

        <Aggregate>

            <Preemptive><True/></Preemptive>

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

            <ReadDatum><Universal:latitude_fix/>
            </ReadDatum>

        </Aggregate>

    </Aggregate>

    <Guidance:Buoyancy RunIn="Sequence">
        <Setting><Guidance:Buoyancy.position/><Units:cubic_centimeter/><Value>500</Value></Setting>
    </Guidance:Buoyancy>

    <Aggregate Id="MaintainDepth" >

        <When>
            <Called/>
        </When>

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

        <Guidance:Point RunIn="Parallel">
            <Setting><Guidance:Point.heading/><Units:degree/><Value>210</Value></Setting>
        </Guidance:Point>

        <Guidance:Wait RunIn="Sequence">
            <Timeout Duration="P30M"></Timeout>
        </Guidance:Wait>

    </Aggregate>

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

<!--
      <Call Id="GPSFIXEND" RefId="GPSFIX"/>
      -->

        <Aggregate Id="bottomDepth">

            <Guidance:Pitch RunIn="Parallel">
<!-- Setting the elevator angle to zero activates mass-only control.-->
                <Setting><Guidance:Pitch.elevatorAngle/><Units:degree/><Value>0</Value></Setting>
                <Setting><Guidance:Pitch.depth/><Units:meter/><Value>7</Value></Setting>
            </Guidance:Pitch>

            <Call RefId="MaintainDepth"/>

        </Aggregate>

        <Aggregate Id="topDepth">

            <Guidance:Pitch RunIn="Parallel">
<!-- Setting the elevator angle to zero activates mass-only control.-->
                <Setting><Guidance:Pitch.elevatorAngle/><Units:degree/><Value>0</Value></Setting>
                <Setting><Guidance:Pitch.depth/><Units:meter/><Value>2</Value></Setting>
            </Guidance:Pitch>

            <Call RefId="MaintainDepth"/>

        </Aggregate>

    </Aggregate>

</Mission>
