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

    <Description>
        This mission navigates to the CANON trianguloid waypoints and sets the
        max depth for each leg. The mission can (re)start at any point within
        this trajectory by adjusting the `leg` parameter as needed. Samples are
        triggered on a clock every SampleInterval.
    </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>42</Value></DefineArg>

    <DefineArg Name="NeedCommsTime"><Description>
        How often to surface for commumications
    </Description><Units:minute/><Value>120</Value></DefineArg>

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

    <DefineArg Name="leg"><Description>
        Leg to start at (default is start at leg 1). leg 1: C1, 40m leg 2: C1 -
        M1 Bypass 01, 50m leg 3: M1 Bypass 01 - Soquel Monterey Junction 01, 50m
        leg 4: Soquel Monterey Junction 01 - WG near MARS, 50m leg 5: WG near
        MARS - WG near Mid 1, 50m leg 6: WG near Mid 1 - M1 Bypass 01, 50m leg
        7: M1 Bypass 01 - C1, 50m leg 8: C1 - ?, 50m (spare wp)
    </Description><Units:count/><Value>1</Value></DefineArg>

    <DefineArg Name="SampleInterval"><Description>
        ESP sampling interval. Must be longer than the duration of a single ESP
        sample.
    </Description><Units:hour/><Value>2</Value></DefineArg>

    <DefineArg Name="FirstSampleTimeOffset"><Description>
        When true, the mission will acquire and ESP sample at the start of the
        mission. When false, the mission will wait for the SampleInterval before
        acquiring the first sample.
    </Description><Units:minute/><Value>10</Value></DefineArg>

    <DefineArg Name="SampleESP"><Description>
        When true, aqurie an ESP sample.
    </Description><True/></DefineArg>

    <DefineArg Name="CartridgeType"><Description>
        Specifies ESP cartridge type code (defaults to archive_bac: -6)
    </Description><Units:count/><Value>-6</Value></DefineArg>

    <DefineArg Name="SampleCANONSampler"><Description>
        When true, aqurie a CANON Sampler water sample.
    </Description><False/></DefineArg>

    <DefineArg Name="CANONSamplerDelay"><Description>
        How long to delay a CANON Sampler sample after an ESP sample is
        intiated.
    </Description><Units:minute/><Value>10</Value></DefineArg>

    <DefineArg Name="SampleTimeout"><Description>
        Max time duration allowed for a single sample.
    </Description><Units:hour/><Value>3</Value></DefineArg>

    <DefineArg Name="Lat1"><Description>
        Latitude of waypoint 1 (default: C1).
    </Description><Units:degree/><Value>36.797</Value></DefineArg>

    <DefineArg Name="Lon1"><Description>
        Longitude of waypoint 1 (default: C1).
    </Description><Units:degree/><Value>-121.847</Value></DefineArg>

    <DefineArg Name="Lat2"><Description>
        Latitude of waypoint 2 (default: M1 Bypass 01).
    </Description><Units:degree/><Value>36.754</Value></DefineArg>

    <DefineArg Name="Lon2"><Description>
        Longitude of waypoint 2 (default: M1 Bypass 01).
    </Description><Units:degree/><Value>-122.0155</Value></DefineArg>

    <DefineArg Name="Lat3"><Description>
        Latitude of waypoint 3 (default: Soquel Monterey Junction 01).
    </Description><Units:degree/><Value>36.7825</Value></DefineArg>

    <DefineArg Name="Lon3"><Description>
        Longitude of waypoint 3 (default: Soquel Monterey Junction 01).
    </Description><Units:degree/><Value>-122.018</Value></DefineArg>

    <DefineArg Name="Lat4"><Description>
        Latitude of waypoint 4 (default: WG near MARS).
    </Description><Units:degree/><Value>36.7117</Value></DefineArg>

    <DefineArg Name="Lon4"><Description>
        Longitude of waypoint 4 (default: WG near MARS).
    </Description><Units:degree/><Value>-122.1919</Value></DefineArg>

    <DefineArg Name="Lat5"><Description>
        Latitude of waypoint 5 (default: WG near Mid 1).
    </Description><Units:degree/><Value>36.6978</Value></DefineArg>

    <DefineArg Name="Lon5"><Description>
        Longitude of waypoint 5 (default: WG near Mid 1).
    </Description><Units:degree/><Value>-122.0562</Value></DefineArg>

    <DefineArg Name="Lat6"><Description>
        Latitude of waypoint 6 (default: M1 Bypass 01).
    </Description><Units:degree/><Value>36.754</Value></DefineArg>

    <DefineArg Name="Lon6"><Description>
        Longitude of waypoint 6 (default: M1 Bypass 01).
    </Description><Units:degree/><Value>-122.0155</Value></DefineArg>

    <DefineArg Name="Lat7"><Description>
        Latitude of waypoint 7 (default: C1).
    </Description><Units:degree/><Value>36.797</Value></DefineArg>

    <DefineArg Name="Lon7"><Description>
        Longitude of waypoint 7 (default: C1).
    </Description><Units:degree/><Value>-121.847</Value></DefineArg>

    <DefineArg Name="Lat8"><Description>
        Latitude of waypoint 8 (spare).
    </Description><Units:degree/><Value>NaN</Value></DefineArg>

    <DefineArg Name="Lon8"><Description>
        Longitude of waypoint 8 (spare).
    </Description><Units:degree/><Value>NaN</Value></DefineArg>

    <DefineArg Name="Speed"><Description>
        Vehicle speed for the entire mission.
    </Description><Units:meter_per_second/><Value>1</Value></DefineArg>

    <DefineArg Name="YoYoMinDepth"><Description>
        Minimum YoYo depth for the entire mission.
    </Description><Units:meter/><Value>5</Value></DefineArg>

    <DefineArg Name="YoYoMaxDepth1"><Description>
        Maximum YoYo depth during leg 1.
    </Description><Units:meter/><Value>40</Value></DefineArg>

    <DefineArg Name="YoYoMaxDepth2"><Description>
        Maximum YoYo depth during leg 2.
    </Description><Units:meter/><Value>50</Value></DefineArg>

    <DefineArg Name="YoYoMaxDepth3"><Description>
        Maximum YoYo depth during leg 3.
    </Description><Units:meter/><Value>50</Value></DefineArg>

    <DefineArg Name="YoYoMaxDepth4"><Description>
        Maximum YoYo depth during leg 4.
    </Description><Units:meter/><Value>50</Value></DefineArg>

    <DefineArg Name="YoYoMaxDepth5"><Description>
        Maximum YoYo depth during leg 5.
    </Description><Units:meter/><Value>50</Value></DefineArg>

    <DefineArg Name="YoYoMaxDepth6"><Description>
        Maximum YoYo depth during leg 6.
    </Description><Units:meter/><Value>50</Value></DefineArg>

    <DefineArg Name="YoYoMaxDepth7"><Description>
        Maximum YoYo depth during leg 7.
    </Description><Units:meter/><Value>50</Value></DefineArg>

    <DefineArg Name="YoYoMaxDepth8"><Description>
        Maximum YoYo depth during leg 8.
    </Description><Units:meter/><Value>50</Value></DefineArg>

    <DefineArg Name="YoYoMinAltitude"><Description>
        Minimum altitude while performing the YoYo behavior (for
        bottom-terminated YoYos).
    </Description><Units:meter/><Value>9</Value></DefineArg>

    <DefineArg Name="YoYoUpPitch"><Description>
        Vehicle up pitch while performing the YoYo behavior.
    </Description><Units:degree/><Value>20</Value></DefineArg>

    <DefineArg Name="YoYoDownPitch"><Description>
        Vehicle down pitch while performing the YoYo behavior.
    </Description><Units:degree/><Value>-20</Value></DefineArg>

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

    <DefineArg Name="CaptureRadius"><Description>
        Waypoint capture radiues.
    </Description><Units:meter/><Value>NaN</Value></DefineArg>

    <DefineArg Name="MinAltitude"><Description>
        Minimum height above the sea floor 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>110</Value></DefineArg>

    <DefineArg Name="MinOffshore"><Description>
        Minimum offshore distance for the entire mission.
    </Description><Units:kilometer/><Value>2</Value></DefineArg>

    <DefineOutput Name="ElapsedSinceLastSampleStart"><Description>
        Mission variable (don't change). The mission sets this variable to reset
        the ESP sample timer.
    </Description><Units:minute/><Value>0</Value></DefineOutput>

    <DefineOutput Name="ElapsedTime"><Description>
        Mission variable (don't change). The mission sets this variable to reset
        the ESP sample timer.
    </Description><Units:hour/><Value>0</Value></DefineOutput>

    <DefineOutput Name="SampleInProgress"><Description>
        Mission variable (don't change). The mission sets this variable to while
        sampling is in progress.
    </Description><False/></DefineOutput>

    <DefineOutput Name="FirstSample"><Description>
        Mission variable (don't change). The mission sets this variable to when
        it's time to take the first sample.
    </Description><False/></DefineOutput>

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

    <Timeout Duration="MissionTimeout"/>

    <Insert Filename="Insert/Science.xml">
        <Description>
            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.
        </Description>
    </Insert>

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

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

    <Assign><Sequence/><Arg Name="NeedComms:DiveInterval"/><Arg Name="NeedCommsTime"/></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>

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

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

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

<!-- Sampling directives -->

    <Aggregate Id="CheckSamplingSettings">

        <Sequence/>

        <Syslog Severity="Info">Checking sampling settings.</Syslog>

        <Aggregate Id="CheckESP">

            <When>
                <Arg Name="SampleESP"/>
                <And><Not><Science:ESPComponent.loadAtStartup/></Not></And>
            </When>

            <Syslog Severity="Critical">Cannot service ESP sample request. ESPComponent is not loaded.</Syslog>

        </Aggregate>

        <Aggregate Id="CheckCANONSampler">

            <When>
                <Arg Name="SampleCANONSampler"/>
                <And><Not><Science:CANONSampler.loadAtStartup/></Not></And>
            </When>

            <Syslog Severity="Critical">Cannot service CANONSampler water sample request. CANONSampler component is not loaded.</Syslog>

        </Aggregate>

    </Aggregate>

    <Insert Filename="Insert/Sample.xml">
        <RedefineArg Name="SampleTimeout"><Arg Name="SampleTimeout"/></RedefineArg>
    </Insert>

<!-- Automatically cycle logs every 24 hours -->

    <Aggregate Id="CycleLogs">

        <Parallel/>

        <Aggregate>

            <Sequence/>

            <Guidance:Wait>
                <Sequence/>
                <Setting><Guidance:Wait.duration/><Units:hour/><Value>24</Value></Setting>
            </Guidance:Wait>

            <Syslog Severity="Important">Restarting logs.</Syslog>

            <Guidance:Execute>
                <Sequence/>
                <Setting><Guidance:Execute.command/><String>restart logs</String></Setting>
            </Guidance:Execute>

        </Aggregate>

    </Aggregate>

<!-- Acquire ESP sample every SampleInterval -->

    <Aggregate Id="SampleTimer">

        <While>
            <Arg Name="FirstSample"/>
            <And>
                <Arg Name="SampleInProgress"/>
                <Or><Elapsed><Arg Name="ElapsedSinceLastSampleStart"/></Elapsed><Gt><Arg Name="SampleInterval"/></Gt></Or>
            </And>
        </While>

        <Aggregate Id="AcquireSample">

            <Sequence/>

            <Assign><Sequence/><Arg Name="ElapsedTime"/><Elapsed><Arg Name="ElapsedSinceLastSampleStart"/></Elapsed></Assign>

            <Syslog Severity="Important">Pre-sample comms. Elapsed time since last water sample: <Arg Name="ElapsedTime"/><Units:hour/></Syslog>

<!-- Surface for comms before initiating the sample sequence -->

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

<!-- Set the surface comms interval to the sample timeout to avoid interruptions while sampling -->

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

            <Aggregate Id="WaitForDepth">

                <Sequence/>

                <Break>
                    <Universal:depth/>
                    <Ge><Arg Name="YoYoMinDepth"/></Ge>
                </Break>

                <Syslog Severity="Info">Waiting to achieve min depth of <Arg Name="YoYoMinDepth"/><Units:meter/></Syslog>

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

            </Aggregate>

<!-- Indicate a sample is in progress -->

            <Assign><Sequence/><Arg Name="SampleInProgress"/><True/></Assign>

<!-- This assignment restarts the sample timer -->

            <Assign><Sequence/><Arg Name="ElapsedSinceLastSampleStart"/><Value>0</Value></Assign>

<!-- Configure sampling sequance -->

            <Assign><Sequence/><Arg Name="Sample:SampleCANONSampler"/><Arg Name="SampleCANONSampler"/></Assign>

            <Assign><Sequence/><Arg Name="Sample:CANONSamplerDelay"/><Arg Name="CANONSamplerDelay"/></Assign>

            <Assign><Sequence/><Arg Name="Sample:ESPCartridgeType"/><Arg Name="CartridgeType"/></Assign>

            <Assign><Sequence/><Arg Name="Sample:SampleESP"/><Arg Name="SampleESP"/></Assign>

<!-- Trigger sampling sequance -->

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

<!-- Surface for comms after the sampling sequence completes -->

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

<!-- Reinstate nominal surface comms interval -->

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

            <Assign><Sequence/><Arg Name="SampleInProgress"/><False/></Assign>

        </Aggregate>

    </Aggregate>

    <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>

    <Guidance:DepthEnvelope>
        <Description>
            Another depth envelope for the YoYo behavior. This envelope should
            fall within the limits of the standard safety envelopes in
            Insert/StandardEnvelopes.xml in order to avoid commanding high pitch
            angles for depth-terminated YoYos.
        </Description>
        <Parallel/>
        <Setting><Guidance:DepthEnvelope.minDepth/><Arg Name="YoYoMinDepth"/></Setting>
        <Setting><Guidance:DepthEnvelope.downPitch/><Arg Name="YoYoDownPitch"/></Setting>
        <Setting><Guidance:DepthEnvelope.upPitch/><Arg Name="YoYoUpPitch"/></Setting>
    </Guidance:DepthEnvelope>

    <Guidance:AltitudeEnvelope>
        <Description>
            Another altitude envelope for the YoYo behavior. This envelope
            should fall within the limits of the standard safety envelopes in
            Insert/StandardEnvelopes.xml in order to avoid commanding high pitch
            angles for bottom-terminated YoYos.
        </Description>
        <Parallel/>
        <Setting><Guidance:AltitudeEnvelope.minAltitude/><Arg Name="YoYoMinAltitude"/></Setting>
        <Setting><Guidance:AltitudeEnvelope.upPitch/><Arg Name="YoYoUpPitch"/></Setting>
    </Guidance:AltitudeEnvelope>

    <Guidance:YoYo>
        <Parallel/>
        <Setting><Guidance:YoYo.downPitch/><Arg Name="YoYoDownPitch"/></Setting>
        <Setting><Guidance:YoYo.upPitch/><Arg Name="YoYoUpPitch"/></Setting>
    </Guidance:YoYo>

    <Aggregate Id="SetWaypointsPerLegParameter">

        <Description>
            The following Leg2-5 aggregates adjust the Lat[] and Lon[] variables
            according to the `trajectory` parameter:
        </Description>

        <Sequence/>

        <Aggregate Id="Leg2">

            <Sequence/>

            <Break><Arg Name="leg"/>
                <Le><Units:count/><Value>1</Value></Le>
            </Break>

            <Assign><Sequence/><Arg Name="Lat1"/><Units:degree/><Value>NaN</Value></Assign>

            <Assign><Sequence/><Arg Name="Lon1"/><Units:degree/><Value>NaN</Value></Assign>

        </Aggregate>

        <Aggregate Id="Leg3">

            <Sequence/>

            <Break><Arg Name="leg"/>
                <Le><Units:count/><Value>2</Value></Le>
            </Break>

            <Assign><Sequence/><Arg Name="Lat2"/><Units:degree/><Value>NaN</Value></Assign>

            <Assign><Sequence/><Arg Name="Lon2"/><Units:degree/><Value>NaN</Value></Assign>

        </Aggregate>

        <Aggregate Id="Leg4">

            <Sequence/>

            <Break><Arg Name="leg"/>
                <Le><Units:count/><Value>3</Value></Le>
            </Break>

            <Assign><Sequence/><Arg Name="Lat3"/><Units:degree/><Value>NaN</Value></Assign>

            <Assign><Sequence/><Arg Name="Lon3"/><Units:degree/><Value>NaN</Value></Assign>

        </Aggregate>

        <Aggregate Id="Leg5">

            <Sequence/>

            <Break><Arg Name="leg"/>
                <Le><Units:count/><Value>4</Value></Le>
            </Break>

            <Assign><Sequence/><Arg Name="Lat4"/><Units:degree/><Value>NaN</Value></Assign>

            <Assign><Sequence/><Arg Name="Lon4"/><Units:degree/><Value>NaN</Value></Assign>

        </Aggregate>

        <Aggregate Id="Leg6">

            <Sequence/>

            <Break><Arg Name="leg"/>
                <Le><Units:count/><Value>5</Value></Le>
            </Break>

            <Assign><Sequence/><Arg Name="Lat5"/><Units:degree/><Value>NaN</Value></Assign>

            <Assign><Sequence/><Arg Name="Lon5"/><Units:degree/><Value>NaN</Value></Assign>

        </Aggregate>

        <Aggregate Id="Leg7">

            <Sequence/>

            <Break><Arg Name="leg"/>
                <Le><Units:count/><Value>6</Value></Le>
            </Break>

            <Assign><Sequence/><Arg Name="Lat6"/><Units:degree/><Value>NaN</Value></Assign>

            <Assign><Sequence/><Arg Name="Lon6"/><Units:degree/><Value>NaN</Value></Assign>

        </Aggregate>

        <Aggregate Id="Leg8">

            <Sequence/>

            <Break><Arg Name="leg"/>
                <Le><Units:count/><Value>7</Value></Le>
            </Break>

            <Assign><Sequence/><Arg Name="Lat7"/><Units:degree/><Value>NaN</Value></Assign>

            <Assign><Sequence/><Arg Name="Lon7"/><Units:degree/><Value>NaN</Value></Assign>

        </Aggregate>

    </Aggregate>

    <Aggregate Id="Lap">

        <Sequence/>

        <Syslog Severity="Important">Starting Lap</Syslog>

        <Syslog Severity="Important">Lat[1] = <Arg Name="Lat1"/><Units:degree/> Lon[1] = <Arg Name="Lon1"/><Units:degree/></Syslog>

        <Syslog Severity="Important">Lat[2] = <Arg Name="Lat2"/><Units:degree/> Lon[2] = <Arg Name="Lon2"/><Units:degree/></Syslog>

        <Syslog Severity="Important">Lat[3] = <Arg Name="Lat3"/><Units:degree/> Lon[3] = <Arg Name="Lon3"/><Units:degree/></Syslog>

        <Syslog Severity="Important">Lat[4] = <Arg Name="Lat4"/><Units:degree/> Lon[4] = <Arg Name="Lon4"/><Units:degree/></Syslog>

        <Syslog Severity="Important">Lat[5] = <Arg Name="Lat5"/><Units:degree/> Lon[5] = <Arg Name="Lon5"/><Units:degree/></Syslog>

        <Syslog Severity="Important">Lat[6] = <Arg Name="Lat6"/><Units:degree/> Lon[6] = <Arg Name="Lon6"/><Units:degree/></Syslog>

        <Syslog Severity="Important">Lat[7] = <Arg Name="Lat7"/><Units:degree/> Lon[7] = <Arg Name="Lon7"/><Units:degree/></Syslog>

        <Syslog Severity="Important">Lat[8] = <Arg Name="Lat8"/><Units:degree/> Lon[8] = <Arg Name="Lon8"/><Units:degree/></Syslog>

<!-- Kick off the first ESP sample on mission start? -->

        <Aggregate Id="SampleOnStart">

            <Sequence/>

            <When>
                <Not><Arg Name="FirstSample"/></Not>
                <And>
                    <Elapsed><Arg Name="ElapsedSinceLastSampleStart"/></Elapsed><Gt><Arg Name="FirstSampleTimeOffset"/></Gt>
                </And>
            </When>

<!-- Start the first ESP sample. -->
            <Syslog Severity="Important">Acquiring first sample.</Syslog>

            <Assign><Sequence/><Arg Name="SampleInProgress"/><True/></Assign>

            <Assign><Sequence/><Arg Name="FirstSample"/><True/></Assign>

        </Aggregate>

<!-- The following aggregates dispatch the waypoints behaviors -->

        <Aggregate Id="Wpt1">

            <Sequence/>

            <Syslog Severity="Important">Navigating to box start WP. YoYoMaxDepth:<Arg Name="YoYoMaxDepth1"/><Units:meter/></Syslog>

            <Guidance:DepthEnvelope>
                <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="YoYoMaxDepth1"/></Setting>
            </Guidance:DepthEnvelope>

            <Guidance:Waypoint>
                <Sequence/>
                <Setting><Guidance:Waypoint.latitude/><Arg Name="Lat1"/></Setting>
                <Setting><Guidance:Waypoint.longitude/><Arg Name="Lon1"/></Setting>
            </Guidance:Waypoint>

        </Aggregate>

        <Aggregate Id="Wpt2">

            <Sequence/>

            <Syslog Severity="Important">Navigating to WP2. YoYoMaxDepth: <Arg Name="YoYoMaxDepth2"/><Units:meter/></Syslog>

            <Guidance:DepthEnvelope>
                <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="YoYoMaxDepth2"/></Setting>
            </Guidance:DepthEnvelope>

            <Guidance:Waypoint>
                <Sequence/>
                <Setting><Guidance:Waypoint.latitude/><Arg Name="Lat2"/></Setting>
                <Setting><Guidance:Waypoint.longitude/><Arg Name="Lon2"/></Setting>
            </Guidance:Waypoint>

        </Aggregate>

        <Aggregate Id="Wpt3">

            <Sequence/>

            <Syslog Severity="Important">Navigating to WP3. YoYoMaxDepth: <Arg Name="YoYoMaxDepth3"/><Units:meter/></Syslog>

            <Guidance:DepthEnvelope>
                <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="YoYoMaxDepth3"/></Setting>
            </Guidance:DepthEnvelope>

            <Guidance:Waypoint>
                <Sequence/>
                <Setting><Guidance:Waypoint.latitude/><Arg Name="Lat3"/></Setting>
                <Setting><Guidance:Waypoint.longitude/><Arg Name="Lon3"/></Setting>
            </Guidance:Waypoint>

        </Aggregate>

        <Aggregate Id="Wpt4">

            <Sequence/>

            <Syslog Severity="Important">Navigating to WP4. YoYoMaxDepth: <Arg Name="YoYoMaxDepth4"/><Units:meter/></Syslog>

            <Guidance:DepthEnvelope>
                <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="YoYoMaxDepth4"/></Setting>
            </Guidance:DepthEnvelope>

            <Guidance:Waypoint>
                <Sequence/>
                <Setting><Guidance:Waypoint.latitude/><Arg Name="Lat4"/></Setting>
                <Setting><Guidance:Waypoint.longitude/><Arg Name="Lon4"/></Setting>
            </Guidance:Waypoint>

        </Aggregate>

        <Aggregate Id="Wpt5">

            <Sequence/>

            <Syslog Severity="Important">Navigating to WP5. YoYoMaxDepth:<Arg Name="YoYoMaxDepth5"/><Units:meter/></Syslog>

            <Guidance:DepthEnvelope>
                <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="YoYoMaxDepth5"/></Setting>
            </Guidance:DepthEnvelope>

            <Guidance:Waypoint>
                <Sequence/>
                <Setting><Guidance:Waypoint.latitude/><Arg Name="Lat5"/></Setting>
                <Setting><Guidance:Waypoint.longitude/><Arg Name="Lon5"/></Setting>
            </Guidance:Waypoint>

        </Aggregate>

        <Aggregate Id="Wpt6">

            <Sequence/>

            <Syslog Severity="Important">Navigating to WP6. YoYoMaxDepth:<Arg Name="YoYoMaxDepth6"/><Units:meter/></Syslog>

            <Guidance:DepthEnvelope>
                <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="YoYoMaxDepth6"/></Setting>
            </Guidance:DepthEnvelope>

            <Guidance:Waypoint>
                <Sequence/>
                <Setting><Guidance:Waypoint.latitude/><Arg Name="Lat6"/></Setting>
                <Setting><Guidance:Waypoint.longitude/><Arg Name="Lon6"/></Setting>
            </Guidance:Waypoint>

        </Aggregate>

        <Aggregate Id="Wpt7">

            <Sequence/>

            <Syslog Severity="Important">Navigating to WP7. YoYoMaxDepth: <Arg Name="YoYoMaxDepth7"/><Units:meter/></Syslog>

            <Guidance:DepthEnvelope>
                <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="YoYoMaxDepth7"/></Setting>
            </Guidance:DepthEnvelope>

            <Guidance:Waypoint>
                <Sequence/>
                <Setting><Guidance:Waypoint.latitude/><Arg Name="Lat7"/></Setting>
                <Setting><Guidance:Waypoint.longitude/><Arg Name="Lon7"/></Setting>
            </Guidance:Waypoint>

        </Aggregate>

        <Aggregate Id="Wpt8">

            <Sequence/>

            <Syslog Severity="Important">Navigating to WP8. YoYoMaxDepth: <Arg Name="YoYoMaxDepth8"/><Units:meter/></Syslog>

            <Guidance:DepthEnvelope>
                <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="YoYoMaxDepth8"/></Setting>
            </Guidance:DepthEnvelope>

            <Guidance:Waypoint>
                <Sequence/>
                <Setting><Guidance:Waypoint.latitude/><Arg Name="Lat8"/></Setting>
                <Setting><Guidance:Waypoint.longitude/><Arg Name="Lon8"/></Setting>
            </Guidance:Waypoint>

        </Aggregate>

        <Aggregate Id="CircleWpt8">

            <Sequence/>

            <Break>
                <Not><Arg Name="SampleInProgress"/></Not>
            </Break>

            <Syslog Severity="Important">Circling at WP8 until sample is finished.</Syslog>

            <Guidance:DepthEnvelope>
                <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="YoYoMaxDepth8"/></Setting>
            </Guidance:DepthEnvelope>

            <Aggregate Id="CircleWrapper">

                <Sequence Repeat="4096"/>

                <Assign><Parallel/><Control:HorizontalControl.kwpHeading/><Units:radian_per_meter/><Value>0.010</Value></Assign>

                <Guidance:Circle>
                    <Sequence/>
                    <Setting><Guidance:Circle.latitude/><Arg Name="Lat8"/></Setting>
                    <Setting><Guidance:Circle.longitude/><Arg Name="Lon8"/></Setting>
                    <Setting><Guidance:Circle.radius/><Units:meter/><Value>100</Value></Setting>
                    <Setting><Guidance:Circle.maxError/><Units:meter/><Value>10</Value></Setting>
                    <Setting><Guidance:Circle.turnToPort/><False/></Setting>
                </Guidance:Circle>

            </Aggregate>

        </Aggregate>

    </Aggregate>

</Mission>
