Sunday, December 22, 2013

How to get your Turnigy or Flysky 9X RC radio to work as a joystick in Ubuntu

To get a joystick interface to work with a TH9X or any 9X r/c remote transmitter as seen here: to work with a ppm2usb adapter was more of a task than I expected. In the end I finally got the Flightgear program running on my Ubuntu 10.04 system using my TH9X radio hooked in with a cheap $4 PPM2USB adapter I got from Hobbyking.com. In this case I used this one http://www.hobbyking.com/hobbyking/store/__24348__USB_Simulator_Lead_for_Turnigy_GTX3_Transmitter_VRC_Sim_Compatible.html. The first problem I had was to get the joystick to read at all. To test and calibrate my joystick I first installed with apt-get install jstest-gtk , that is a GUI to see joystick activity and to calibrate them. From jstest-gtk it would seem there was no activity from any movement on my TH9X radio when plugged in. To verify that Ubuntu detected my joystick adapter I tried from the command line $lsusb and I could see a new device appear seen as Bus 002 Device 011: ID 0401:0401 National Registry, Inc. when I plugged my joystick adapter in. I could also see from a dmesg command this: [565386.876209] input: Љ PPM########### as /devices/pci0000:00/0000:00:02.0/usb2/2-3/2-3:1.0/input/input14 [565386.876638] generic-usb 0003:0401:0401.000B: input,hidraw3: USB HID v1.00 Joystick [Љ PPM###########] on usb-0000:00:02.0-3/input0 ; That shows that it was also recognized by my Ubuntu kernel and was bound to a driver when the usb adapter was plugged in. So why wasn't I getting any action from the movement of my joysticks on my TH9X radio? I searched the Internet for an answer and came across something in a blog stating there was a problem in some of the 9X radios that the PPM output signal was too low for some devices unless you unplugged the TX module from the back of the radio. So I gave that a try and finally the magic started. I could see a small amount of action in jstest-gtk when I moved any of my 4 sticks on the radio. I looked at the raw data seen coming out with the command line jstest /dev/input/js0 and saw that the stick movement would put out from about 62 – 141 with full movement of any of the sticks and it centered around 100. So with this info I plugged the values into the calibration page of jstest-gtk as seen here: . With these values plugged in I now could see full movement of the graphs in jstest-gtk move. So now it was time to see what flightgear would do with it. I started the flightgear application and selected the /dev/input/js0 as my input device. With the “P” command in flightgear I could see the movements of each the joystick positions move as expected but the throttle was reversed and the elevator throttle sticks action was wrong. I had to put the throttle full down to be full up on flightgear. So I exited the flightgear application and again ran jstest-gtk. In jstest-gtk calibration page there is an invert box at the right of each stick that I activated on the second from the top that was the active throttle on my joystick. I again brought up the flightgear application and found that fixed my throttle problem. Oh but also my throttle stick and elevator sticks action were also reversed. Note I might be able to correct this in the TH9X with some transmitter setting adjustments but I just had the TH9X setup in a standard airplane mode and chose to find the solution on the computer side. This took a bit more research but I found a hack to get it to at least work for me. I had to modify the file at: /usr/share/games/FlightGear/Input/Joysticks/Default/joystick.xml with these values:  I reversed the values with  <axis n="1">  and <axis n="2"> to be reversed in sequence from the original default values to swap the controls of the throttle and elevator actions on my TH9X radio. With these changes I again started flightgear and now I can fly the Cessna 172 from my TH9x radio. The last parts to learn was how to activate the ignition with the '}{' keys and to start the motor after ignition was active with the 'S' key on my keyboard. With my first flight I did find I had to do some trim adjustments on my radio to get the aircraft to fly at trim when I took my fingers off the sticks. In fact one was so far out that I again had to make a small change in the calibration settings in jstest-gtk to put it within the range of my TH9X radio trim adjustments. OK finally a fully working Cessna plane. I later learned With the 'Vv' keys I could changed the view perspective to fly from the tower or other positions. After I finally got all the values figured out on my joystick I later found that it didn't save the values after I reboot my system. So I had to do one more thing to save the calibration values I did this command: jscal -p /dev/input/js0 . This would output the needed command that will set the calibration values that are presently detected in my case it created this: jscal -s 5,1,0,99,102,14509581,13765500,1,0,100,100,14127750,13094012,1,0,99,102,14509581,13765500,1,0,99,102,14509581,13765500,1,0,99,102,14509581,13765500 /dev/input/js0 . I added this to another or the same script to run at boot or just before I start the flightgear application. The next task is to get the helicopter mode to work. I've only just started working on this part. I was surprised it wasn't just a setting in the flightgear GUI to change it. Just to get the helicopter mode started I had to start the flightgear application with something like this: fgfs --aircraft=T38 . I just created a script file to start it in this way to simplify it a bit so I don't have to remember. I still haven't got the heli mode working fully yet as when I start up the blades to spin it ends up flipping the heli and crashing before I touch anything. So I guess there are some different trim adjustments for heli mode and maybe stick action might also have to change for it to work? I'll add to this article if and when I figure this part out or create another article just for heli mode if it becomes to complicated .

No comments:

Post a Comment