FIRST Robotics Competition Blog

Community Browser
Showing results for 
Search instead for 
Did you mean: 

Sometimes during the competition, it would be nice if the sensitivity of the joystick could be lowered temporarily to allow you to maneuver more precisely. The code snippet below does exactly that. If you press button #7 on your gamepad (this is the right trigger on my gamepad), it halves the sensitivity of the joystick. That way, you can drop the sensitivity mid-match by simply holding down the right button.

Replace the joystick and motor code in with the snippet below.


The code is quite simple: the Joystick Get Values function outputs both an array of joystick data and an array of boolean button data. The index array function is used to get the boolean value of the specified button, in this case, button #7. That value is fed into a case structure. If the button is pressed, the case structure gives a value of 2. If it is not pressed, it gives a value of 1. The value of the joystick position is then divided by the output. This way, when button #7 is pressed, every joystick value is divided by two, dropping the sensitivity. If button #7 is not pressed, the joystick sensitivity is unchanged and the robot moves at full speed.


The Producer/Consumer design pattern is a great way to keep two processes in sync when they might run at different rates.  This is especially important when there is data transferred between the loops.  When programming your robot you can use the Producer/Consumer design to save data about motor speed, various voltages, accelerometer data, and a lot more!  This can come in handy as you're testing and fine-tuning your robot.

In this example the Producer loop acquires data from the LabVIEW Front Panel (the "Input Value" and "Scaling Factor" are Front Panel Controls) and adds it to a queue of data to be processed.  The Event Structure is where the data is actually added to the queue.  This part of the code runs when the number in "Input Value" changes (for more on Event Structures, see this blog post).  The Consumer loop then removes each element from the queue, displays it on the Front Panel ("Result Value"), and adds the data to a text file.  Because writing data to a text file is a time consuming activity, the Consumer loop takes longer to run than the Producer loop.

This White Paper talks about the Producer/Consumer pattern in more detail and has some additional example code snippets!

Producer Consumer.png