Joystick autopilot bindings: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(Begin work on this page. Done: intro, initialisation, horizontal mode direction selection)
 
Line 35: Line 35:
         autopilottype=2;  
         autopilottype=2;  
     }
     }
    ....
  ]]></script>
</nasal>
</syntaxhighlight>
</syntaxhighlight>
As you can see it assumes only the Cessna 172 has the KAP-140. If there is another plane with this autopilot the condition should be adjusted
As you can see it assumes only the Cessna 172 has the KAP-140. If there is another plane with this autopilot the condition should be adjusted

Revision as of 22:01, 24 September 2014

This page is under construction!

Introduction

Before you start, read Input device and probably Writing Joystick Code: Part 1

Autopilots are generally very useful features, but unfortunately there are only key bindings for the `magic autopilot', and the only way to control popular GA autopilots is by clicking the corresponding buttons in the 3D-cockpit. This is awkward if there is a need to change mode or turn off the autopilot quickly (at final stage of ILS landing, autopilot does something silly). This page describes joystick bindings, which can be used to control the (simulated) autopilot with a set of joystick buttons. Every type of autopilot is operated quite differently, such that these keys only work for specific models. In the current implementation the key bindings work for the Bendix/King KAP140 Autopilot (in the Cessna 172) and the CENTURY III Autopilot POH (Seneca II). Those were prioritised, as the more complex autopilots in jets usually have a dedicated GUI but it is planned to provide bindings for at least basic functions like AUTOPILOT OFF in the future.

Implementation

The example code provides a nice setup for six buttons arranged like this (this happens to be suitable for the Thrustmaster T16000M but it can be adapted trivially to other button numbers by simply changing the button numbers in the snippets below

4 5 6 9 8 7

In the following snippets for each functionality are given - usually one with the actual binding and some corresponding initialisation code (put between nasal tags at the beginning of the script). You need to copy/paste both into your joystick bindings xml file. In a Joystick Autopilot Bindings#Summary the code of all snippets is provided in one code box for convenience. Generally, it was attempted to have somewhat consistent bindings between the different autopilot types, but because they are operated quite differently, this was not entirely possible, and it was attempted to stay close to the mode of operation of the actual instruments.

Generic initialisation code

On startup, we need to figure out whether we are dealing with a Bendix KAP 140 or CENTURY II autopilot.

<nasal>
    <!-- set autopilot type:
          1: KAP140     (e.g. c172p)
          2: CENTURYIII (e.g. senecaII) -->
   <script><![CDATA[
      var autopilottype=0;
      var horizontalmode=0;
     if (getprop("sim/aircraft")=="c172p") {
        print("FOUND KAP140 autopilot");
        autopilottype=1;
     } elsif (getprop("autopilot/CENTURYIII/power")>-1) {
        print("Using CENTURYIII autopilot joystick binding");
        autopilottype=2; 
     }
    ....
   ]]></script>
</nasal>

As you can see it assumes only the Cessna 172 has the KAP-140. If there is another plane with this autopilot the condition should be adjusted

Major mode selection

Horizontal mode selection

Vertical mode pitch or vertical speed selector

Horizontal mode direction selector

Adjust heading bug (button 8 clockwise and button 9 anti-clockwise)

With modifiers:
(SHIFT) coarse heading bug adjustment
(CTRL) adjust bank angle (CENTURY II only!)
(ALT) adjust radial of NAV1 (can also be used without autopilot)


Initialisation:

    var showhdgbug=func() {if ( autopilottype==1 ) {
                 gui.popupTip(sprintf("Heading Bug:%3d",getprop("autopilot/settings/heading-bug-deg"))); 
              } elsif ( autopilottype==2 ) {
                gui.popupTip(sprintf("Hdg Bug:%3d",getprop("instrumentation/kcs55/ki525/selected-heading-deg")));
              }}

Button definition:

<button n="8">
    <desc>Heading bug CW / Heading bug CW large steps /
(CENTURYIII:)Roll knob turn right / Course select CW</desc>
      <repeatable>true</repeatable>
    <binding>
            <command>property-adjust</command>
            <property>/autopilot/settings/heading-bug-deg</property>
            <step type="double">0.25</step>
    <min>000</min>    <!-- the property will never be allowed to go below 0 -->
      <max>360</max>    <!-- ...or above 360 -->
      <wrap>true</wrap> <!-- when we hit 361, wrap back to 0 and vice-versa -->
         </binding>
    <binding>
            <command>property-adjust</command>
            <property>instrumentation/kcs55/ki525/selected-heading-deg</property>
            <step type="double">0.25</step>
     <min>000</min>    <!-- the property will never be allowed to go below 0 -->
      <max>360</max>    <!-- ...or above 360 -->
      <wrap>true</wrap> <!-- when we hit 361, wrap back to 0 and vice-versa -->
         </binding>
         <binding>
            <command>nasal</command>
             <script>
             showhdgbug();
          </script>
         </binding>
    <mod-shift>
        <binding>
            <command>nasal</command>
             <script>
             showhdgbug();
             </script>
         </binding>
    <binding>
            <command>property-adjust</command>
            <property>/autopilot/settings/heading-bug-deg</property>
            <step type="double">2.5</step>
      <min>000</min>    <!-- the property will never be allowed to go below 0 -->
      <max>360</max>    <!-- ...or above 360 -->
      <wrap>true</wrap> <!-- when we hit 361, wrap back to 0 and vice-versa -->
         </binding>
    <binding>
            <command>property-adjust</command>
            <property>instrumentation/kcs55/ki525/selected-heading-deg</property>
            <step type="double">2.5</step>
     <min>000</min>    <!-- the property will never be allowed to go below 0 -->
      <max>360</max>    <!-- ...or above 360 -->
      <wrap>true</wrap> <!-- when we hit 361, wrap back to 0 and vice-versa -->
         </binding>
         <binding>
            <command>nasal</command>
             <script>
              showhdgbug();
          </script>
    </binding>
    </mod-shift>
   <mod-ctrl>
    <binding>
      <command>property-adjust</command>
       <property>/autopilot/CENTURYIII/settings/roll-knob-deg</property>
       <step type="double">0.5</step>
       <max>30</max>
     </binding>
     <binding>
            <command>nasal</command>
             <script>
             showroll();
          </script>
     </binding>
   </mod-ctrl>
 <mod-alt>
   <binding>
            <command>property-adjust</command>
            <property>instrumentation/nav/radials/selected-deg</property>
            <step type="double">0.25</step>
     <min>000</min>    <!-- the property will never be allowed to go below 0 -->
      <max>360</max>    <!-- ...or above 360 -->
      <wrap>true</wrap> <!-- when we hit 361, wrap back to 0 and vice-versa -->
         </binding>
    <binding>
            <command>property-adjust</command>
            <property>instrumentation/kcs55/ki525/selected-course-deg</property>
            <step type="double">0.25</step>
     <min>000</min>    <!-- the property will never be allowed to go below 0 -->
      <max>360</max>    <!-- ...or above 360 -->
      <wrap>true</wrap> <!-- when we hit 361, wrap back to 0 and vice-versa -->
         </binding>
     <binding>
            <command>nasal</command>
             <script>
             showcourseselect();
          </script>
     </binding>
 </mod-alt>
  </button>


 <button n="9">
    <desc>Heading bug CCW / Heading bug CCW large steps</desc>
      <repeatable>true</repeatable>
    <binding>
            <command>property-adjust</command>
            <property>/autopilot/settings/heading-bug-deg</property>
            <step type="double">-0.25</step>
         </binding>
    <binding>
            <command>property-adjust</command>
            <property>instrumentation/kcs55/ki525/selected-heading-deg</property>
            <step type="double">-0.25</step>
     <min>000</min>    <!-- the property will never be allowed to go below 0 -->
      <max>360</max>    <!-- ...or above 360 -->
      <wrap>true</wrap> <!-- when we hit 361, wrap back to 0 and vice-versa -->
         </binding>
         <binding>
            <command>nasal</command>
             <script>
                 showhdgbug();
          </script>
         </binding>
    <mod-shift>
    <binding>
            <command>property-adjust</command>
            <property>/autopilot/settings/heading-bug-deg</property>
            <step type="double">-2.5</step>
      <min>000</min>    <!-- the property will never be allowed to go below 0 -->
      <max>360</max>    <!-- ...or above 360 -->
      <wrap>true</wrap> <!-- when we hit 361, wrap back to 0 and vice-versa -->
         </binding>
    <binding>
            <command>property-adjust</command>
            <property>instrumentation/kcs55/ki525/selected-heading-deg</property>
            <step type="double">-2.5</step>
     <min>000</min>    <!-- the property will never be allowed to go below 0 -->
      <max>360</max>    <!-- ...or above 360 -->
      <wrap>true</wrap> <!-- when we hit 361, wrap back to 0 and vice-versa -->
         </binding>
         <binding>
            <command>nasal</command>
             <script>
              showhdgbug();
          </script>
    </binding>
    </mod-shift>
   <mod-ctrl>
    <binding>
      <command>property-adjust</command>
       <property>/autopilot/CENTURYIII/settings/roll-knob-deg</property>
       <step type="double">-0.5</step>
       <min>-30</min>
     </binding>
     <binding>
            <command>nasal</command>
             <script>
                showroll();
          </script>
     </binding>
   </mod-ctrl>
 <mod-alt>
   <binding>
            <command>property-adjust</command>
            <property>instrumentation/nav/radials/selected-deg</property>
            <step type="double">-0.25</step>
     <min>000</min>    <!-- the property will never be allowed to go below 0 -->
      <max>360</max>    <!-- ...or above 360 -->
      <wrap>true</wrap> <!-- when we hit 361, wrap back to 0 and vice-versa -->
         </binding>
    <binding>
            <command>property-adjust</command>
            <property>instrumentation/kcs55/ki525/selected-course-deg</property>
            <step type="double">-0.25</step>
     <min>000</min>    <!-- the property will never be allowed to go below 0 -->
      <max>360</max>    <!-- ...or above 360 -->
      <wrap>true</wrap> <!-- when we hit 361, wrap back to 0 and vice-versa -->
         </binding>
     <binding>
            <command>nasal</command>
             <script>
               showcourseselect();
          </script>
     </binding>
 </mod-alt>