Intro: PmodJSTK 2 Controller LabVIEW Code
This instructable will go over the LabVIEW code that I wrote for the Sumobot controller. This will be an in-depth explanation of the code. If you're not interested in the explanation, the LabVIEW VI is attached in the last step. The code shown is the code for the Raspberry Pi 2 Sumobot controller, it is the same as the code used for the BeagleBone Black Controller. LabVIEW 2014 and Linx 3.0 are required to run this code. Below are some related Instructables:
Step 1: Front Panel
This is the front panel, right here is where you will enter the chip select channel and the SPI channel for each of your PmodJSTK 2's and here is where you will see their output value.
Step 2: Reading From the Pmod JSTK2
After LINX is opened, a reference to the each of the PmodJSTK2’s is opened, and the settings that we set on the front panel are fed in.
Inside the While Loop is a JSTK read for the right and left sides, you feed in the Chipselect and SPI channel for each, and they output a value that specifies the position of the joystick and whether or not the button is being pressed.
The data that comes out of bundle all the values from both Joysticks and then use a “flatten to string” to convert it to a string.
Step 3: Sending Controller Values Over UDP
We use UDP(User Datagram Protocol) to continuously send the joystick values over Wi-Fi.
First a UDP socket is opened, and the port is fed in. The IP address that will be fed into the UDP write and tell it what IP address to send to is specified here
We bundle all the values from both Joysticks and then use a “flatten to string” to convert it to a string before we feed it into the UDP write.
This will continue to send to the port specified here until the stop button is pressed, after which it will leave the loop and close the LINX reference as well as the UPD socket.
Step 4: Receiving Controller Values Over UDP
In the corresponding Surobot code, there are a few things you need to do before the data can be read.
First, a UDP open block opens a UDP socket. The IP address and port fed in here match the one fed into the UDP write in the controller’s code.
The UDP read outputs the string we sent over, and we feed it into a “unflatten from string” and specify its type to output our data bundle. Next, it is fed into an unbundle block which outputs each value from the PmodJSTKs.