<?xml version="1.0" encoding="UTF-8"?>
<Stack 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 ../Xml/Tethys.xsd
                           Tethys/Control ../Xml/Control.xsd
                           Tethys/Guidance ../Xml/Guidance.xsd
                           Tethys/Units ../Xml/Units.xsd
                           Tethys/Universal ../Xml/Universal.xsd"
       Id="buoyancyTankDemo">

    <Timeout Duration="P600M">
        <Guidance:StopMission RunIn="Sequence"/>
    </Timeout>

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

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

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

    <Stack Id="GPSFIX" >

        <When>
            <Called/>
        </When>

        <Guidance:GoToSurface RunIn="Progression"/>

        <Stack>

            <Preemptive><True/></Preemptive>

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

            <Guidance:ReadSensor RunIn="Sequence">
                <SetUri><Guidance:ReadSensor.uri/><Universal:latitude_fix/></SetUri>
            </Guidance:ReadSensor>

        </Stack>

    </Stack>

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

    <Stack Id="MaintainDepth" >

        <When>
            <Called/>
        </When>

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

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

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

    </Stack>

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

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

        <Stack Id="bottomDepth">

            <Guidance:Pitch RunIn="Parallel">
<!-- Setting the elevator angle and mass posn to zero shuts off pitch control.-->
                <Set><Guidance:Pitch.elevatorAngle/><Units:degree/><Value>0</Value></Set>
                <Set><Guidance:Pitch.massPosition/><Units:centimeter/><Value>0</Value></Set>
                <Set><Guidance:Pitch.depth/><Units:meter/><Value>7</Value></Set>
            </Guidance:Pitch>

            <Call refId="MaintainDepth"/>

        </Stack>

        <Stack Id="topDepth">

            <Guidance:Pitch RunIn="Parallel">
<!-- Setting the elevator angle and mass posn to zero shuts off pitch control.-->
                <Set><Guidance:Pitch.elevatorAngle/><Units:degree/><Value>0</Value></Set>
                <Set><Guidance:Pitch.massPosition/><Units:centimeter/><Value>0</Value></Set>
                <Set><Guidance:Pitch.depth/><Units:meter/><Value>2</Value></Set>
            </Guidance:Pitch>

            <Call refId="MaintainDepth"/>

        </Stack>

    </Stack>

</Stack>
