Using Saitek AV8R second throttle as view pan speed control

From FlightGear wiki
Jump to navigation Jump to search

These changes to your aviator.xml file will enable you to use the second throttle of the Saitek AV8R joystick as a view panning speed control. The panning speed can be controlled smoothly from no movement at all to very fast.

Caveats

You will lose the second throttles other functionality. The most important being mixture, which means you will have to use the keyboard for this - Shift+M for leaner and M for richer. This is not a significant problem as the mixture does not have to be adjusted often.

Also, this article assumes that you have not done any modifications to your aviator.xml file. If you have, you will have to work out the changes yourself, or ask on the Support->Hardware forum.

Usage

This is the same as standard - use the hat-switch as is to get the predefined views. Press the modifier (trigger) while using the hat-switch to pan left/right and up/down. The difference is that, while using the trigger/hat-switch, Throttle 2 will control the speed of view-change.

There are two methods you can use:

Method 1
Moving the hat-switch left/right (up/down) will pan left/right (up/down) with Throttle 2 controlling the speed of movement - throttle closed is dead-still and throttle fully open is very fast movement. This means that the hat-switch can only be used for left/right and up/down.
Method 2
With this method you assign 4 different controls to the 4 directions of the hat-switch. With each one, Throttle 2 in the center means no movement, fully open is fast in one direction and throttle closed means fast in the other direction.

So you could use hat-switch left for pan left/right and hat-switch up for pan up/down. This leaves hat-switch right and hat-switch down for other functions, such as move eye-position (more on this later.)

Changes to aviator.xml

You need a text-editor to modify this file:

   .../FlightGear/data/Input/Saitek/Aviator.xml

Step 1 is to make a copy of this file in a safe place, in case things go wrong.

Step 2 is to open the file, and find this:

 <!-- Analog axis 4. Throttle 2 -->
 <axis>
  <name>Right throttle</name>
  <number>
   <unix>4</unix>
   <mac>4</mac>
   <windows>4</windows>
  </number>
  <desc>TM0: mixture, TM1: throttle/propeller 2, TM2: throttle/propeller 4</desc>
  <binding>
   <command>nasal</command>
   <script>
     if (engine_select_mode == 0) {
       controls.mixtureAxis();
     } else {
       controls.perEngineSelectedAxisHandler(engine_axis_mode)
           ((engine_select_mode == 1) ? engine[1] : engine[3]);
     }
   </script>
  </binding>
 </axis>

and change it to this:

 <!-- Analog axis 4. Throttle 2 -->
 <axis>
  <name>Right throttle</name>
  <number>
   <unix>4</unix>
   <mac>4</mac>
   <windows>4</windows>
  </number>
  <desc>TM0: mixture, TM1: throttle/propeller 2, TM2: throttle/propeller 4</desc>
  <binding>
  </binding>
 </axis>

Now Throttle 2 does nothing. No cutting out the engine because you changed the Mixture while panning around. If you really want to keep your Mixture control, then you can change the above to:

 <!-- Analog axis 4. Throttle 2 -->
 <axis>
  <name>Right throttle</name>
  <number>
   <unix>4</unix>
   <mac>4</mac>
   <windows>4</windows>
  </number>
  <desc>TM0: mixture, TM1: throttle/propeller 2, TM2: throttle/propeller 4</desc>
  <binding>
   <command>nasal</command>
   <script>
     if (!modifier) {
       if (engine_select_mode == 0) {
         controls.mixtureAxis();
       } else {
         controls.perEngineSelectedAxisHandler(engine_axis_mode)
             ((engine_select_mode == 1) ? engine[1] : engine[3]);
       }
     }
   </script>
  </binding>
 </axis>

This will keep the Throttle 2 functionality, but you need to return it to its original position before you release the modifier button.

Next is to look for this:

 <!-- Axis 5. Hat left/right -->
 <axis>
  <name>Hat left/right</name>
  <number>
   <unix>5</unix>
   <mac>5</mac>
   <windows>5</windows>
  </number>
  <desc>quick view left/right, +mod: horizontal view pan</desc>
  .....

Scroll down until you see:

    <script>
     <![CDATA[
       trace("Axis 5, Hat: low!");
      if (modifier) {
         view.panViewDir(0.5);
       } else {
         quick_view(1);
       }
     ]]>
    </script>

You will need to change this line:

         view.panViewDir(0.5);

If you are using Method 1, change it to

         view.panViewDir(1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting"));

If you are using Method 2, change it to

         view.panViewDir(getprop("input/joysticks/js[0]/axis[4]/binding/setting") * 2);

You only need do this step for Method 1. Scroll a bit further down until you see

    <script>
     <![CDATA[
       trace("Axis 5, Hat: high!");
       if (modifier) {
         view.panViewDir(-0.5);
       } else {
         quick_view(2);
       }
     ]]>
    </script>

The line to change is

         view.panViewDir(-0.5);

Change it to

         view.panViewDir(-(1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting")));

Having made these changes, you can do the following:

Method 1
Pressing modifier (trigger) and moving the hat-switch left means you can use Throttle 2 to control the speed of pan to the left. Pressing modifier (trigger) and moving the hat-switch right means you can use Throttle 2 to control the speed of pan to the right.
Method 2
Pressing modifier (trigger) and moving the hat-switch left means that you can use Throttle 2 to control the speed of pan to left and right, with throttle in the middle doing no movement.

Now to make the changes to manage pan up and down (pitch).

Scroll down to

 <!-- Axis 6. Hat up/down -->
 <axis>
  <name>Hat up/down</name>
  <number>
   <unix>6</unix>
   <mac>6</mac>
   <windows>6</windows>
  </number>
  <desc>view reset/quick view front, +mod: vertical view pan</desc>

Scroll a bit further down. The line to change is

         view.panViewPitch(0.5);

For Method 1, change it to

         view.panViewPitch(1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting"));

For Method 2, change it to

         view.panViewPitch(getprop("input/joysticks/js[0]/axis[4]/binding/setting") * 2);

For Method 1, scroll a bit further down and replace

         view.panViewPitch(0.5);

with this

         view.panViewPitch(-(1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting")));

Now you can do look up/down exactly the same as left/right.

Alternatives

You could of course use this exact same method to move your eye-point around, instead of looking around.

If using Method 1, replace

         view.panViewDir(1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting"));

with

         controls.slewProp("/sim/current-view/x-offset-m", (1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting")) * 10);

and

         view.panViewDir(-(1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting")));

with

         controls.slewProp("/sim/current-view/x-offset-m", (1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting"))* -10);

If using Method 2. change

         view.panViewDir(getprop("input/joysticks/js[0]/axis[4]/binding/setting") * 2);

to

         controls.slewProp("/sim/current-view/x-offset-m", getprop("input/joysticks/js[0]/axis[4]/binding/setting") * 20);

This will move you horizontally. To move up and down, replace x-offset with y-offset. To move backwards and forwards, change it to z-offset.

You can also use this method for zooming in and out. Unfortunately we need to implement limits for zoom, so the code is more complicated. If using Method 1, replace

         view.panViewDir(-(1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting")));

with

         <![CDATA[
           controls.slewProp("/sim/current-view/field-of-view", 
              (1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting")) * -20);
           if (getprop("/sim/current-view/field-of-view") >= 120)
             setprop("/sim/current-view/field-of-view", 120);
           if (getprop("/sim/current-view/field-of-view") <= 1)
             setprop("/sim/current-view/field-of-view", 1);
         ]]>

and

         view.panViewDir(1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting"));

with

         <![CDATA[
           controls.slewProp("/sim/current-view/field-of-view", 
              -(1 - getprop("input/joysticks/js[0]/axis[4]/binding/setting")) * -20);
           if (getprop("/sim/current-view/field-of-view") >= 120)
             setprop("/sim/current-view/field-of-view", 120);
           if (getprop("/sim/current-view/field-of-view") <= 1)
             setprop("/sim/current-view/field-of-view", 1);
         ]]>

If using Method 2. change

         view.panViewDir(getprop("input/joysticks/js[0]/axis[4]/binding/setting") * -2);

to

         <![CDATA[
           controls.slewProp("/sim/current-view/field-of-view", 
              getprop("input/joysticks/j[0]/axis[4]/binding/setting") * 40);
           if (getprop("/sim/current-view/field-of-view") >= 120)
             setprop("/sim/current-view/field-of-view", 120);
           if (getprop("/sim/current-view/field-of-view") <= 1)
             setprop("/sim/current-view/field-of-view", 1);
         ]]>

Summing up

It seems a bit daunting, but if you look carefully, the steps are all the same, there are just a few places where the changes need to be made.

Related content