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

    <DefineArg Name="Wpt1Lat"><Units:degree/><Value>36.815</Value></DefineArg>

    <DefineArg Name="Wpt1Lon"><Units:degree/><Value>-121.869</Value></DefineArg>

    <DefineArg Name="Speed1"><Description>
        Speed for leg 1
    </Description><Units:meter_per_second/><Value>1</Value></DefineArg>

    <DefineArg Name="Wpt2Lat"><Units:degree/><Value>36.829</Value></DefineArg>

    <DefineArg Name="Wpt2Lon"><Units:degree/><Value>-121.886</Value></DefineArg>

    <DefineArg Name="Speed2"><Description>
        Speed for leg 2
    </Description><Units:meter_per_second/><Value>.75</Value></DefineArg>

    <DefineArg Name="Wpt3Lat"><Units:degree/><Value>36.816</Value></DefineArg>

    <DefineArg Name="Wpt3Lon"><Units:degree/><Value>-121.883</Value></DefineArg>

    <DefineArg Name="Speed3"><Description>
        Speed for leg 3
    </Description><Units:meter_per_second/><Value>.60</Value></DefineArg>

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

    <DefineArg Name="MinAltitude"><Description>
        Minimum height above the sea floor for the entire mission.
    </Description><Units:meter/><Value>7.0</Value></DefineArg>

    <DefineArg Name="DepthShallow"><Description>
        Depth for transit
    </Description><Units:meter/><Value>15</Value></DefineArg>

    <DefineArg Name="DepthDeep"><Description>
        Depth for test
    </Description><Units:meter/><Value>32</Value></DefineArg>

    <DefineArg Name="NeedCommsTime"><Description>
        Elapsed time after previous surface communications when vehicle will
        begin to ascend for additional surface communications
    </Description><Units:minute/><Value>50</Value></DefineArg>

    <DefineArg Name="TimeoutDuration"><Description>
        Maximum length of mission
    </Description><Units:minute/><Value>250</Value></DefineArg>

    <DefineArg Name="MassHold"><Description>
        Set to True in order to hold mass at user defined position, False to
        allow mass to run on its own.
    </Description><True/></DefineArg>

    <DefineArg Name="MassDefault"><Description>
        Static setting for mass when the mass position is held.
    </Description><Control:VerticalControl.massDefault/></DefineArg>

    <DefineArg Name="massDeadband"><Description>
        Sets the value of VerticalControl.massDeadband
    </Description><Units:millimeter/><Value>0.0</Value></DefineArg>

    <DefineArg Name="BuoyancyHold"><Description>
        Set to True in order to hold buoyancy at neutral position, False to
        allow buoyancy to run on its own.
    </Description><True/></DefineArg>

    <DefineArg Name="BuoyancyNeutral"><Description>
        Buoyancy bladder position when buoyancy is held. Defaults to
        buoyancyNeutral setting in the Config/Control.cfg file.
    </Description><Control:VerticalControl.buoyancyNeutral/></DefineArg>

    <DefineArg Name="ElevatorHold"><Description>
        Set to True in order to hold the elevators at neutral position, False to
        allow them to run on their own.
    </Description><False/></DefineArg>

    <DefineArg Name="ElevatorDefault"><Description>
        Static setting for elevator if elevator position is held.
    </Description><Units:degree/><Value>0.0</Value></DefineArg>

    <DefineArg Name="elevDeadband"><Description>
        Sets the value of VerticalControl.elevDeadband
    </Description><Units:degree/><Value>0.0</Value></DefineArg>

    <DefineArg Name="ElevIntInDepthMode"><Description>
        Sets VerticalControl.useElevIntInDepthMode value
    </Description><False/></DefineArg>

    <DefineArg Name="StopDepthExcursion"><Description>
        Sets VerticalControl.stopDepthExcursion within the triangle, but not
        during the transit.
    </Description><Control:VerticalControl.stopDepthExcursion/></DefineArg>

    <DefineArg Name="kdPitchMass"><Description>
        Sets the value of VerticalControl.kdPitchMass
    </Description><Control:VerticalControl.kdPitchMass/></DefineArg>

    <DefineArg Name="kiDepthOff"><Description>
        Sets the value of VerticalControl.kiDepthOff
    </Description><Control:VerticalControl.kiDepthOff/></DefineArg>

    <DefineArg Name="kiPitchMass"><Description>
        Sets the value of VerticalControl.kiPitchMass
    </Description><Control:VerticalControl.kiPitchMass/></DefineArg>

    <DefineArg Name="kpPitchMass"><Description>
        Sets the value of VerticalControl.kpPitchMass
    </Description><Control:VerticalControl.kpPitchMass/></DefineArg>

    <DefineArg Name="maxDiveAccel"><Description>
        Sets the value of VerticalControl.maxDiveAccel
    </Description><Control:VerticalControl.maxDiveAccel/></DefineArg>

    <Timeout Duration="TimeoutDuration"/>

    <Guidance:AltitudeEnvelope>
        <Parallel/>
        <Setting><Guidance:AltitudeEnvelope.minAltitude/><Arg Name="MinAltitude"/></Setting>
    </Guidance:AltitudeEnvelope>

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

    <Guidance:OffshoreEnvelope>
        <Parallel/>
        <Setting><Guidance:OffshoreEnvelope.minOffshore/><Units:kilometer/><Value>1</Value></Setting>
    </Guidance:OffshoreEnvelope>

    <ReadData Strategy="AllDevices">
        <Universal:platform_orientation/>
    </ReadData>

    <Aggregate Id="SURFACECOMMS">

        <Sequence/>

        <Guidance:GoToSurface>
            <Progression/>
        </Guidance:GoToSurface>

        <Aggregate>

            <Sequence/>

            <Preemptive>
                <True />
            </Preemptive>

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

            <ReadDatum>
                <Universal:latitude_fix />
            </ReadDatum>

            <ReadDatum>
                <Timeout Duration="P30M">
                    <Assign Id="TouchComms"><Sequence/><Universal:platform_communications/></Assign>
                </Timeout>
                <Universal:platform_communications />
            </ReadDatum>

            <ReadDatum>
                <Universal:latitude_fix />
            </ReadDatum>

        </Aggregate>

    </Aggregate>

<!-- GPS Update.  Don't go too long w/o a GPS fix. -->

    <Aggregate Id="NeedComms">

        <When>
            <Elapsed><Universal:time_fix/></Elapsed>
            <Gt><Arg Name="NeedCommsTime"/></Gt>
        </When>

        <Call Id="NEEDCOMMS" RefId="SURFACECOMMS" />

    </Aggregate>

    <Aggregate Id="WaypointOne">

        <Sequence/>

<!-- Go to Wpt1 and start from there -->

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

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

        <Guidance:Waypoint Id="WaypointW1">
            <Sequence/>
            <Setting><Guidance:Waypoint.latitude/><Arg Name="Wpt1Lat"/></Setting>
            <Setting><Guidance:Waypoint.longitude/><Arg Name="Wpt1Lon"/></Setting>
        </Guidance:Waypoint>

        <Call Id="PHONEHOMEWPT1" RefId="SURFACECOMMS"/>

    </Aggregate>

    <Aggregate Id="ThreeLegs">

        <Sequence/>

        <Aggregate Id="BuoyancyHold">

            <While>
                <Arg Name="BuoyancyHold"/>
            </While>

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

        </Aggregate>

        <Aggregate Id="MassHold">

            <While>
                <Arg Name="MassHold"/>
            </While>

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

        </Aggregate>

        <Aggregate Id="ElevatorHold">

            <While>
                <Arg Name="ElevatorHold"/>
            </While>

            <Guidance:Pitch>
                <Parallel/>
                <Setting><Guidance:Pitch.elevatorAngle/><Arg Name="ElevatorDefault"/></Setting>
            </Guidance:Pitch>

        </Aggregate>

        <Assign><Parallel/><Control:VerticalControl.useElevIntInDepthMode/><Arg Name="ElevIntInDepthMode"/></Assign>

        <Assign><Parallel/><Control:VerticalControl.elevDeadband/><Arg Name="elevDeadband"/></Assign>

        <Assign><Parallel/><Control:VerticalControl.kdPitchMass/><Arg Name="kdPitchMass"/></Assign>

        <Assign><Parallel/><Control:VerticalControl.kiDepthOff/><Arg Name="kiDepthOff"/></Assign>

        <Assign><Parallel/><Control:VerticalControl.kiPitchMass/><Arg Name="kiPitchMass"/></Assign>

        <Assign><Parallel/><Control:VerticalControl.kpPitchMass/><Arg Name="kpPitchMass"/></Assign>

        <Assign><Parallel/><Control:VerticalControl.massDeadband/><Arg Name="massDeadband"/></Assign>

        <Assign><Parallel/><Control:VerticalControl.maxDiveAccel/><Arg Name="maxDiveAccel"/></Assign>

        <Assign><Parallel/><Control:VerticalControl.stopDepthExcursion/><Arg Name="StopDepthExcursion"/></Assign>

        <Aggregate Id="TestDrive">

            <Sequence/>

            <Aggregate Id="Speed1">

                <Sequence/>

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

                <Guidance:Pitch>
                    <Parallel/>
                    <Setting><Guidance:Pitch.depth/><Arg Name="DepthDeep"/></Setting>
                </Guidance:Pitch>

                <Guidance:Waypoint Id="Wpt2">
                    <Sequence/>
                    <Setting><Guidance:Waypoint.latitude/><Arg Name="Wpt2Lat"/></Setting>
                    <Setting><Guidance:Waypoint.longitude/><Arg Name="Wpt2Lon"/></Setting>
                </Guidance:Waypoint>

                <Call Id="PHONEHOMEWPT2" RefId="SURFACECOMMS"/>

            </Aggregate>

            <Aggregate Id="Speed2">

                <Sequence/>

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

                <Guidance:Pitch>
                    <Parallel/>
                    <Setting><Guidance:Pitch.depth/><Arg Name="DepthDeep"/></Setting>
                </Guidance:Pitch>

                <Guidance:Waypoint Id="Wpt3">
                    <Sequence/>
                    <Setting><Guidance:Waypoint.latitude/><Arg Name="Wpt3Lat"/></Setting>
                    <Setting><Guidance:Waypoint.longitude/><Arg Name="Wpt3Lon"/></Setting>
                </Guidance:Waypoint>

                <Call Id="PHONEHOMEWPT3" RefId="SURFACECOMMS"/>

            </Aggregate>

            <Aggregate Id="Speed3">

                <Sequence/>

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

                <Guidance:Pitch>
                    <Parallel/>
                    <Setting><Guidance:Pitch.depth/><Arg Name="DepthDeep"/></Setting>
                </Guidance:Pitch>

                <Guidance:Waypoint Id="Wpt1">
                    <Sequence/>
                    <Setting><Guidance:Waypoint.latitude/><Arg Name="Wpt1Lat"/></Setting>
                    <Setting><Guidance:Waypoint.longitude/><Arg Name="Wpt1Lon"/></Setting>
                </Guidance:Waypoint>

                <Call Id="PHONEHOMEWPT1" RefId="SURFACECOMMS"/>

            </Aggregate>

        </Aggregate>

    </Aggregate>

</Mission>
