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

    <Description>
        Vehicle circles at a specified depth and rudder angle
    </Description>

<!-- Almost every mission should start with an overall timeout and a NeedCommsTime. -->

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

    <DefineArg Name="Depth01"><Description>
        Depth of circle 1.
    </Description><Units:meter/><Value>50</Value></DefineArg>

    <DefineArg Name="Depth02"><Description>
        Depth of circle 2.
    </Description><Units:meter/><Value>50</Value></DefineArg>

    <DefineArg Name="RudderAngle01"><Description>
        Rudder angle to use while performing the first circle.
    </Description><Units:degree/><Value>5</Value></DefineArg>

    <DefineArg Name="RudderAngle02"><Description>
        Rudder angle to use while performing the second circle.
    </Description><Units:degree/><Value>14</Value></DefineArg>

    <DefineArg Name="WaitDuration"><Description>
        How long to circle.
    </Description><Units:minute /><Value>5</Value></DefineArg>

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

    <DefineArg Name="SettleTime"><Description>
        How long to wait after reaching target depth before triggering sample.
    </Description><Units:second/><Value>0</Value></DefineArg>

    <DefineArg Name="Speed"><Description>
        Speed while performing the spiral cast.
    </Description><Units:meter_per_second/><Value>1</Value></DefineArg>

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

    <DefineArg Name="MinAltitude"><Description>
        Minimum altitude for the entire mission.
    </Description><Units:meter/><Value>5</Value></DefineArg>

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

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

    <Timeout Duration="MissionTimeout"/>

<!-- Most missions will run the science sensors. -->

    <Insert Filename="Insert/Science.xml">
        <RedefineArg Name="PeakDetectChlActive"><True/></RedefineArg>
    </Insert>

<!-- Most missions will use the NeedComms aggregate. In this case, we use NeedComms for the start of the mission and for the upcast, but set the dive interval to be the same as the mission timeout. -->

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

    <Assign><Sequence/><Arg Name="NeedComms:DiveInterval"/><Arg Name="MissionTimeout"/></Assign>

    <Assign><Sequence/><Arg Name="NeedComms:SurfaceSpeed"/><Arg Name="Speed"/></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:MinAltitude"/><Arg Name="MinAltitude"/></Assign>

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

<!-- Check for additional instructions first. -->

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

<!-- Many missions will keep mass position and buoyancy volume fixed at defaults. -->

    <Guidance:Pitch>
        <Parallel/>
        <Setting><Guidance:Pitch.massPosition/><Control:VerticalControl.massDefault/></Setting>
    </Guidance:Pitch>

    <Guidance:Buoyancy>
        <Parallel/>
        <Setting><Guidance:Buoyancy.position/><Control:VerticalControl.buoyancyNeutral/></Setting>
    </Guidance:Buoyancy>

    <Guidance:SetSpeed>
        <Parallel/>
        <Setting><Guidance:SetSpeed.speed/><Arg Name="Speed"/></Setting>
    </Guidance:SetSpeed>

    <Aggregate Id="Circle 1">

        <Sequence/>

        <Guidance:Point>
            <Parallel/>
            <Setting><Guidance:Point.rudderAngle /><Arg Name="RudderAngle01" /></Setting>
        </Guidance:Point>

        <Guidance:Pitch>
            <Progression/>
            <Setting><Guidance:Pitch.depth /><Arg Name="Depth01" /></Setting>
        </Guidance:Pitch>

        <Guidance:Wait>
            <Sequence/>
            <Setting><Guidance:Wait.duration /><Arg Name="WaitDuration" /></Setting>
        </Guidance:Wait>

    </Aggregate>

    <Aggregate Id="Circle 2">

        <Sequence/>

        <Guidance:Point>
            <Parallel/>
            <Setting><Guidance:Point.rudderAngle /><Arg Name="RudderAngle02" /></Setting>
        </Guidance:Point>

        <Guidance:Pitch>
            <Progression/>
            <Setting><Guidance:Pitch.depth /><Arg Name="Depth02" /></Setting>
        </Guidance:Pitch>

        <Guidance:Wait>
            <Sequence/>
            <Setting><Guidance:Wait.duration /><Arg Name="WaitDuration" /></Setting>
        </Guidance:Wait>

    </Aggregate>

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

</Mission>
