How to code the Logitech joystick button in Labview?

I have been trying to code the buttons on the joystick to do specific tasks like control solenoids with the various buttons, but have found no success to code them to get an output.

Check out guide. They have multiple examples of how to set stuff up in labview. We have their examples up basically any time the programmers on working the bot.

LabVIEW comes with a bunch of examples installed. With LabVIEW open, go to Help → Find Examples… and browse to FRC Robotics → roboRIO → Pneumatics → Simple Solenoid.lvproj. You may need to make a few tweaks to this example to get it to work for your situation but before you change anything, make a copy of the example by (in the project window) going to Project → Project Properties, note the “Path to Project” and navigate (using File Explorer) to the project’s containing folder. Copy that folder to somewhere else on your computer. Make sure you only have the copy open in LabVIEW.
The changes to make are:

  1. The IP address of the roboRIO (if you are deploying over USB this step is unnecessary) by right clicking the roboRIO item in the project window and selecting properties and changing the IP Address/DNS Name to “roboRIO-TEAM-frc.local”. Replace TEAM with your team number with no leading zeros.
  2. Tell the program if you are using a single or double solenoid by selecting the appropriate option from the drop-down menu under the Open VI on the block diagram.
  3. If you are using a double solenoid, there will be an extra terminal on the left of the Open VI called Reverse Solenoid Channel. Right click it and select Create → Control. In the middle of the while loop, change the drop-down menu selections from On and Off to Forward and Reverse.
  4. On the front panel, select the solenoid channels you are using on your PCM.
  5. Depending on if your solenoid is a 12 volt or 24 volt solenoid, make sure the jumper on the PCM is in the correct position.

Now run the example and make sure everything works so far. The solenoid will be controlled by a switch on the front panel.

Now we need to replace the switch on the front panel with a joystick button.
Help → Find Examples… and browse to FRC Robotics → roboRIO → Joystick → Joystick Input.lvproj.
This time instead of making a complete copy of the project files, copy and paste all the code from the Joystick example’s block diagram to the block diagram of the Solenoid code. Close the Joystick example now.

Enlarge the solenoid while loop and move (or copy) the Joystick VIs to the solenoid while loop. The Joystick example was setup to use axes but you want to use the buttons. Open context help by either clicking the yellow question mark in the top right of most any LabVIEW window or by pressing Ctrl + H. Hover your cursor over the Joystick Get Values VI. The context help shows that there is a thick orange wire coming out the right of the Joystick Get Values VI with all the axes and a think green wire with all the buttons. You want the buttons, so delete the orange wire on the block diagram and rewire it using the green terminal. Now read this post about how the joystick buttons and axes are numbered, and setup the button number. Delete the XY Graph and all the related code to the right of the Index Array function. Delete the “Value to Write” control that used to control the solenoid. Create a wire from the right of the Index Array (which is resizable for however many buttons you are pulling off of it) to the input of the Select function (where the “Value to Write” control used to go). Delete the old Joystick while loop and the things with it. As shown below, on the flat sequence structure on the right, right click its edge and “Add Frame Before” and arrange the Close VIs as shown. This ensures the Close VIs run before the Stop function. This is what you should have so far. Even though I am providing you with a LabVIEW snippet that you could download and then drag and drop into LabVIEW, I hope you will take the time to program this yourself as you will learn so much more!

Run this and make sure it works.

Now this needs to be moved into the regular robot project. The Driver Station Start Comm VI is already there. The Open VIs go in the Begin VI. The Joystick Get Values VI and the Solenoid Set VI go in the TeleOp VI. And the Close VIs go in the Finish VI. To connect the wires in-between, use the Joystick and Solenoid Refnum Registry Set/Get VIs. The only place you use the Refnum Registry Set VIs is in the Begin VI, everywhere else use the Get VIs. Name the Solenoid and Joystick whatever makes since to you, just make sure to change the name everywhere they are used. Change the inputs to the Open VIs from controls to constants by right clicking them and selecting “Change to Constant”. This is how things should look except that they need to be in the different VIs as indicated by the comments.