<?xml version="1.0" encoding="UTF-8"?>
<DefineBehavior 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"
       Name="DepthEnvelope" Language="Lua">

    <Description>
        Overly simple example replacement for DepthEnvelope behavior. Only takes
        three settings: maxDepth, minDepth, and pitch
    </Description>

    <DefineSetting Name="maxDepthSet">
        <Guidance:DepthEnvelope.maxDepth/>
        <Description>
            Maximum Depth
        </Description><Units:meter/>
        <DefaultValue>NaN</DefaultValue>
    </DefineSetting>

    <DefineSetting Name="minDepthSet">
        <Guidance:DepthEnvelope.minDepth/>
        <Description>
            Minimum Depth
        </Description><Units:radian/>
        <DefaultValue>NaN</DefaultValue>
    </DefineSetting>

    <DefineSetting Name="pitchSet">
        <Guidance:DepthEnvelope.pitch/>
        <Description>
            Pitch to use when correcting depth. Default is 20 degrees.
        </Description><Units:radian/>
        <DefaultValue>0.34906585</DefaultValue>
    </DefineSetting>

    <Construct>
        <Description>
            Not really used for depth envelope.
        </Description>
        <Script><![CDATA[
	       return "Constructed DepthEnvelope", "IMPORTANT"
	    ]]></Script>
    </Construct>

    <Run>
        <Input Name="depth"><Universal:depth/><Units:meter/><DefaultValue>NaN</DefaultValue></Input>
        <Output><Control:VerticalControl.verticalMode/><Units:enum/></Output>
        <Output><Control:VerticalControl.pitchCmd/><Units:radian/></Output>
        <Script><![CDATA[
           if minDepthSet == minDepthSet and depth < minDepthSet then
               -- 5.0 is Vertical Control's pitch mode
               return 5.0, -pitchSet;
           elseif maxDepthSet == maxDepthSet and depth > maxDepthSet then
               return 5.0, pitchSet;
           end
           -- If nothing is returned, nothing happens
        ]]></Script>
    </Run>

</DefineBehavior>
