Walkera helicopters under Linux – part 3

In part one we built a kernel module and put it somewhere in the filesystem. In part 2, we changed the inputattach utility to be able to use the new transmitter. Now we’re ready for the real part: install the Heli-X simulator.

First step: go to the download page and download the latest version. At the time of writing, this is is something like version “2117” (at least, that is the subdirectory it is coming from). Unpack the zip-file in a decent subdirectory. For example, I use my home-directory. The software in the zip-file is found in a subdirectory called HELI-X, so you will have something like /home/user/HELI-X/.

Install Java version 6:
$ sudo aptitude install sun-java6-bin sun-java6-fonts
Then you make runhelix.sh executable:
cd HELI-X; chmod +x runhelix.sh

Now we are, in theory, ready to run Heli-x. And, in fact, we’ll go to practice in a few moments, but I’ll tell you about some things that could go wrong first. Of course, many other things can go wrong and one of the things I should have told you earlier is, that you need 3d acceleration on your graphics card. If in doubt, run glxgears from an xterm and see if the framerate is above 500. If it is, you may be able to run Heli-X. If it is not – well, fix your graphics first (and I cannot help you with that. I’m running Intel chipsets now for years, as they are 3D-native-Linux, reliable and no-nonsense). Apart from that, things that can (and, according to Murphy, will) go wrong are:

  • An error message about your joystick.
    We have not – yet – activated the Zhenhua joystick. Yes, it is there, but it is not active yet. So when you start Heli-X, it will complain “no controller found”. Unfortunately, the message box (with a single “OK” button) is hidden behind the splash screen. This will make you think that Heli-X hangs. And in fact, it does: it is waiting for you to press Enter in order to select the “OK” button. So prepare to press Enter.
  • There’s also another error about your joystick, that has to do with an incompatible version of the jinput.jar file in Heli-X. I’ll show you how to fix this in a moment.
  • The next thing that went wrong for me – so it might go wrong for you, too – is the Compiz windowmanager.
    For some reason, it cannot handle Heli-X (or Heli-X cannot handle Compiz, whichever way of telling this you prefer). Disable Compiz. So go to System, Preferences, Appearance, tab Visual Effects and select None. Otherwise, Heli-x will seem to jump around the whole screen, no menu options are clickable and it misbehaves whereever it can.
  • Finally, a possible problem might be your chipset unable to handle the massive amount of airport graphics data. This was a real problem for me. Running Heli-X from the command line (i.e. from a terminal) gave lots of [driAllocateTexture:636] unable to allocate texture errors and gave me a frame rate of 1 to 10 frames per second (yes, that is one frame per second). Believe it or not, flying a helicopter with 1 view per second is impossible. If this happens to you, then your graphics card cannot handle the large amount of graphics data that Heli-X provides. If this happens to you, you should decrease the scene sizes. I’ll demonstrate this below.

OK, so now you know what could happen, and we’re ready to take off now, for real.
Plugin your Walkera helicopter transmitter and turn it on. If you have a serial-to-USB-cable, plug that in and make sure it works. Typing dmesg|tail should give you something like:

[19670.612878] usbcore: registered new interface driver usbserial
[19670.613089] /build/buildd/linux-2.6.24/drivers/usb/serial/usb-serial.c: USB Serial support registered for generic
[19670.613312] usbcore: registered new interface driver usbserial_generic
[19670.613316] /build/buildd/linux-2.6.24/drivers/usb/serial/usb-serial.c: USB Serial Driver core
[19670.617731] /build/buildd/linux-2.6.24/drivers/usb/serial/usb-serial.c: USB Serial support registered for pl2303
[19670.617759] pl2303 4-1:1.0: pl2303 converter detected
[19670.617864] usb 4-1: pl2303 converter now attached to ttyUSB0
[19670.617874] usbcore: registered new interface driver pl2303
[19670.617876] /build/buildd/linux-2.6.24/drivers/usb/serial/pl2303.c: Prolific PL2303 USB to serial adaptor driver

If this looks OK, you can start the inputattach utility, like so: sudo inputattach -zhen /dev/ttyUSB0. Please note, that we use ttyUSB0 here, because that showed up in the above dmesg output. If your input is a traditional serial port, you will most likely use /dev/ttyS0 or /dev/ttyS1. If you have other serial port adapters connected to your PC (like a GPS device or a fax modem), you may need to adjust (ttyUSB1, 2 or more).

Inputattach doesn’t show any output, it just sits there.

  • If it complains about device initialization failed, just start it again. If it keeps complaining, then there’s something wrong between your transmitter and the computer. Device initialization failed means that inputattach could not detect a ZhenHua transmitter. Do you have the right cable? The right port?
  • If inputattach complains can’t set line discipline, then you have not enough rights to mess with the serial port settings. Are you root enough?

So, if inputattach is running (and does nothing), we can start heli-X, by just typing ./runHELI-X.sh in the right directory. It should show the splash screen.

Now chances are, that you still get the “no controller found” error. That is because Heli-X uses a jinput library that is incompatible with your kernel (at least, that is what I make of it). So you need a couple of extra steps:
Go to https://jinput.dev.java.net/ and click on the link named Latest distribution. This will get you a file named jinput_combined_dist_latest.zip. Save it, extract the file libjinput-linux.so from it. Copy this file to the HELI-X/libs/jinput/linux-i586/ directory. To be on the safe side, also extract jinput.jar and copy it to the /HELI-X/libs/jinput/ directory (I am not sure if this is necessary, but it won’t harm you). This basically updates your jinput files under Linux. If you need this HELI-X installation under OS-X or Windows, too, you might need to fix other files, too, I wouldn’t know.

OK, now we’re ready. Make sure that inputattach is still running, then start Heli-X again. It should start now without error messages. Now there’s just a few things more we need to do, but they’re minor compared to what we have done before.

  1. Select an airport.
    Go to Simulation, Airport Selection and select an airport. If this is your very first start and you’re still testing your computing abilities (instead of your flying abilities), choose the “Small” environment. You can hardly fly it (it is too small), but it is good to test if it loads all right.
  2. Select a helicopter.
    Any helicopter will do. Just go to Simulator – Helicopter Selection and get one.
  3. Configure your joystick.
    Go to Configuration – Controller Configuration and use “Auto Configuration”. If all goes well, you should see the colored bars move when you move the sticks of your transmitter. Also, under Keyboard Config, assign a key to the “idleUp1” and “idleUp2” functions. You need them to start your helicopter.

All right. Press the key that you assigned to “idleUp1” and use the transmitter to control the helicopter. Please note, that your Walkera transmitter has a safety feature: you need to turn the gas (throttle) to zero before it will function. This is to prevent you from accidentally starting your helicopter full gas when you just turn on your transmitter.

You can now safely fly around without hitting your spouse, children, Chinese vases and dog. Don’t fly through the glass of your monitor.

A last word for those that have an older video chip (like the Intel 945G in my computer). It cannot handle the massive amount of graphics in memory in Heli-X. This gave me a frame rate of about 1 frame per second and an unusable helicopter. I fixed this with MichaelS’s help, see the rc-heli-fan forum. In short:
sudo aptitude install imagemagick
cd HELI-X/ressources/environments/

Then use something like find -type f -name '*.jpg'|xargs -i mogrify -resize 1024x1024'!' -verbose {} (to resize your environment to 1024×1024) or find -type f -name '*.jpg'|xargs -i mogrify -resize 2024x1024'!' -verbose {} (to do what MichaelS suggests).
This will decrease memory usage of the airports by a factor 2 to 4. This gives me about 15-25 frames per second, which is enough to learn to fly a helicopter. (When aliens show in Heli-X and I would feel the need to frag them, I’ll buy a new video card).

Happy flying! And if this article was of help to you, drop me a comment please.

4 Replies to “Walkera helicopters under Linux – part 3”

  1. Thanks a lot, Valentijn, for this excellent article that gives me a lot of good responses to all my problems.
    Long life to you.
    Eric / France

  2. Don’t know why I get this error:

    Exception in thread “main” java.awt.HeadlessException
    at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:173)
    at java.awt.Window.(Window.java:437)
    at java.awt.Frame.(Frame.java:419)
    at java.awt.Frame.(Frame.java:384)
    at javax.swing.SwingUtilities$SharedOwnerFrame.(SwingUtilities.java:1758)
    at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1835)
    at javax.swing.JWindow.(JWindow.java:185)
    at javax.swing.JWindow.(JWindow.java:137)
    at ch.ntb.HeliX.windows.SplashScreen.(SplashScreen.java:19)
    at ch.ntb.HeliX.windows.SplashScreenThread.(SplashScreenThread.java:7)
    at ch.ntb.HeliX.application.Application.main(Application.java:753)

Comments are closed.