<?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="test_thruster_stop_and_go">

       <Description>
           This mission commands the vehicle actuators to a specified position/velocity.
           The thruster will toggle between 2 velocities over spcified time interval and repeat num.
       </Description>

<!-- The following arguments are input arguments -->

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

    <DefineArg Name="ThrusterPowerIntervalTime"><Description>
        Time duration to run in each thruster speed interval.
    </Description><Units:minute/><Value>2</Value></DefineArg>

    <DefineArg Name="ThrusterPowerIntervalRepeat"><Description>
        Number of times to repeat the thruster interval lap.
    </Description><Units:count/><Value>5</Value></DefineArg>

    <DefineArg Name="Speed1"><Description>
        Speed setting for speed during interval 1.
    </Description><Units:meter_per_second/><Value>0.0</Value></DefineArg>

    <DefineArg Name="Speed2"><Description>
        Speed setting for speed during interval 2 (meter_per_second; 1 m/s = 300 RPM).
    </Description><Units:meter_per_second/><Value>1.0</Value></DefineArg>


    <DefineArg Name="MassPosition"><Description>
        Static setting for mass during the mission (millimeter). Defaults to massDefault
        setting in the Config/Control.cfg file.

        Commanded values should fall between the permitted cofig range as defined by:
            - VerticalControl.massPositionLimitFwd  // Forward limit (toward nose = positive)
            - VerticalControl.massPositionLimitAft  // Backward limit (toward tail = negative)

    </Description><Control:VerticalControl.massDefault/></DefineArg>


    <DefineArg Name="BuoyancyPosition"><Description>
        Static setting for buoyancy during the mission (cubic_centimeter). Defaults to
        buoyancyNeutral setting in the Config/Control.cfg file.

        Commanded values should fall between the permitted cofig range as defined by:
        - VerticalControl.buoyancyLimitHiCC  // High limit (max bouncy)
        - VerticalControl.buoyancyLimitLoCC  // Low limit (min bouncy)

    </Description><Control:VerticalControl.buoyancyNeutral/></DefineArg>


    <DefineArg Name="RudderAngle"><Description>
        Static setting for rudder angle during the mission (degrees). Defaults to center (0 deg).

        Max value:  15 degrees, turn rudder to stbd, turn vehicle nose to port
        Max value: -15 degrees, turn rudder to port, turn vehicle nose to stbd

    </Description><Units:degree/><Value>0</Value></DefineArg>


    <DefineArg Name="ElevatorAngle"><Description>
        Static setting for elevator angle during the mission (degrees). Defaults to center (0 deg).

        Max value:  15 degrees, turn elevator up, pitch vehicle nose down (pitch < 0)
        Max value: -15 degrees, turn elevator down, pitch vehicle nose up (pitch > 0)

    </Description><Units:degree/><Value>0</Value></DefineArg>


    <DefineOutput Name="Speed"><Description>
        Mission variable (don't change).
        The mission will set this var to match the appropriate speed for per interval.
    </Description><Units:meter_per_second/><Value>0.0</Value></DefineOutput>


<!-- The timeout -->

    <Timeout Duration="MissionTimeout"/>

<!-- And now the mission -->

    <Aggregate Id="HoldMassPos">

        <Sequence Repeat="ThrusterPowerIntervalRepeat"/>

        <!-- Hold the VBS at pos -->
        <Guidance:Buoyancy>
            <Parallel/>
            <Setting><Guidance:Buoyancy.position/><Arg Name="BuoyancyPosition"/></Setting>
        </Guidance:Buoyancy>

        <!-- Hold the mass-shifter at pos -->
        <Guidance:Mass>
            <Parallel/>
            <Setting><Guidance:Mass.position/><Arg Name="MassPosition"/></Setting>
        </Guidance:Mass>

        <!-- Hold the rudder at pos -->
        <Guidance:Point>
            <Parallel/>
            <Setting><Guidance:Point.rudderAngle/><Arg Name="RudderAngle"/></Setting>
        </Guidance:Point>

        <!-- Hold the elevator at pos -->
        <Guidance:Pitch>
            <Parallel/>
            <Setting><Guidance:Pitch.elevatorAngle/><Arg Name="ElevatorAngle"/></Setting>
        </Guidance:Pitch>

        <Aggregate Id="speed1">

            <Sequence/>

            <!-- Command a speed in m/s -->
            <Guidance:SetSpeed>
                <Parallel/>
                <Setting><Guidance:SetSpeed.speed/><Arg Name="Speed1"/></Setting>
            </Guidance:SetSpeed>

            <!-- Keep mission running until timeout is expired -->
            <Guidance:Wait>
                <Sequence/>
                <Setting><Guidance:Wait.duration/><Arg Name="ThrusterPowerIntervalTime"/></Setting>
            </Guidance:Wait>

        </Aggregate>

        <Aggregate Id="speed2">

            <Sequence/>

            <!-- Command a speed in m/s -->
            <Guidance:SetSpeed>
                <Parallel/>
                <Setting><Guidance:SetSpeed.speed/><Arg Name="Speed2"/></Setting>
            </Guidance:SetSpeed>

            <!-- Keep mission running until timeout is expired -->
            <Guidance:Wait>
                <Sequence/>
                <Setting><Guidance:Wait.duration/><Arg Name="ThrusterPowerIntervalTime"/></Setting>
            </Guidance:Wait>

        </Aggregate>

    </Aggregate>

</Mission>
