Reading Outputs from an Attack 3 Joystick plugged into a USB port on your computer in Labview

By Austin Steeno - 11/30/08 (Last revised 11/30/08)

-------------------------------------------------------------------------

This tutorial assumes you have basic knowledge of how to use LabView 8.5.

-------------------------------------------------------------------------

Items to note:

  • I will be going through this tutorial with auto-tools turned on.
  • Our team did not have the cRio at the time this tutorial was made, so we are connecting the joystick directly to our computer and using the libraries that came with Labview 8.5, not the WPI Robotics libraries.
  • Though this tutorial uses the Attack 3 Joystick (The official joystick for the 2009 FRC competition) it should work with any USB joystick... And possibly non-USB joysticks.

 

Ok, lets begin:

Step 1: Plug in your Attack 3 Joystick to any USB port on your computer.

Step 2: Open up LabView and create a blank VI by clicking on the "Blank VI" button.

Step 3: In your new VI switch to you block diagram panel and pin down your functions menu. It should look something like this:

Step 4: Expand the "Connectivity" category on your functions menu.

Step 5: Select "Input Devices" ... You should see these icons:

Step 6: Select "Query Input Device" and place it in your block diagram.

Step 7: Right click on the "joystick info" connector and navigate to: Create » Indicator

You should see this on your block diagram:

Step 8: Go ahead and switch to the front panel and mover the indicator to whereever you want it on the grid. (Position is irrelevant to functionality)

We are going to use this setup to determine the Device ID of the joystick so we can later specify which device the read data from. This query function is meant to find all mice, keyboards and joysticks currently plugged into your computer and give you basic information about them. Number 1 is the device ID for the device listed in Number 2. Number 3 is the the device after the device listed in Number 1.

Step 9: Run the VI

Step 10: Hit the up arrow in Number 1 until "Logitech Attack 3" is in Number 2.

Now the number in Number 1 is the device ID for your joystick, write this number down or keep it in memory for later.

Step 11: Select the query VI and its indicator and delete them. (Note: You do not have to delete them, but we will not be using them anymore.)

Step 12: (This is a big one) Add an "Initialize Joystick" VI, an "Accquire Input" VI and a "Close Input Device" VI to your block diagram from your functions menu.

Step 13: Right click on the "device index" input on the Initialize Joystick VI and navigate to: Create » Constant.

Step 14: Enter the device ID we found early for the value of the constant.

Step 15: Now, wire the "Device ID" output on the "Initialize Joystick" VI to the "Device ID" input on the "Accquire Input" VI.

Step 16: Then, wire the "Device ID" output on the "Accquire Input" VI to the "Device ID" input on the "Close Input Device" VI.

As of now, if you run your VI your joystick will be read by LabView. But just to be sure we'll hook up some basic indicators so we can see that it is working correctly. (More advanced ways to display outputs will be covered in a later tutorial)

Step 17: Right click on the "Axis Info" output of the "Accquire Input" VI and navigate to: Create » Indicator. You may reposition the indicator VI on your block diagram if you wish.

Step 18: Now, right click on the "Button Info" output on the "Accquire Input" VI and navigate to: Create » Indicator. You may reposition the indicator VI on your block diagram as well.

Step 19: Now, switch to your front panel and arrange it any way you want. (Note: The "Button Info" bundle will show about 30 buttons. The joystick only has 11, and as far as I can figure there is no way to trigger any of the other button. So I resized the bundle to show just the first 11 buttons.)

Step 20: The final step! Now we just need to test that everything is working. Go ahead and hold the joystick and any position and hold down any buttons you want and run the VI. (Note: I pushed my joystick to the top right corner and held down the main trigger in my example.)

 

My result:

 

-------------------------------------------------------------------------

 

I hope you found this tutorial helpful. If you see any errors, have any suggestion or have any questions about LabView please feel free to contact me at ajsteeno@cox.net.

For those already experienced in LabView, I know, it was basic. But there will be more to come. In future tutorials I will be covering some more advanced ways to output the data, including a control loop for real-time data reading and output, so stay tuned!