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

    <Description>
        After transit, this mission dives to yo-yo min depth, turns on red
        lights and camera, and begins the cylinder. Lights switch between
        red/white every LightDeltaTimeSetting minutes.
    </Description>

<!-- Almost every mission should start with an overall timeout and a NeedCommsTime. Drift Missions will have an acoustic timeout instead of a NeedCommsTime. -->

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

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

    <DefineArg Name="NeedCommsTimeInTransit"><Description>
        On the way transiting to the surveying location, how often to surface
        for commumications
    </Description><Units:minute/><Value>30</Value></DefineArg>

    <DefineArg Name="BeingInterrogatedTimeout"><Description>
        If the vehicle does not receive an acoustic signal for more than this
        length of time, it will surface for communications. Set longer than
        MissionTimeout to effectively disable.
    </Description><Units:hour/><Value>1</Value></DefineArg>

    <DefineArg Name="TrackAcousticTarget"><Description>
        Whether to track an acoustic target at all.
    </Description><True/></DefineArg>

<!--debug
    </Description><False/></DefineArg>
-->

    <DefineArg Name="TrackAcousticTargetDuringTransit"><Description>
        Whether to track an acoustic target during transit (on condition that
        TrackAcousticTarget is True).
<!--debug
    </Description><True/></DefineArg>
-->
    </Description><False/></DefineArg>

    <DefineArg Name="AcousticTargetContactLabel"><Description>
        The acoustic address of the asset to be tracked
    </Description><Units:count/><Value>0</Value></DefineArg>

    <DefineArg Name="AcousticTargetDepth"><Description>
        Depth of acoustic target if known and fixed (or nearly fixed). For
        example, if the acoustic target is a Wave Glider, set it to zero. This
        will improve 2D projected position estimates in the Earth reference
        frame. Defaults to NaN.
    </Description><Units:meter/><Value>NaN</Value></DefineArg>

    <DefineArg Name="AcousticTargetContactTimeout"><Description>
        Only use a sufficiently fresh handshake to update the tracking center.
    </Description><Units:minute/><Value>15</Value></DefineArg>

    <DefineArg Name="PeriodOfParameterSetting"><Description>
        Period of taking settings for setting samplers. Set to a large number
        (e.g., 20000 minutes = 14 days) to practically diable this
        functionality.
    </Description><Units:minute/><Value>10.0</Value></DefineArg>

    <DefineArg Name="LightDeltaTimeSetting"><Description>
        Period of red versus white lights.
    </Description><Units:minute/><Value>5.0</Value></DefineArg>

    <DefineArg Name="SpeedTransit"><Description>
        Vehicle speed when transiting to the surveying location.
    </Description><Units:meter_per_second/><Value>1.0</Value></DefineArg>

    <DefineArg Name="SpeedSurveySetting"><Description>
        Value for setting vehicle speed when surveying on cylinder yoyo.
    </Description><Units:meter_per_second/><Value>1.0</Value></DefineArg>

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

    <DefineArg Name="YoYoMinDepthSetting"><Description>
        Value for setting minimum depth while performing the YoYo behavior.
    </Description><Units:meter/><Value>40</Value></DefineArg>

    <DefineArg Name="YoYoMaxDepthSetting"><Description>
        Value for setting maximum depth while performing the YoYo behavior.
    </Description><Units:meter/><Value>50</Value></DefineArg>

    <DefineArg Name="InitDepthTimeout"><Description>
        Maximum time duration for the vehicle to reach the initial yo-yo depth.
        The vehicle will switch over to attempting yo-yos after the timeout is
        expired.
    </Description><Units:minute/><Value>20</Value></DefineArg>

    <DefineArg Name="TransitYoYoMinDepth"><Description>
        Minimum yoyo depth while transiting to the surveying location.
    </Description><Units:meter/><Value>10</Value></DefineArg>

    <DefineArg Name="TransitYoYoMaxDepth"><Description>
        Maximum yoyo depth while transiting to the surveying location.
    </Description><Units:meter/><Value>50</Value></DefineArg>

    <DefineArg Name="TransitCaptureRadius"><Description>
        Waypoint capture radius for transiting to the surveying location.
    </Description><Units:meter/><Value>100</Value></DefineArg>

    <DefineArg Name="CylinderRadiusSetting"><Description>
        Value for setting radius of cylinder centered at the surveying location.
    </Description><Units:meter/><Value>100</Value></DefineArg>

    <DefineArg Name="MaxCirclesOnCylinder"><Description>
        Maximum number of circles on cylinder.
    </Description><Units:count/><Value>1000</Value></DefineArg>

<!--debug
    </Description><Units:count/><Value>3</Value></DefineArg>
-->

    <DefineArg Name="TransitLatitude"><Description>
        The latitude of the surveying location. If NaN, will skip transit.
    </Description><Units:degree/><Value>NaN</Value></DefineArg>

<!--debug
    </Description><Units:degree/><Value>36.805</Value></DefineArg>
-->

    <DefineArg Name="TransitLongitude"><Description>
        The longitude of the surveying location. If NaN, will skip transit.
    </Description><Units:degree/><Value>NaN</Value></DefineArg>

<!--debug
    </Description><Units:degree/><Value>-121.825</Value></DefineArg>
-->

    <DefineArg Name="CenterLatitude"><Description>
        The latitude of the center of the circle. Fill this in to specify a
        start position, it will be overwritten once the vehicle receives an
        acoustic signal from the contact.
    </Description><Units:degree/><Value>NaN</Value></DefineArg>

    <DefineArg Name="CenterLongitude"><Description>
        The longitude of the center of the circle. Fill this in to specify a
        start position, it will be overwritten once the vehicle receives an
        acoustic signal from the contact.
    </Description><Units:degree/><Value>NaN</Value></DefineArg>

<!-- Use caution when changing these. -->

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

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

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

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

    <DefineArg Name="TrackingUpdatePeriod"><Description>
        How long to wait between acoustic queries
    </Description><Units:second/><Value>15</Value></DefineArg>

    <DefineArg Name="NumberOfPings"><Description>
        Number of return pings to request with each acoustic query (more than 1
        will activate oneway mode)
    </Description><Units:count/><Value>1</Value></DefineArg>

    <DefineArg Name="NumberOfFixesLowPass"><Description>
        Number of fixes to average to produce smoothed lat/lon/dep output
        (initialized to 4).
    </Description><Units:count/><Value>4</Value></DefineArg>

    <DefineArg Name="NumberOfStartingFixesToIgnore"><Description>
        Number of fixes to ignore at the start of mission (as the vehicle just
        leaves surface, contact's location estimate especailly bearing can be
        erroneous. Initialized to 8, corresponding to 2 minutes if query
        interval TrackingUpdatePeriod = 15 s.
    </Description><Units:count/><Value>8</Value></DefineArg>

    <DefineArg Name="CylinderCircleMaxError"><Description>
        If this distance away from the circle, drive straight towards (or away
        from the center). Otherwise, try to reduce distance from the ideal
        circle.
    </Description><Units:meter/><Value>100</Value></DefineArg>

    <DefineArg Name="CylinderCircleTurnToPort"><Description>
        If true, vehicle turns to the left around the center point. If false,
        vehicle turns to the right.
    </Description><False/></DefineArg>

    <DefineArg Name="KwpHeading"><Description>
        Used to relax waypoint cross-track error constant that is adjusted for
        docking. (You can override this setting by passing an argument.)
    </Description><Units:radian_per_meter/><Value>0.010</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>

    <DefineArg Name="BuoyancyNeutral"><Description>
        Buoyancy bladder position while performing the YoYo behavior. Defaults
        to buoyancyNeutral setting in the Config/Control.cfg file. Set to NaN cc
        for active buoyancy
    </Description><Control:VerticalControl.buoyancyNeutral/></DefineArg>

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

<!-- Internal variables that you should not change -->

    <DefineArg Name="LightDeltaTime"><Description>
        Period of red versus white lights.
    </Description><Units:minute/><Value>5.0</Value></DefineArg>

    <DefineArg Name="SpeedSurvey"><Description>
        Vehicle speed when surveying on cylinder yoyo.
    </Description><Units:meter_per_second/><Value>1.0</Value></DefineArg>

    <DefineArg Name="YoYoMinDepth"><Description>
        Minimum depth while performing the YoYo behavior. Initialized to 1.5 m.
    </Description><Units:meter/><Value>1.5</Value></DefineArg>

    <DefineArg Name="YoYoMaxDepth"><Description>
        Maximum depth while performing the YoYo behavior. Initialized to 20 m.
    </Description><Units:meter/><Value>20</Value></DefineArg>

    <DefineArg Name="CylinderRadius"><Description>
        Radius of cylinder centered at the surveying location. Initialized to
        100 m.
    </Description><Units:meter/><Value>100</Value></DefineArg>

    <DefineArg Name="FlagFirstTimeParameterSetting"><Description>
        Flag of first time setting samplers (initialized to True).
    </Description><True/></DefineArg>

    <DefineArg Name="ContactLatitudeLowpass"><Description>
        Low-pass filtered latitude of contact (initialized to NaN).
    </Description><Units:degree/><Value>NaN</Value></DefineArg>

    <DefineArg Name="ContactLongitudeLowpass"><Description>
        Low-pass filtered longitude of contact (initialized to NaN).
    </Description><Units:degree/><Value>NaN</Value></DefineArg>

    <DefineArg Name="FromLastTimeFixToCenterUpdate"><Description>
        Elapsed time from last time-fix to center update time (initialized to
        zero).
    </Description><Units:minute/><Value>0</Value></DefineArg>

    <DefineArg Name="FromLastTimeFixToParameterSetting"><Description>
        Elapsed time from last time-fix to setting of samplers.
    </Description><Units:minute/><Value>NaN</Value></DefineArg>

    <DefineArg Name="LastLightSwitchTime"><Description>
        Elapsed time from last time the light color was switched.
    </Description><Units:minute/><Value>NaN</Value></DefineArg>

    <DefineArg Name="WhiteLightsRequested"><Description>
        Indicates white lights should be turned on (default is red to start so
        we don't scare the fish). If false, red will be turned on.
    </Description><False/></DefineArg>

    <DefineArg Name="TransitWaypointCompleted"><Description>
        Transit waypoint is completed (initialized to false).
    </Description><False/></DefineArg>

<!-- Missions should almost always start with a timeout and a NeedComms aggregate. Drift missions will not use NeedComms. -->

    <Timeout Duration="MissionTimeout"/>

<!-- Missions should almost always start with standard safety 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>

    <Insert Filename="Insert/AbortDrift.xml">
        <RedefineArg Name="AcousticTimeout"><Arg Name="BeingInterrogatedTimeout"/></RedefineArg>
    </Insert>

<!-- Many missions will keep mass position fixed at the default. -->

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

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

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

    <Aggregate Id="SetAllParameters">

        <When>
            <Called/>
        </When>

        <Assign><Sequence/><Arg Name="SpeedSurvey"/><Arg Name="SpeedSurveySetting"/></Assign>

        <Assign><Sequence/><Arg Name="YoYoMinDepth"/><Arg Name="YoYoMinDepthSetting"/></Assign>

        <Assign><Sequence/><Arg Name="YoYoMaxDepth"/><Arg Name="YoYoMaxDepthSetting"/></Assign>

        <Assign><Sequence/><Arg Name="CylinderRadius"/><Arg Name="CylinderRadiusSetting"/></Assign>

        <Assign><Sequence/><Arg Name="LightDeltaTime"/><Arg Name="LightDeltaTimeSetting"/></Assign>

        <Syslog Severity="Important">Set SpeedSurvey = <Arg Name="SpeedSurvey"/><Units:meter_per_second/>, YoYoMinDepth = <Arg Name="YoYoMinDepth"/><Units:meter/>, YoYoMaxDepth = <Arg Name="YoYoMaxDepth"/><Units:meter/>, CylinderRadius = <Arg Name="CylinderRadius"/><Units:meter/>, LightingPeriod = <Arg Name="LightDeltaTime"/><Units:minute/>.</Syslog>

    </Aggregate>

    <Aggregate Id="TrackingAcousticTarget">

        <While>
            <Arg Name="TrackAcousticTarget"/>
            <And><Arg Name="TrackAcousticTargetDuringTransit"/></And>
            <Or><Arg Name="TrackAcousticTarget"/><And><Not><Arg Name="TrackAcousticTargetDuringTransit"/></Not><And><Arg Name="TransitWaypointCompleted"/></And></And></Or>
            <Or><Arg Name="TrackAcousticTarget"/><And><IsNaN><Arg Name="TransitLatitude"/>
            </IsNaN></And></Or>
            <Or><Arg Name="TrackAcousticTarget"/><And><IsNaN><Arg Name="TransitLongitude"/>
            </IsNaN></And></Or>
        </While>

        <Estimation:Tracking>
            <Parallel/>
            <Setting><Estimation:Tracking.contactLabelSetting/><Arg Name="AcousticTargetContactLabel"/></Setting>
            <Setting><Estimation:Tracking.numberOfSamplesSetting/><Arg Name="NumberOfPings"/></Setting>
            <Setting><Estimation:Tracking.updatePeriodSetting/><Arg Name="TrackingUpdatePeriod"/></Setting>
            <Setting><Estimation:Tracking.numFixesLowPassSetting/><Arg Name="NumberOfFixesLowPass"/></Setting>
            <Setting><Estimation:Tracking.numStartingFixesToIgnoreSetting/><Arg Name="NumberOfStartingFixesToIgnore"/></Setting>
            <Setting><Estimation:Tracking.contactDepthSetting/><Arg Name="AcousticTargetDepth"/></Setting>
        </Estimation:Tracking>

    </Aggregate>

    <Aggregate Id="MissionStart">

        <Sequence/>

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

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

    </Aggregate>

    <Aggregate Id="TransitToSurveyingLocation">

        <Sequence/>

        <Break>
            <IsNaN><Arg Name="TransitLatitude"/>
            </IsNaN>
            <Or><IsNaN><Arg Name="TransitLongitude"/>
            </IsNaN></Or>
        </Break>

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

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

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

        <Guidance:DepthEnvelope>
            <Parallel/>
            <Setting><Guidance:DepthEnvelope.minDepth/><Arg Name="TransitYoYoMinDepth"/></Setting>
            <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="TransitYoYoMaxDepth"/></Setting>
            <Setting><Guidance:DepthEnvelope.downPitch/><Arg Name="YoYoDownPitch"/></Setting>
            <Setting><Guidance:DepthEnvelope.upPitch/><Arg Name="YoYoUpPitch"/></Setting>
        </Guidance:DepthEnvelope>

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

        <Guidance:Buoyancy>
            <Parallel/>
            <Setting><Guidance:Buoyancy.position/><Arg Name="BuoyancyNeutral"/></Setting>
        </Guidance:Buoyancy>

        <Guidance:Waypoint>
            <Sequence/>
            <Setting><Guidance:Waypoint.latitude/><Arg Name="TransitLatitude"/></Setting>
            <Setting><Guidance:Waypoint.longitude/><Arg Name="TransitLongitude"/></Setting>
            <Setting><Guidance:Waypoint.captureRadius/><Arg Name="TransitCaptureRadius"/></Setting>
        </Guidance:Waypoint>

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

    </Aggregate>

    <Aggregate Id="InitializeWithGPSlatlon">

        <Sequence/>

        <When>
            <IsNaN><Arg Name="CenterLatitude"/>
            </IsNaN>
            <Or><IsNaN><Arg Name="CenterLongitude"/>
            </IsNaN></Or>
        </When>

        <Assign><Sequence/><Arg Name="CenterLatitude"/><Universal:latitude_fix/></Assign>

        <Assign><Sequence/><Arg Name="CenterLongitude"/><Universal:longitude_fix/></Assign>

        <Syslog Severity="Important">Initialize CenterLatitude and CenterLongitude to GPS fix: <Arg Name="CenterLatitude"/><Units:degree/>, <Arg Name="CenterLongitude"/><Units:degree/>.</Syslog>

    </Aggregate>

    <Aggregate Id="UpdateCenter">

        <When>
            <Elapsed><Estimation:Tracking.range_to_contact/></Elapsed>
            <Lt><Arg Name="AcousticTargetContactTimeout"/></Lt>
        </When>

        <Assign><Sequence/><Arg Name="ContactLatitudeLowpass"/><Estimation:Tracking.contact_latitude_lowpass/></Assign>

        <Assign><Sequence/><Arg Name="ContactLongitudeLowpass"/><Estimation:Tracking.contact_longitude_lowpass/></Assign>

        <Aggregate Id="UpdateWithContactLowpassLatLon">

            <Sequence/>

            <When>
                <Not><IsNaN><Arg Name="ContactLatitudeLowpass"/>
                </IsNaN></Not>
                <And><Not><IsNaN><Arg Name="ContactLongitudeLowpass"/>
                </IsNaN></Not></And>
                <And><Elapsed><Universal:time_fix/></Elapsed><Ge><Arg Name="FromLastTimeFixToCenterUpdate"/><Add><Arg Name="TrackingUpdatePeriod"/></Add></Ge></And>
            </When>

            <Assign><Sequence/><Arg Name="CenterLatitude"/><Arg Name="ContactLatitudeLowpass"/></Assign>

            <Assign><Sequence/><Arg Name="CenterLongitude"/><Arg Name="ContactLongitudeLowpass"/></Assign>

            <Syslog Severity="Info">Updating. FromLastTimeFixToCenterUpdate, CenterLatitude, CenterLongitude = <Arg Name="FromLastTimeFixToCenterUpdate"/><Units:second/>, <Arg Name="CenterLatitude"/><Units:degree/>, <Arg Name="CenterLongitude"/><Units:degree/></Syslog>

            <Assign><Sequence/><Arg Name="FromLastTimeFixToCenterUpdate"/><Elapsed><Universal:time_fix/></Elapsed></Assign>

        </Aggregate>

    </Aggregate>

    <Aggregate Id="PeriodicSetting">

        <When>
            <Arg Name="FlagFirstTimeParameterSetting"/>
            <Or><Elapsed><Universal:time_fix/></Elapsed><Ge><Arg Name="FromLastTimeFixToParameterSetting"/><Add><Arg Name="PeriodOfParameterSetting"/></Add></Ge></Or>
        </When>

        <Call Id="SetLightingAndOtherParameters" RefId="SetAllParameters"/>

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

        <Assign><Sequence/><Arg Name="FromLastTimeFixToParameterSetting"/><Elapsed><Universal:time_fix/></Elapsed></Assign>

    </Aggregate>

    <Aggregate Id="InitialDive">

        <Description>
            Descend from to initial depth prior to beginning yo-yos and turning
            on the lights/camera.
        </Description>

        <Sequence/>

        <Guidance:Buoyancy>
            <Parallel/>
            <Setting><Guidance:Buoyancy.position/><Arg Name="BuoyancyNeutral"/></Setting>
        </Guidance:Buoyancy>

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

        <Guidance:Pitch>
            <Sequence/>
            <Timeout Duration="InitDepthTimeout">
                <Syslog Severity="Important">Timed out at current depth of <Universal:depth/><Units:meter/>. Switching to yo-yo command.</Syslog>
            </Timeout>
            <Setting><Guidance:Pitch.depth/><Arg Name="YoYoMinDepth"/></Setting>
        </Guidance:Pitch>

    </Aggregate>

<!-- Now that the initial dive is done, get on with the yo-yos -->

    <Aggregate Id="Cylinder">

        <Sequence/>

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

        <Guidance:DepthEnvelope>
            <Parallel/>
            <Setting><Guidance:DepthEnvelope.minDepth/><Arg Name="YoYoMinDepth"/></Setting>
            <Setting><Guidance:DepthEnvelope.maxDepth/><Arg Name="YoYoMaxDepth"/></Setting>
            <Setting><Guidance:DepthEnvelope.downPitch/><Arg Name="YoYoDownPitch"/></Setting>
            <Setting><Guidance:DepthEnvelope.upPitch/><Arg Name="YoYoUpPitch"/></Setting>
        </Guidance:DepthEnvelope>

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

        <Guidance:Buoyancy>
            <Parallel/>
            <Setting><Guidance:Buoyancy.position/><Arg Name="BuoyancyNeutral"/></Setting>
        </Guidance:Buoyancy>

<!-- Power Camera -->

        <ReadData Id="PowerCamera">
            <Sensor:PowerOnly.sampleLoad1/>
        </ReadData>

        <Syslog Severity="Info">Activating camera.</Syslog>

<!-- Wait one minute for camera to start recording -->

        <Guidance:Wait>
            <Sequence/>
            <Setting><Guidance:Wait.duration/><Units:second/><Value>25</Value></Setting>
        </Guidance:Wait>

<!-- Here we start the light clock and effectively turn on the default (red) lights -->

        <Assign><Sequence/><Arg Name="LastLightSwitchTime"/><Elapsed><Universal:time_fix/></Elapsed></Assign>

        <Syslog Severity="Info">Activating Red Lights.</Syslog>

<!-- As long as the time hasn't expired and white lights are requested, turn on the white ones -->

        <Aggregate Id="WhiteLights">

            <While>
                <Elapsed><Universal:time_fix/></Elapsed>
                <Le><Arg Name="LastLightSwitchTime"/><Add><Arg Name="LightDeltaTime"/></Add></Le>
                <And><Arg Name="WhiteLightsRequested"/></And>
            </While>

            <Aggregate Id="PowerRequest">

                <Sequence/>

<!-- Power White Lights -->

                <ReadData Id="PowerWhiteLights">
                    <Sensor:PowerOnly.sampleLoad3/>
                </ReadData>

            </Aggregate>

        </Aggregate>

<!-- As long as the time hasn't expired and white lights are NOT requested, turn on the red ones -->

        <Aggregate Id="RedLights">

            <While>
                <Elapsed><Universal:time_fix/></Elapsed>
                <Le><Arg Name="LastLightSwitchTime"/><Add><Arg Name="LightDeltaTime"/></Add></Le>
                <And><Not><Arg Name="WhiteLightsRequested"/></Not></And>
            </While>

            <Aggregate Id="PowerRequest">

                <Sequence/>

<!-- Power Red Lights -->

                <ReadData Id="PowerRedLights">
                    <Sensor:PowerOnly.sampleLoad2/>
                </ReadData>

            </Aggregate>

        </Aggregate>

<!-- These two aggregates below handle the logic for turning lights from white to red by setting the boolean and resetting the timer -->

        <Aggregate Id="FlipLightsWhite">

            <When>
                <Elapsed><Universal:time_fix/></Elapsed>
                <Ge><Arg Name="LastLightSwitchTime"/><Add><Arg Name="LightDeltaTime"/></Add></Ge>
                <And><Not><Arg Name="WhiteLightsRequested"/></Not></And>
            </When>

            <Aggregate>

                <Sequence/>

                <Syslog Severity="Info">Activating White Lights.</Syslog>

                <Assign><Parallel/><Arg Name="WhiteLightsRequested"/><True/></Assign>

                <Assign><Parallel/><Arg Name="LastLightSwitchTime"/><Elapsed><Universal:time_fix/></Elapsed></Assign>

            </Aggregate>

        </Aggregate>

        <Aggregate Id="FlipLightsRed">

            <When>
                <Elapsed><Universal:time_fix/></Elapsed>
                <Ge><Arg Name="LastLightSwitchTime"/><Add><Arg Name="LightDeltaTime"/></Add></Ge>
                <And><Arg Name="WhiteLightsRequested"/></And>
            </When>

            <Aggregate>

                <Sequence/>

                <Syslog Severity="Info">Activating Red Lights.</Syslog>

                <Assign><Parallel/><Arg Name="WhiteLightsRequested"/><False/></Assign>

                <Assign><Parallel/><Arg Name="LastLightSwitchTime"/><Elapsed><Universal:time_fix/></Elapsed></Assign>

            </Aggregate>

        </Aggregate>

        <Aggregate Id="CylinderYoYo">

            <Sequence/>

            <Syslog Severity="Important">Yoyo profile on a cylinder around location <Arg Name="CenterLatitude"/><Units:degree/>,<Arg Name="CenterLongitude"/><Units:degree/>, at radius = <Arg Name="CylinderRadius"/><Units:meter/>.</Syslog>

            <Aggregate Id="CylinderWrapper">

                <Sequence Repeat="MaxCirclesOnCylinder"/>

                <Assign><Parallel/><Control:HorizontalControl.kwpHeading/><Arg Name="KwpHeading"/></Assign>

                <Guidance:Circle>
                    <Sequence/>
                    <Setting><Guidance:Circle.latitude/><Arg Name="CenterLatitude"/></Setting>
                    <Setting><Guidance:Circle.longitude/><Arg Name="CenterLongitude"/></Setting>
                    <Setting><Guidance:Circle.radius/><Arg Name="CylinderRadius"/></Setting>
                    <Setting><Guidance:Circle.maxError/><Arg Name="CylinderCircleMaxError"/></Setting>
                    <Setting><Guidance:Circle.turnToPort/><Arg Name="CylinderCircleTurnToPort"/></Setting>
                </Guidance:Circle>

            </Aggregate>

        </Aggregate>

    </Aggregate>

</Mission>
