<?xml version="1.0"?>
<!--
        Description: Beagle Pup controls
        Author: Richard Harrison (rjh@zaretto.com)
-->


<system name="Controls">
    <property value="0">gear/gear-asym</property>
    <property value="0">aero/include-propeller-effects</property>
    
    <channel name="extra-aero">
        <!-- need %Cg in chord for moments [Xcg - Xref)/100] -->
        <summer name="cg-x-offset-chord-in">
            <input> inertia/cg-x-in</input>
            <input> -metrics/aero-rp-x-in</input>
            <output>inertia/cg-x-offset-chord-in</output>
        </summer>
        <!-- figure out the factor for the fuel tank aero -->
        <pure_gain name="cg-x-chord-percent">
            <description>Percent offset of the CoP from the CG</description>
            <input>inertia/cg-x-offset-chord-in</input>
            <gain> -0.01</gain>
            <clipto>
                <min> -1 </min>
                <max> 1 </max>
            </clipto>
            <output> inertia/cg-x-mac-percent </output>
        </pure_gain>

        <fcs_function name="pb">
            <description>PB Denormalization</description>
            <function>
                <quotient>
                    <product>
                        <property>metrics/bw-ft</property>
                        <property>velocities/p-aero-rad_sec</property>
                    </product>
                    <!-- over -->
                    <product>
                        <value>2</value>
                        <property>velocities/vt-fps</property>
                    </product>
                </quotient>
            </function>
            <clipto>
                <min> -1.00 </min>
                <max>  1.00 </max>
            </clipto>
            <output>aero/pb</output>
        </fcs_function>

        <fcs_function name="cbarq-2vo">
            <description>For denormalization</description>
            <function>
                <quotient>
                    <product>
                        <property>metrics/cbarw-ft</property>
                        <property>velocities/q-aero-rad_sec</property>
                    </product>
                    <!-- over -->
                    <product>
                        <value>2</value>
                        <property>velocities/vt-fps</property>
                    </product>
                </quotient>
            </function>
            <clipto>
                <min> -2.01 </min>
                <max>  2.01 </max>
            </clipto>
            <output>aero/qb</output>
        </fcs_function>
        <fcs_function name="rb-2vo">
            <description>For denormalization</description>
            <function>
                <quotient>
                    <product>
                        <property>metrics/bw-ft</property>
                        <property>velocities/r-aero-rad_sec</property>
                    </product>
                    <!-- over -->
                    <product>
                        <value>2</value>
                        <property>velocities/vt-fps</property>
                    </product>
                </quotient>
            </function>
            <clipto>
                <min> -1.00 </min>
                <max>  1.00 </max>
            </clipto>
            <output>aero/rb</output>
        </fcs_function>


        <fcs_function name="aero-cos-alpha">
            <function>
                <product>
                    <cos>
                        <property>aero/alpha-rad</property>
                    </cos>
                </product>
            </function>
            <output>aero/cos-alpha</output>
        </fcs_function>

        <fcs_function name="aero-sin-alpha">
            <function>
                <product>
                    <sin>
                        <property>aero/alpha-rad</property>
                    </sin>
                </product>
            </function>
            <output>aero/sin-alpha</output>
        </fcs_function>
    </channel>

    <channel name="Auxiliary">
        <pure_gain name="Pilot G">
            <input>accelerations/n-pilot-z-norm</input>
            <gain>-1</gain>
            <output>/accelerations/pilot-gdamped</output>
        </pure_gain>

        <switch name="position/aircraft-on-ground">
            <description>Aircraft on ground</description>
            <default value="0"/>
            <test value="1" logic="OR">
                gear/unit[0]/WOW ne 0
                gear/unit[1]/WOW ne 0
                gear/unit[2]/WOW ne 0
            </test>
        </switch>
        <fcs_function name="aero/alpha-indicated-deg">
            <description>ARI nose probe; ref ADA101648 p84; alpha_true = .8122 alphaNOSEPROBE + .797deg</description>
            <function>
                <product>
                    <sum>
                        <property> aero/alpha-deg </property>
                        <value> -0.797 </value>
                    </sum>
                    <value>1.231223836</value>
                </product>
            </function>
        </fcs_function>
    </channel>

    <channel name="SoundFX">
        <fcs_function name="fcs/flap-windfx-volume">
            <function>
                <product>
                    <property>velocities/ve-kts</property>
                    <property>fcs/flap-pos-norm</property>
                </product>
            </function>
            <output>fcs/flap-windfx-volume</output>
        </fcs_function>
        <fcs_function name="fcs/gear-windfx-volume">
            <function>
                <product>
                    <property>velocities/ve-kts</property>
                    <property>fcs/gear-control</property>
                </product>
            </function>
            <output>fcs/gear-windfx-volume</output>
        </fcs_function>
    </channel>

</system>
