<?xml version="1.0" encoding="UTF-8"?>
<Mission xmlns="Tethys"
       xmlns:Control="Tethys/Control"
       xmlns:Guidance="Tethys/Guidance" 
       xmlns:Science="Tethys/Science"
       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/Science http://okeanids.mbari.org/tethys/Xml/Science.xsd
                           Tethys/Units http://okeanids.mbari.org/tethys/Xml/Units.xsd
                           Tethys/Universal http://okeanids.mbari.org/tethys/Xml/Universal.xsd"
       Id="sample">

    <Description>
        This mission is designed to be run offshore to sample water using
        whichever sampling payload is installed and enabled. It triggers
        sampling at a given depth after descending using buoyancy control only.
    </Description>

<!-- Almost every mission should start with an overall timeout this one does not have a NeedCommsTime because we don't want a sample interrupted. -->

    <DefineArg Name="MissionTimeout"><Description>
        Maximum duration of mission
    </Description><Units:hour/><Value>2</Value></DefineArg>

<!-- You probably need to change these. -->

    <DefineArg Name="SampleDepth"><Description>
        Depth to sample at.
    </Description><Units:meter/><Value>15</Value></DefineArg>

<!-- You probably do not need to change these. -->

    <DefineArg Name="SettleTime"><Description>
        Time to wait after reaching target depth before triggering sample.
    </Description><Units:minute/><Value>10</Value></DefineArg>

    <DefineArg Name="SkipComms"><Description>
        Skip communications at start of mission. (for example, when in test
        tank, or when scheduled to start underwater)
    </Description><False/></DefineArg>

<!-- You are even less likely to need to change these. -->

    <DefineArg Name="MassDefault"><Description>
        Static setting for mass during the mission. Set to NaN mm for active
        mass position.
    </Description><Control:VerticalControl.massDefault/></DefineArg>

    <DefineArg Name="MaxDepth"><Description>
        Maximum depth for the entire mission.
    </Description><Units:meter/><Value>32</Value></DefineArg>

<!-- Missions should almost always start with a timeout -->

    <Timeout Duration="MissionTimeout"/>

<!-- Most missions will run the science sensors. If you don't place this aggregate above NeedComms, science instruments get turned off on the last upcast and while floating on the surface. -->

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

<!-- Most missions should use the NeedComms aggregate. -->

    <Insert Filename="Insert/NeedComms.xml" Id="NeedComms"/>

    <Assign><Sequence/><Arg Name="NeedComms:DiveInterval"/><Units:day/><Value>3</Value></Assign>

<!-- Missions should almost always start with standard safety envelopes; most missions should not expose the parameters of these envelopes. -->

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

    <Assign><Sequence/><Arg Name="StandardEnvelopes:MaxDepth"/><Arg Name="MaxDepth"/></Assign>

    <Aggregate Id="StartingMission">

        <Sequence/>

        <Break><Arg Name="SkipComms"/>
        </Break>

<!-- DO NOT REMOVE the syslog entry below. The MissionManager seems to ignore the value of SkipComms, does not evaluate the Break statement properly, and always calls NeedComms. Adding the syslog call somehow fixes it. -->

        <Syslog Severity="Info">Checking for additional instructions before submerging.</Syslog>

        <Call Id="StartingMission" RefId="NeedComms"/>

    </Aggregate>

<!-- Now for the actual mission -->

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

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

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

    <Assign><Sequence/><Arg Name="SampleAtDepth:SettleTime"/><Arg Name="SettleTime"/></Assign>

    <Aggregate Id="TestDrive">

        <Sequence/>

        <Assign><Sequence/><Arg Name="SampleAtDepth:TargetDepth"/><Arg Name="SampleDepth"/></Assign>

        <Call Id="Sample" RefId="SampleAtDepth"/>

    </Aggregate>

</Mission>
