Jump to content

Having fun interfacing a game controller


jpdrolet

Recommended Posts

Last week I had to interface an application with a game controller. The funny part is that it uses the joystick buttons to select a target region with the cursors of a graph, Up/Down arrows to select the power and the buttons to trigger a real laser. The goal of the "game" is to flatten those nasty bumps in the transmission curve of a fiber grating by selectively laser heating offensive regions.

The need arose from the fact that the application required a lot of mouse clicks (place cursors on target, set power, shoot; many tens of time) and there was a shortage of valid wrists to operate. I did already provided few keyboard shortcuts but it was not enough. The integration of the game controller was relatively easy. I plug the USB device and the Joystick VIs worked immediatly. I wrote a Joystick monitor to poll it and generate value change user events for buttons and controls. These were catched in the user event loop of the application to programmatically move cursors or signaling actual FP controls.

While the joystick provides integer values ±32000 for the position, I noticed that it didn't always come back to the same idle position, with errrors up to 3000 counts in position. Is that a common behavior for game controllers of are come controllers are better than others?

Link to comment

QUOTE (jpdrolet @ May 12 2008, 01:56 PM)

Cool! I worked on a similar application years ago, except the control was closed loop feedback from a spectral analyzer through a series of mirrors on piezo-electric stages...

QUOTE (jpdrolet @ May 12 2008, 01:56 PM)

While the joystick provides integer values ±32000 for the position, I noticed that it didn't always come back to the same idle position, with errrors up to 3000 counts in position.

Yeah - that's pretty standard. Joysticks are meant for gaming, and a less than 5% error in idle isn't uncommon. That said, when you get an offset, it's often pretty repeatable. In the past, I've written alogrythms that consider <5% of centre as centre. Remember, joysticks are all about change in direction, not position.

Link to comment

QUOTE (jpdrolet @ May 12 2008, 10:56 AM)

:thumbup: Cool Project.

Like crelf said, the offset is pretty standard. There are some controllers that have customizable software that will allow you to set a "center dead zone" so that the position counts don't change until you pass a defined threshold (sounds like what crelf did).

http://lavag.org/old_files/monthly_05_2008/post-8758-1210617603.png' target="_blank">post-8758-1210617603.png?width=400

I just purchased a Logitech gamepad that allows me to program the 10 buttons to mimic any keypress or key combitaion. The logitech program runs in the background to handle the translation and can be configured differently for different programs that are running. Could have a lot of cool applications.

-Toby

Link to comment

QUOTE (TobyD @ May 12 2008, 02:47 PM)

There are some controllers that have customizable software that will allow you to set a "center dead zone" so that the position counts don't change until you pass a defined threshold (sounds like what crelf did).

Kind-of: I just ignored anything +/- a threshold.

Link to comment

QUOTE (TobyD @ May 12 2008, 02:47 PM)

:thumbup: Cool Project.

Like crelf said, the offset is pretty standard. There are some controllers that have customizable software that will allow you to set a "center dead zone" so that the position counts don't change until you pass a defined threshold (sounds like what crelf did).

I just purchased a Logitech gamepad that allows me to program the 10 buttons to mimic any keypress or key combitaion. The logitech program runs in the background to handle the translation and can be configured differently for different programs that are running. Could have a lot of cool applications.

-Toby

What I did is to map the position to 20 cursor speed levels. The mapping is non linear to allow fine pixel moves and high speed coarse moves.

Link to comment

Yes. Some joysticks are better than others. I've seen the same errors with a $50 Logitech "gaming" joystick but not with a $300 industrial grade joystick. Industrials have extra circuitry that generates a true "0" when in neutral along with added robustness and waterproofing. It all depends on what you need it to do. If you're just gaming the Logitech is probably fine. But if you're looking at ultrasonic transducer signals with fluids getting splashed all over the place you need to spend some money.

Link to comment

QUOTE (jpdrolet @ May 12 2008, 03:31 PM)

Perfect - all you need to do is map the centre position to speed=0.

QUOTE (PaulG. @ May 12 2008, 03:35 PM)

But if you're looking at ultrasonic transducer signals with fluids getting splashed all over the place you need to spend some money.

That's just down-right spooky :unsure: - that's the application I used a joystick for too...

Link to comment

QUOTE (TobyD @ May 12 2008, 01:47 PM)

I just purchased a Logitech gamepad that allows me to program the 10 buttons to mimic any keypress or key combitaion.

We bought a series of piezoelectric motors and an electronic control system a couple of years ago. All in all, we've probably spent $20,000. (What is that, maybe 1.50 euro these days?) Imagine my amusement when the analog controller that came with the system was labeled "Sony Playstation."

Link to comment

QUOTE (jpdrolet @ May 12 2008, 08:31 PM)

What I did is to map the position to 20 cursor speed levels. The mapping is non linear to allow fine pixel moves and high speed coarse moves.

we did similar thing on a multiple axis robotic platform (with stepper motors). since we used cheap usb game controller we had to define dead band, however we used velocity profile mode and mapped it to position of the 'stick', i.e. further you push it from the center faster it will go. Also, one of the spare buttons on the controller was used as a 'safety' - you had to press and hold it while controlling the robot (to avoid unintentional movement in case controller gets dropped, bumped, etc.). It's pretty fun...

Link to comment

I also wanted to use the standarized joystick interface instead of expensive hardware to detect joystick and potmeter positions. I ended up with this controller:

http://www.lbodnar.dsl.pipex.com/joystick/

which is very nice. You could even use it to acquire voltages between 0 and 5V as really cheap analog input device. But if you do this be warned, the inputs are not protected so this is not advisable.

This one has 10 bits, sufficiently accurate for me. So far I only needed 4 of the possible 8 axes and about 15 buttons of the 32 possible. The best feature of this type of controller is that you don't need any special drivers to use it (on windows).

Joris

Link to comment
  • 5 months later...

QUOTE (robijn @ May 14 2008, 09:29 AM)

I also wanted to use the standarized joystick interface instead of expensive hardware to detect joystick and potmeter positions. I ended up with this controller:

http://www.lbodnar.dsl.pipex.com/joystick/

which is very nice. You could even use it to acquire voltages between 0 and 5V as really cheap analog input device. But if you do this be warned, the inputs are not protected so this is not advisable.

This one has 10 bits, sufficiently accurate for me. So far I only needed 4 of the possible 8 axes and about 15 buttons of the 32 possible. The best feature of this type of controller is that you don't need any special drivers to use it (on windows).

Joris

Hi,

I did take a look in the example with the Joystick. Beside the buttons, could you please tell me how we can get the data of the potentionmeter?

Best regards,

Thang Nguyen

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.