Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

Difference between revisions of "Writing Joystick Code: Part 4"

From FlightGear wiki
Jump to: navigation, search
(Created page with "{{WIP}} == Axis Numbering == Until now we have got our joysticks working in our system by defining each axis with the following format <axis n="0"> <desc>Aileron</des...")
 
m (Update forum links)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{JoystickScripting Navigation}}
 
{{WIP}}
 
{{WIP}}
  
Line 4: Line 5:
  
 
Until now we have got our joysticks working in our system by defining each axis with the following format
 
Until now we have got our joysticks working in our system by defining each axis with the following format
 +
<syntaxhighlight lang="xml">
 
   <axis n="0">
 
   <axis n="0">
 
     <desc>Aileron</desc>
 
     <desc>Aileron</desc>
Line 9: Line 11:
 
     ...
 
     ...
 
   </axis>
 
   </axis>
 +
</syntaxhighlight>
  
 +
This is fine if you are using the joystick on your system. But imagine that you have worked out a brilliant button assignment scheme, using modifiers, so that the joystick is a joy to use. You want to post your code in the forum so everyone can use it.
  
This fine if you are using the joystick on your system. But imagine that you have worked out a brilliant button assignment scheme, using modifiers, so that the joystick is a joy to use. You want to post your code in the forum so everyone can use it.
+
There's a problem though. Different operating systems assign different numbers to the axes. Let's say that with a your joystick, Windows says that the Aileron axis is number 0, and Macs and Linux say it is axis 2. We have to change our format of the axis definition to
 
+
There's a problem though. Different operating systems assign different numbers to the axes. Let's say that with joystick, Windows says that the Aileron axis is number 0, and Macs and Linux say it is axis 2. We have to change our format of the axis definition to
+
 
   <axis>
 
   <axis>
     <win>0</win>
+
     <number>
    <mac>2</mac>
+
      <windows>0</windows>
    <unix>2</unix>
+
      <mac>2</mac>
 +
      <unix>2</unix>
 +
    </number>
 
     <desc>Aileron</desc>
 
     <desc>Aileron</desc>
 
     <binding>
 
     <binding>
    ...
+
      ...
 +
    </binding>
 
   </axis>
 
   </axis>
  
  
Now th joystick will work with all operating systems.
+
Now the joystick will work with all operating systems.
 +
 
 +
Except!! Sometimes an axis works upside down in some operating systems. Here is an example of what to do if the hat works opposite ways
 +
in Linux and Windows. Note the swapping around of - signs between the 2 OSs. Add <mac> to which ever one is correct for the Mac.
 +
  <axis>
 +
    <number>
 +
      <unix>6</unix>
 +
    </number>
 +
    <desc>View Elevation</desc>
 +
    <low>
 +
      <repeatable>true</repeatable>
 +
      <binding>
 +
        <command>property-adjust</command>
 +
        <property>/sim/current-view/goal-pitch-offset-deg</property>
 +
        <step type="double">1.0</step>
 +
      </binding>
 +
    </low>
 +
    <high>
 +
      <repeatable>true</repeatable>
 +
      <binding>
 +
        <command>property-adjust</command>
 +
        <property>/sim/current-view/goal-pitch-offset-deg</property>
 +
        <step type="double">-1.0</step>
 +
      </binding>
 +
    </high>
 +
  </axis>
 +
  <axis>
 +
    <number>
 +
      <windows>7</windows>
 +
    </number>
 +
    <desc>View Elevation</desc>
 +
    <low>
 +
      <repeatable>true</repeatable>
 +
      <binding>
 +
        <command>property-adjust</command>
 +
        <property>/sim/current-view/goal-pitch-offset-deg</property>
 +
        <step type="double">-1.0</step>
 +
      </binding>
 +
    </low>
 +
    <high>
 +
      <repeatable>true</repeatable>
 +
      <binding>
 +
        <command>property-adjust</command>
 +
        <property>/sim/current-view/goal-pitch-offset-deg</property>
 +
        <step type="double">1.0</step>
 +
      </binding>
 +
    </high>
 +
  </axis>
 +
 
  
  
Line 30: Line 83:
  
  
Unfortunately, there is no fixed relationship between axis numbering in the operating susyems, and the information must be garnered form experienece. Fortunately, the button numbering doesn't change.
+
Unfortunately, there is no fixed relationship between axis numbering in the operating systems, and the information must be garnered form experience. Fortunately, the button numbering doesn't seem to change.
  
  
Here is a list of axis numbers for various joysticks. The list will be expanded as and when I get the required information. If you have axis numbers for a joystick not listed, please post the information [http://flightgear.org/forums/viewtopic.php?f=24&t=17924 here].
+
Here is a list of axis numbers for various joysticks. The list will be expanded as and when I get the required information. If you have axis numbers for a joystick not listed here, please post the information [http://forum.flightgear.org/viewtopic.php?f=24&t=17924 here]. Don't post the axis number as they are currently in the xml file, we already know them.
  
  
Line 46: Line 99:
 
   Hat        win 6  unix 4  mac 4  # Left/right
 
   Hat        win 6  unix 4  mac 4  # Left/right
 
   Hat        win 7  unix 5  mac 5  # Up/down
 
   Hat        win 7  unix 5  mac 5  # Up/down
 +
--------------------------------------------------
 +
  Saitek X52 Pro Flight Control System
 +
  Aileron                      win ?  unix 0  mac 0
 +
  Elevator                      win ?  unix 1  mac 1
 +
  Rudder                        win ?  unix 5  mac 2
 +
  Throttle                      win ?  unix 2  mac 3
 +
  Throttle Top Rotary Dial      win ?  unix 4  mac 4
 +
  Throttle Bottom Rotary Dial  win ?  unix 3  mac 5
 +
  Throttle Slider              win ?  unix 6  mac 6
 +
  Bottom Stick Hat              win ?  unix 7  mac 7
 +
  Top Stick Hat                win ?  unix 8  mac 8
 +
 +
  I have listed this because the Mac axis numbers are newly available'
 +
  As you can see, win numbers still missing. The ones I have are just a guess.
 
--------------------------------------------------
 
--------------------------------------------------
  
Line 53: Line 120:
  
  
--------------------------------------------------
 
  
 +
-----------------------------------------------------------------------------
  
Go back to [[Writing Joystick Code: Part 3]]
 
  
 +
Any complaints/suggestions/questions/kudos can be posted [http://forum.flightgear.org/viewtopic.php?f=24&t=17892 here].
  
--------------------------------------------------
+
 
 +
 
 +
 
 +
[[Category:Hardware]]

Latest revision as of 15:35, 25 October 2013


WIP.png Work in progress
This article or section will be worked on in the upcoming hours or days.
See history for the latest developments.

Axis Numbering

Until now we have got our joysticks working in our system by defining each axis with the following format

  <axis n="0">
    <desc>Aileron</desc>
    <binding>
    ...
  </axis>

This is fine if you are using the joystick on your system. But imagine that you have worked out a brilliant button assignment scheme, using modifiers, so that the joystick is a joy to use. You want to post your code in the forum so everyone can use it.

There's a problem though. Different operating systems assign different numbers to the axes. Let's say that with a your joystick, Windows says that the Aileron axis is number 0, and Macs and Linux say it is axis 2. We have to change our format of the axis definition to

 <axis>
   <number>
     <windows>0</windows>
     <mac>2</mac>
     <unix>2</unix>
   </number>
   <desc>Aileron</desc>
   <binding>
     ...
   </binding>
 </axis>


Now the joystick will work with all operating systems.

Except!! Sometimes an axis works upside down in some operating systems. Here is an example of what to do if the hat works opposite ways in Linux and Windows. Note the swapping around of - signs between the 2 OSs. Add <mac> to which ever one is correct for the Mac.

 <axis>
   <number>
     <unix>6</unix>
   </number>
   <desc>View Elevation</desc>
   <low>
     <repeatable>true</repeatable>
     <binding>
       <command>property-adjust</command>
       <property>/sim/current-view/goal-pitch-offset-deg</property>
       <step type="double">1.0</step>
     </binding>
   </low>
   <high>
     <repeatable>true</repeatable>
     <binding>
       <command>property-adjust</command>
       <property>/sim/current-view/goal-pitch-offset-deg</property>
       <step type="double">-1.0</step>
     </binding>
   </high>
 </axis>
 <axis>
   <number>
     <windows>7</windows>
   </number>
   <desc>View Elevation</desc>
   <low>
     <repeatable>true</repeatable>
     <binding>
       <command>property-adjust</command>
       <property>/sim/current-view/goal-pitch-offset-deg</property>
       <step type="double">-1.0</step>
     </binding>
   </low>
   <high>
     <repeatable>true</repeatable>
     <binding>
       <command>property-adjust</command>
       <property>/sim/current-view/goal-pitch-offset-deg</property>
       <step type="double">1.0</step>
     </binding>
   </high>
 </axis>


The reason we write <unix> is because Linux is a variant of Unix.


Unfortunately, there is no fixed relationship between axis numbering in the operating systems, and the information must be garnered form experience. Fortunately, the button numbering doesn't seem to change.


Here is a list of axis numbers for various joysticks. The list will be expanded as and when I get the required information. If you have axis numbers for a joystick not listed here, please post the information here. Don't post the axis number as they are currently in the xml file, we already know them.



 Logitech WingMan Extreme Digital 3D (USB)
 
 Ailerons   win 0   unix 0   mac 0
 Elevator   win 1   unix 1   mac 1
 Throttle   win 2   unix 3   mac 3   # Slider
 Rudder     win 3   unix 2   mac 2   # Twist
 Hat        win 6   unix 4   mac 4   # Left/right
 Hat        win 7   unix 5   mac 5   # Up/down

 Saitek X52 Pro Flight Control System
 Aileron                       win ?   unix 0   mac 0
 Elevator                      win ?   unix 1   mac 1
 Rudder                        win ?   unix 5   mac 2
 Throttle                      win ?   unix 2   mac 3
 Throttle Top Rotary Dial      win ?   unix 4   mac 4
 Throttle Bottom Rotary Dial   win ?   unix 3   mac 5
 Throttle Slider               win ?   unix 6   mac 6
 Bottom Stick Hat              win ?   unix 7   mac 7
 Top Stick Hat                 win ?   unix 8   mac 8

 I have listed this because the Mac axis numbers are newly available'
 As you can see, win numbers still missing. The ones I have are just a guess.






Any complaints/suggestions/questions/kudos can be posted here.