Board index FlightGear Support Hardware

How-to: motion tracking controller using vJoy and FreePIE

Joysticks, pedals, monitors.

How-to: motion tracking controller using vJoy and FreePIE

Postby hamzaalloush » Sat Feb 06, 2016 10:19 pm

For those interested in running a head motion sensing tracker for view panning or even flight controlling purposes, this process will be the same for most hardware and setups including FacetrackNoIR and TrackIR,

It consists of setting up a virtual joystick device using the vJoy driver, then emulating it as a device of your choice using FreePIE and exposing its axis using the configurable script, and finally using FGCamera so that it binds these axis to a /sim/TrackIR/ property which is used to pan views.

The process outlined below will work on Windows7/8/10, and _assumes_ you have the TrackIR.

Prerequisites/Software:

# vJoy, sets up a virtual joystick device for handling by a feeder application like FreePIE, click to download vJoy 2.0.5-080115

# FreePIE, arbitrary device emulation, configurable using a Python-syntax script, click to download FreePIE 1.9.611.0

# FGCamera, interactive camera management system, click to download fgcamera_v1_2



Installation instructions:

1 - Install FGCamera, once you have FGCamera working and tested running by following these instructions http://wiki.flightgear.org/FGCamera#Download_link_.2F_Installation, create the following file in $FGData\Input\Joysticks\vJoy\trackir.xml:

Code: Select all
    <PropertyList>
   <name>vJoy Device</name>
    <axis n="0">
      <desc>6DOFYaw</desc>
      <tolerance>0.00001</tolerance>
      <binding>
       <command>property-scale</command>
       <property>/sim/TrackIR/heading-deg</property>
       <factor type="double">-180.0</factor>
      </binding>
     </axis>
     
     <axis n="1">
      <desc>6DOFPitch</desc>
      <tolerance>0.00001</tolerance>
      <binding>
       <command>property-scale</command>
       <property>/sim/TrackIR/pitch-deg</property>
       <factor type="double">100.0</factor>
      </binding>
     </axis>
     
     <axis n="2">
      <desc>6DOFRoll</desc>
      <tolerance>0.00001</tolerance>
      <binding>
       <command>property-scale</command>
       <property>/sim/TrackIR/roll-deg</property>
       <factor type="double">100.0</factor>
      </binding>
    </axis>
     
     <axis n="3">
      <desc>6DOFX</desc>
      <tolerance>0.00001</tolerance>
      <binding>
       <command>property-scale</command>
       <property>/sim/TrackIR/x-m</property>
       <factor type="double">0.5</factor>
      </binding>
     </axis>
     
     <axis n="4">
      <desc>6DOFY</desc>
      <tolerance>0.00001</tolerance>
      <binding>
       <command>property-scale</command>
       <property>/sim/TrackIR/y-m</property>
       <factor type="double">-0.5</factor>
      </binding>
     </axis>
     
      <axis n="5">
      <desc>6DOFZ</desc>
      <tolerance>0.00001</tolerance>
      <binding>
       <command>property-scale</command>
       <property>/sim/TrackIR/z-m</property>
       <factor type="double">1.5</factor>
      </binding>
      </axis>
     
    </PropertyList>

    <!-- end of trackir.xml -->



2 - Install vJoy driver(doesn't require restart on Windows 8 ).


3 - Run TrackIR software.


4 - Install FreePIE, run as admin, insert and save the following script, then choose "Script > Run Script" from within the application(make sure there aren't any errors):

Code: Select all
import sys

def toIntSafe(value):
    if value > sys.maxint: return sys.maxint
    if value < -sys.maxint: return -sys.maxint
    return value

def update():
   yaw = filters.mapRange(trackIR.yaw, -90, 90, -vJoy[0].axisMax, vJoy[0].axisMax)
   pitch = filters.mapRange(trackIR.pitch, -90, 90, -vJoy[0].axisMax, vJoy[0].axisMax)
   roll = filters.mapRange(trackIR.roll, -120, 120, -vJoy[0].axisMax, vJoy[0].axisMax)
   side = filters.mapRange(trackIR.x, -120, 120, -vJoy[0].axisMax, vJoy[0].axisMax)
   zoom = filters.mapRange(trackIR.z, -120, 120, -vJoy[0].axisMax, vJoy[0].axisMax)
   updown = filters.mapRange(trackIR.y, -120, 120, -vJoy[0].axisMax, vJoy[0].axisMax)

   vJoy[0].x = toIntSafe(yaw)
   vJoy[0].y = toIntSafe(pitch)
   vJoy[0].z = toIntSafe(roll)
   vJoy[0].rx = toIntSafe(side)
   vJoy[0].rz = toIntSafe(zoom)
   vJoy[0].ry = toIntSafe(updown)

if starting:
    trackIR.update += update


5 - Start vJoy Monitor testing utility which was installed by the vJoy driver, and monitor if the axis are corresponding to your input, if they are...

6 - Launch Flightgear and Enjoy!!!
hamzaalloush
 
Posts: 632
Joined: Sat Oct 26, 2013 9:31 am
OS: Windows 10

Re: How-to: motion tracking controller using vJoy and FreePI

Postby ekg » Sat Jul 02, 2016 12:41 am

Hate to dig up an old thread but I'm at wits end here. I followed these instructions and track IR works in flight gear. However there is one problem. I can't get the camera inside the cockpit. It's always just above the plane (c-172p). What do I need to change to get this to work? I've tried playing around with the fgcamera dialog boxes (creating a cockpit preset for one of the cameras) and playing around with some of the view xml files. Nothing works! Any help would be greatly appreciated
ekg
 
Posts: 6
Joined: Sat Jul 02, 2016 12:37 am

Re: How-to: motion tracking controller using vJoy and FreePI

Postby hamzaalloush » Sat Jul 02, 2016 12:51 am

Try without fgcamera, I'v let go ever since, from problems you are describing.

There's also another way to do with a Nasal script which is fine but I've not tested on Windows.
hamzaalloush
 
Posts: 632
Joined: Sat Oct 26, 2013 9:31 am
OS: Windows 10

Re: How-to: motion tracking controller using vJoy and FreePI

Postby ekg » Sat Jul 02, 2016 2:15 am

hamzaalloush wrote in Sat Jul 02, 2016 12:51 am:Try without fgcamera, I'v let go ever since, from problems you are describing.

There's also another way to do with a Nasal script which is fine but I've not tested on Windows.


I disabled it and assigned the vJoy axis to view horizontal and vertical. It's almost there... sort of... The problem now is that the view shifts in 45 degree increments when the input on the axis is 100% in either direction. Otherwise it won't move.
There's this custom field in the drop-down. Perhaps there's a way to assign it through there?

I suppose another alternative would be to find out where the 45 degree increment is defined and change it to something really small and then make a complicated free pie script to handle this. Although on second thought it might not be so simple...
ekg
 
Posts: 6
Joined: Sat Jul 02, 2016 12:37 am

Re: How-to: motion tracking controller using vJoy and FreePI

Postby sim » Sat Jul 02, 2016 3:08 pm

ekg says
there is one problem. I can't get the camera inside the cockpit. It's always just above the plane (c-172p). What do I need to change to get this to work?

Have you tried using the Flightgear GUI to adjust your view position to return to a suitable view inside cockpit?
I can move viewpoint using my joystick buttons/axes set up with X Y Z scripts (left/right up/down back/forward) :!:

Example http://db.tt/zvvoSrP
User avatar
sim
 
Posts: 1445
Joined: Tue Jun 30, 2009 2:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Re: How-to: motion tracking controller using vJoy and FreePI

Postby ekg » Sat Jul 02, 2016 9:54 pm

sim wrote in Sat Jul 02, 2016 3:08 pm:ekg says
there is one problem. I can't get the camera inside the cockpit. It's always just above the plane (c-172p). What do I need to change to get this to work?

Have you tried using the Flightgear GUI to adjust your view position to return to a suitable view inside cockpit?
I can move viewpoint using my joystick buttons/axes set up with X Y Z scripts (left/right up/down back/forward) :!:

Example http://db.tt/zvvoSrP


Is this what you're refering to?

Code: Select all
<button n="10">
  <desc>Zoom in</desc>
  <repeatable>true</repeatable>
  <binding>
   <command>property-adjust</command>
   <property>/sim/current-view/x-offset-m</property>
   <step>10.0</step>
   <min>0</min>
  </binding>
  <binding>
   <command>property-adjust</command>
   <property>/sim/current-view/y-offset-m</property>
   <step>10.0</step>
   <min>0</min>
  </binding>
  <binding>
   <command>property-adjust</command>
   <property>/sim/current-view/z-offset-m</property>
   <step>10.0</step>
   <min>0</min>
  </binding>
 </button>

 <button n="11">
  <desc>Zoom out</desc>
  <repeatable>true</repeatable>
  <binding>
   <command>property-adjust</command>
   <property>/sim/current-view/x-offset-m</property>
   <step>-10.0</step>
   <min>0</min>
  </binding>
  <binding>
   <command>property-adjust</command>
   <property>/sim/current-view/y-offset-m</property>
   <step>-10.0</step>
   <min>0</min>
  </binding>
  <binding>
   <command>property-adjust</command>
   <property>/sim/current-view/z-offset-m</property>
   <step>-10.0</step>
   <min>0</min>
  </binding>
 </button>


What exactly do I do with this? I have an x-55 rhino. Alternatively is it possible to get these actions as part of the numpad (with +/- for the z axis)?

EDIT: I hacked around with the default joystick xml. This doesn't work with FG Camera. :(
ekg
 
Posts: 6
Joined: Sat Jul 02, 2016 12:37 am

Re: How-to: motion tracking controller using vJoy and FreePI

Postby hamzaalloush » Sun Jul 03, 2016 11:59 am

I'm not sure what your real problem is, maybe it is that the IR camera is losing "track" of you at some angles? or is it that the view snaps back to straight ahead after a 180* in-sim rotation?

i have a TrackIR profile specifically to fix those, and i *think* we can use modified AndersG nasal script for freetrack, we just have to change the properties for all the axes in the vJoy xml, to read like the properties in the freetrack protocol here:

https://github.com/uglyDwarf/linuxtrack/blob/master/doc/fgfs/Protocol/linuxtrack.nas.xml

and then load this awesome nasal script, it will serve to 1) disable TrackIR in exterior views. 2) you can enable whichever axis you want from the command line. 3) It will prevent view bobbing after 180* rotation.

EDIT: sorry that there's no more intuitive way to have TrackIR work in FGFS.
hamzaalloush
 
Posts: 632
Joined: Sat Oct 26, 2013 9:31 am
OS: Windows 10

Re: How-to: motion tracking controller using vJoy and FreePI

Postby ekg » Sun Jul 03, 2016 7:29 pm

My problem is I can't get TrackIR inside the cockpit. It's always above the plane c-172p. The cockpit view in FG camera is always above the plane.
ekg
 
Posts: 6
Joined: Sat Jul 02, 2016 12:37 am

Re: How-to: motion tracking controller using vJoy and FreePI

Postby ekg » Sun Jul 03, 2016 8:06 pm

I got it to work by pure fluke. I removed the vJoy folder and ran FG. I was then able to move the camera position with the num pad (x and z axis only). The camera was facing backwards. I then copied back the vjoy folder and it now works.
ekg
 
Posts: 6
Joined: Sat Jul 02, 2016 12:37 am

Re: How-to: motion tracking controller using vJoy and FreePI

Postby sim » Sun Jul 03, 2016 11:23 pm

No ekg ! you seem not to have understood my last post.
Glad you fixed the problem with your workaround solution but here is the GUI/View/adjust view position I was asking you to try. :wink:
Image
User avatar
sim
 
Posts: 1445
Joined: Tue Jun 30, 2009 2:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Re: How-to: motion tracking controller using vJoy and FreePI

Postby ekg » Mon Jul 04, 2016 3:46 am

sim wrote in Sun Jul 03, 2016 11:23 pm:No ekg ! you seem not to have understood my last post.
Glad you fixed the problem with your workaround solution but here is the GUI/View/adjust view position I was asking you to try. :wink:
Image


I tried that too. That will not work with fgcamera as far as I can tell.

The solution to my problem was to delete $FGData\Input\Joysticks\vJoy\trackir.xml in step 1 of the guide. FG creates it's own xml in app data which is good enough (pitch and yaw axis only).

The x , y , z axis cannot be included in the xml since the position for fgcamera will be fixed and unmovable.

Edit:Highlight for other users
ekg
 
Posts: 6
Joined: Sat Jul 02, 2016 12:37 am

Re: How-to: motion tracking controller using vJoy and FreePI

Postby sim » Mon Jul 04, 2016 1:12 pm

Thanks for enlightenment ekg. Think I'll just continue to use joystick to pan views!
Or build a headset full of potentiometers, then wire 'em into my joystick so views follow head movement :roll:
User avatar
sim
 
Posts: 1445
Joined: Tue Jun 30, 2009 2:13 pm
Location: Shropshire England
Callsign: Fly4Fun
Version: 0.9.10 up
OS: 64 Win 10 HD6450

Re: How-to: motion tracking controller using vJoy and FreePI

Postby hamzaalloush » Mon Jul 04, 2016 3:36 pm

Does it work for other planes too? I think what fgcamera does is it saves the position for the active camera, which is what you were able to do when you disabled x, y and z, and moved it with numpad, but I'm not sure if that's the case.

@sim, it is a "headache"
hamzaalloush
 
Posts: 632
Joined: Sat Oct 26, 2013 9:31 am
OS: Windows 10

Re: How-to: motion tracking controller using vJoy and FreePI

Postby Marius_A » Tue Oct 25, 2016 4:21 pm

ekg wrote in Sat Jul 02, 2016 12:41 am: I can't get the camera inside the cockpit. It's always just above the plane


I changed
Code: Select all
...
vJoy[0].ry = toIntSafe(updown)
...

to
Code: Select all
...
vJoy[0].slider = toIntSafe(updown)
...

and that resolved the issue.
Marius_A
 
Posts: 89
Joined: Wed Dec 04, 2013 2:20 pm

Re: How-to: motion tracking controller using vJoy and FreePI

Postby flug » Tue Feb 28, 2017 8:38 am

FYI I made my own solution to the problem. I couldn't get FGCamera to work, so instead I modded LinuxTrack (mentioned upthread) and the result--well, it may not be the slickest solution out there, but it works. Details here:

viewtopic.php?f=24&t=31757
flug
 
Posts: 218
Joined: Wed Jun 17, 2009 1:06 am


Return to Hardware

Who is online

Users browsing this forum: MSN [Bot] and 1 guest