<?xml version="1.0" encoding="UTF-8"?>

<!--
    Copyright (c) 2016 HHS81 and dany93

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<system name="indicated-airspeed">
        
<!--
    (dany93) Largely inspired from c182, thanks HHS81.
-->
        
<!--
    IAS Indicated airspeed (IAS) is the airspeed indicator reading(ASIR)
    uncorrected for instrument, position, and other errors. 
    From current EASA definitions: Indicated airspeed means the speed of
    an aircraft as shown on its pitot static airspeed indicator 
    calibrated to reflect standard atmosphere adiabatic compressible 
    flow at sea level uncorrected for airspeed system errors.
    Calibrated airspeed (CAS) is indicated airspeed corrected for
    instrument errors, position error (due to incorrect pressure at the 
    static port) and installation errors.
    According the POH Skyhawk C172P-1982 on Page 5-9 airspeed
    calibration shows a large difference between KIAS and KCAS at lower 
    speeds than 90 and above. 
    It seems this is not reflected by JSBSim or FlightGear in a 
    realistic way.
    So use this numbers and create a table which corrects the
    output shown on the ASI.
-->

    <property>/instrumentation/airspeed-indicator/indicated-speed-kt</property>

    <channel name="indicated airspeed">

        <fcs_function name="systems/asi/indicated-airspeed">
            <output>velocities/vias-kts</output>
            <function>
                <table>
                    <!-- The indicated-speed-kt property reacts to pitot
                         failure, but it assumes the pitot is perfect.
                         Therefore, it practically reacts as a calibrated
                         airspeed indicator (KCAS).
                    -->
                    <independentVar lookup="row">/instrumentation/airspeed-indicator/indicated-speed-kt</independentVar>
                    <independentVar lookup="column">fcs/flap-pos-deg</independentVar>
                    <tableData>
                              0     10    30
                        0     0     0     0
                        47    38    38    40
                        49    40    40    42
                        53    45    47    50
                        55    49    50    52
                        56    50    51    54
                        62    60    60    61
                        70    70    70    70
                        80    81    81    80
                        89    90    90    90
                        98    100   100   100
                        107   110   109   109
                        117   120   120   120
                        126   130   130   130
                        135   140   140   140
                        145   150   150   150
                        154   160   160   160
                    </tableData>
                </table>
            </function>
        </fcs_function>

        <switch name="systems/asi/pitot-serviceable">
            <output>/systems/pitot/serviceable</output>
            <default value="1"/>

            <test logic="AND" value="0">
                /sim/model/c172p/securing/pitot-cover-visible EQ 1
            </test>
        </switch>

    </channel>
</system>