Board index FlightGear Support Interfacing

Offset problem with infra-red headtracker

Connecting two computers, using generic protocol, connecting with Matlab?

Offset problem with infra-red headtracker

Postby newforestroadwarrior » Sun Apr 15, 2012 11:01 pm

I have been playing Flightgear off and on for a few years, and recently have built a simple headtracker using infra-red LEDs. This is imaged using a webcam (with an IR filter) and is brought into the Flightgear environment as a "joystick" with 6 axes (X,Y and Z translation, plus yaw, pitch and roll). In operation Flightgear assigns the "default" joystick file: this is edited so the six axes are assigned to /sim/current-view/goal- roll / pitch / heading -offset (for the rotational axes) and sim/current-view/ x / y / z -offset-m (for the translational axes)

In the absence of the headtracker the program seems to obtain some offset values from somewhere (presumably from the aircraft config files, although I can't find anything in the C172 xml documents), so the default view is at the pilot's eye level. I built these offsets into the joystick config file without too much hassle. However, they only work for the C172. If I load up another aircraft the viewpoint is in the wrong place.

I could edit the joystick file (with different offsets) every time I want to change planes, but surely there must be an easier way.

Ian
out there somewhere
newforestroadwarrior
 
Posts: 17
Joined: Mon Jan 28, 2008 9:16 pm
Location: St. Leonards on Sea, East Sussex
Callsign: G-CHQR
Version: 2.8.0.5
OS: Windows 7

Re: Offset problem with infra-red headtracker

Postby Gijs » Mon Apr 16, 2012 2:36 pm

Cockpit view settings are (usually) stored in /sim/view[0]/config/.... You could use those as "origins" and sum them with your joystick input to get the /sim/current-view/... values.
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9381
Joined: Tue Jul 03, 2007 2:55 pm
Location: Amsterdam/Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: Offset problem with infra-red headtracker

Postby Molly » Sat Apr 21, 2012 7:14 pm

Here's how I did it. The resolution feels like it could be higher, it should be 1000/65535=0.015mm between positions but it feels more like 3mm. FG axis order is unconventional. I also had problems detecting one of the axes of an eight axis virtual joystick and had to change it to a six axis joystick.

Code: Select all
<axis n="0">
  <desc>6DOFYaw</desc>
  <binding>
   <command>property-scale</command>
   <property>/sim/current-view/goal-heading-offset-deg</property>
   <factor type="double">180.0</factor>
  </binding>
 </axis>
 
 <axis n="1">
  <desc>6DOFPitch</desc>
  <binding>
   <command>property-scale</command>
   <property>/sim/current-view/goal-pitch-offset-deg</property>
   <factor type="double">180.0</factor>
  </binding>
 </axis>
 
 <axis n="2">
  <desc>6DOFRoll</desc>
  <binding>
   <command>property-scale</command>
   <property>/sim/current-view/goal-roll-offset-deg</property>
   <factor type="double">-180.0</factor>
  </binding>
 </axis>
 
 <axis n="3">
  <desc>6DOFZ</desc>
  <binding>
   <command>property-scale</command>
   <property>/sim/current-view/z-offset-m</property>
   <factor type="double">0.5</factor>
  </binding>
  <binding>
   <command>nasal</command>
   <script>
     vn = getprop("/sim/current-view/view-number");
     if (vn == 0) {
       var offset = getprop("/sim/view[0]/config/z-offset-m");
       setprop("/sim/current-view/z-offset-m", offset + getprop("/sim/current-view/z-offset-m"));
     }
   </script> 
  </binding>
 </axis>
 
 <axis n="4">
  <desc>6DOFY</desc>
  <binding>
   <command>property-scale</command>
   <property>/sim/current-view/y-offset-m</property>
   <factor type="double">0.5</factor>
  </binding>
  <binding>
   <command>nasal</command>
   <script>
     vn = getprop("/sim/current-view/view-number");
     if (vn == 0) {
       var offset = getprop("/sim/view[0]/config/y-offset-m");
       setprop("/sim/current-view/y-offset-m", offset + getprop("/sim/current-view/y-offset-m"));
     }
   </script> 
  </binding>
 </axis>
 
 <axis n="5">
  <desc>6DOFX</desc>
  <binding>
   <command>property-scale</command>
   <property>/sim/current-view/x-offset-m</property>
   <factor type="double">-0.5</factor>
  </binding>
  <binding>
   <command>nasal</command>
   <script>
     vn = getprop("/sim/current-view/view-number");
     if (vn == 0) {
       var offset = getprop("/sim/view[0]/config/x-offset-m");
       setprop("/sim/current-view/x-offset-m", offset + getprop("/sim/current-view/x-offset-m"));
     }
   </script> 
  </binding>
 </axis>
/property
Molly
 
Posts: 2
Joined: Sat Apr 21, 2012 6:52 pm

Re: Offset problem with infra-red headtracker

Postby newforestroadwarrior » Thu May 03, 2012 9:09 pm

Yes, that's how I did it.

I found setting a tolerance for the yaw and pitch axes was useful as well. Like <dead-zone> it has to precede the binding tag (something which is not too obvious in the documentation).

Ian
out there somewhere
newforestroadwarrior
 
Posts: 17
Joined: Mon Jan 28, 2008 9:16 pm
Location: St. Leonards on Sea, East Sussex
Callsign: G-CHQR
Version: 2.8.0.5
OS: Windows 7

Re: Offset problem with infra-red headtracker

Postby Molly » Thu Jun 07, 2012 5:40 pm

I finally addressed the resolution problem, there is a 'tolerance' property which by default has a value of 0.002 and needs to be set to 0.00001 to get the maximum possible precision. Similar to the deadzone property, tolerance needs to be set before the binding section.

For anyone interested I've included the full xml file configured for FreeTrack 6DOF head tracking with PPJoy virtual joystick output, the joystick needs to be six axis and named 'PPJoy Virtual Joystick 1'. The file needs to be placed in the FlightGear subdirectory \data\Input\Joysticks.

FreeTrackPPJoy6DOF.xml
Molly
 
Posts: 2
Joined: Sat Apr 21, 2012 6:52 pm

Re: Offset problem with infra-red headtracker

Postby newforestroadwarrior » Thu Jun 21, 2012 8:18 pm

Generally Flightgear will assign one of the Default joysticks to PPJoy, so you just edit that file (in data/input/joysticks/default).

Have been playing with it a bit more - certainly very absorbing, but the lack of screen resolution makes adjusting the autopilot rather difficult (and, of course, you can't see the keyboard).

Ian
out there somewhere
newforestroadwarrior
 
Posts: 17
Joined: Mon Jan 28, 2008 9:16 pm
Location: St. Leonards on Sea, East Sussex
Callsign: G-CHQR
Version: 2.8.0.5
OS: Windows 7


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 0 guests