Joystick controller using pc sound card [WORKING]

More
08 Jun 2014 13:38 - 15 Jun 2014 18:59 #23966 by DarioP
I've written a Linux program that takes the input of a joystick (Logitech G940 in my case) and outputs a PPM signal from the sound card that is used to drive a transmitter (devo8 in my case).

The program uses the Joystick++ library from Drew Noakes (shipped with the program) to read data from joystick, and the portaudio library (available in most Linux distributions) to drive the sound card.

You may need to amplify the signal coming out from your sound card. I used an old HI-FI amplifier. Start with a very low volume and go up slowly until the TX sees the signal.

Here are some pictures of the setup: imgur.com/a/zlXnR
And here a video of me flying the Walkera miniCP:


The readme file contains some instruction to setup and run the program. It is not stupid-proof but shouldn't be too hard to use.

File Attachment:

File Name: joy2ppm_20....tar.bz2
File Size:52 KB
Attachments:
Last edit: 15 Jun 2014 18:59 by DarioP.

Please Log in or Create an account to join the conversation.

More
08 Jun 2014 17:57 - 15 Jun 2014 12:01 #23974 by DarioP
ORIGINAL MESSAGE

I'm looking forward for the reversed usb-hid, in the meanwhile I've written a small C++ program in linux that takes input from a joystick and modulates a PPM signal through the sound card.

I captured the signal with another pc, measured it and looks fine, but when I try to send it to my devo8 nothing happens. I'm not sure if there's an issue with the shaping of the signal, the setting of the devo or maybe it's just my sound card that cannot output enough voltage...

Any experience?

Here is the signal captured with the second pc (voltage scale is random: it depends on the mic gain)

File Attachment:


I attached to this post the full program. A precompiled executable for x86_64 architecture is included together with the sources. To run it you'll have to have a Linux OS with Gnuplot and ALSA, everything should be clarified in the README file.

The PPM structure is easily modifiable in the joy2ppm.cpp source file. Let me know if you can take something out of this! I suspect that the signal have to be amplified (or the TX modded) in order to be able to drive the TX.
Last edit: 15 Jun 2014 12:01 by DarioP.

Please Log in or Create an account to join the conversation.

More
09 Jun 2014 00:14 #23980 by PhracturedBlue
Replied by PhracturedBlue on topic Controlling the devo8 with PPM from pc sound card
you did not include your model.ini. It really isn't possible to help you without it.

Please Log in or Create an account to join the conversation.

More
09 Jun 2014 08:39 - 09 Jun 2014 08:40 #23987 by DarioP
I guess that the part that you need is this:

[ppm-in]
mode=stick
num_channels=4
switch=MIX2
centerpw=1100
deltapw=400
map1=AIL
map2=ELE
map3=THR
map4=RUD
map5=None
map6=None
map7=None
map8=None

I took care to match the centerPW and deltaPW between my code and the Devo config, however I wasn't sure about the notch (400us?) and the total pulse length (22500us?). I'm also not sure if the filling part of the pulse should be up or down (I tried both but no luck).

When I switch to MIX2 the TX doesn't take input from its sticks (I think it's correct) but it also doesn't react to the ppm modulation. Unfortunately I don't have a real oscilloscope available so I cannot do precise measures, I'm quite confident with the time structure, but I have no clue about the voltage.

File Attachment:

File Name: model1.ini
File Size:2 KB
Attachments:
Last edit: 09 Jun 2014 08:40 by DarioP.

Please Log in or Create an account to join the conversation.

More
09 Jun 2014 14:59 - 23 Jun 2014 10:44 #23990 by DarioP
I still didn't get the communication with the TX but attached there is a much improved version of the program. It contains a couple of scripts that should make the compilation and the run trivial (executables for LINUX 64 bits are still shipped so there is no need to compile on this system). I also moved all the configuration to a .conf file so that every parameter of the signal generation and joystick mapping can be easily accessed. The README file contains updated instructions.
Last edit: 23 Jun 2014 10:44 by DarioP.

Please Log in or Create an account to join the conversation.

More
09 Jun 2014 17:28 #23994 by PhracturedBlue
Replied by PhracturedBlue on topic Controlling the devo8 with PPM from pc sound card
The PPM-in is pretty flexible in what it accepts. The way it works is by sampling a timer on the rising edge of the PPM-in pin. It then sets:
chan[x] = (current_time-last_time-center_pw)/delta_pw

So the dwell/notch time are incorporated into the center time. If the pw at val=0 is 1100us, and the dwell is 400us, then the center-pw will be 1500us. Calculating this wrong will only mean that the channels are not centered properly, so this is unlikely to be the cause of your issues.

There is also a requirement of at least 3300us without a rising edge between sending the last channel, and starting on the 1st again.

When I get some time, i'll try to run your code and see what is going on.

Please Log in or Create an account to join the conversation.

More
09 Jun 2014 18:07 #23998 by DarioP
I definitely got it right. So it must be a voltage problem. I think that my sound card output is too small to trigger the acquisition in the TX. Do you know what is the required voltage gap? I may try to put in between an amplifier...

It would be great if you could try the code, it should be pretty straightforward to run it. Please report me any issue and I'll provide assistance ASAP.

Please Log in or Create an account to join the conversation.

More
09 Jun 2014 18:25 #23999 by PhracturedBlue
Replied by PhracturedBlue on topic Controlling the devo8 with PPM from pc sound card
I believe ~2.7V swing should be enough. The input is likely a Shottky, so it triggers at roughly 80% of the supply rail (3.3V). The input is probably5.5V capable.

I forgot to ask...how did you wire to the plug? The Devo8 plug actually uses a single pin (I think it is the tip) for both Rx and Tx. So either use a mono cable or be sure you hooked it up correctly

Please Log in or Create an account to join the conversation.

More
09 Jun 2014 19:19 - 09 Jun 2014 19:26 #24003 by DarioP
Yep, I use the mono cable which was supplied with the TX. In the next days I'll write a similar program to produce a sine wave so that I can measure the output voltage with the simple tester that I own and eventually try to amplify it. Thanks for the assistance!


PS. It is quite like that my signal is below the threshold: en.wikipedia.org/wiki/Line_level
Last edit: 09 Jun 2014 19:26 by DarioP.

Please Log in or Create an account to join the conversation.

More
11 Jun 2014 07:30 #24027 by DarioP
And I got it! The level was too low. I put in between an old HI-FI stereo amplifier and it worked. I had to fine tune the volume so I don't think that the TX accepts a wide range of voltages. However starting quite low and going up slowly it is quite straightforward. I also had to fix some math in the code.

Now the major problem is the delay between a joystick movement and the sound modulation. I guess I should be able to remove it redesigning the code with better libraries. I'll have a look if I can employ something which is also multiplatform.

Please Log in or Create an account to join the conversation.

More
15 Jun 2014 12:04 #24085 by DarioP
Updated the program, now uses portaudio. It works very well! You find everything in the first post.

Please Log in or Create an account to join the conversation.

Time to create page: 0.050 seconds
Powered by Kunena Forum