Use a Potentiometer to Tune your programs

We implemented this simple idea and it worked so well that I though it should be posted for others to steal.

Ever need to tune a value in your program to make the output behave in particular manner but get frustrated by having to edit-compile-download every time? Then this is for you.

Get a low-cost 5 to 100 k-ohm single-turn potentiometer (RadioShack has them). Connect to a PWM cable as shown in the picture below.

Connect the cable to an analog input and you are done with the hardware.

In software, add the code below into your default and autonomous functions to read the pot:

#define TWEAK_POT rc_ana_in16 //we use channel 16

unsigned int tweak_pot; //variable declaration

tweak_pot = (unsigned int)Get_Analog_Value(TWEAK_POT);

Now you are all set to use the tweak_pot variable in your code. Remember the following points:

-the analog value will be read as a number between 0 and 1023. Zero will be when the potentiometer is rotated full counter-clockwise if you have it connected as in the picture.
-if you need the number converted to a value compatible with a PWM output (8-bit), divide by 4. (new_value = (unsigned char)(tweak_pot >> 2)
-the tweak_pot value is updated every time the loop is executed giving you real-time control of the variable in the RC.
-You can do a similar effect with a joystick on the operator interface, but that input will be limited to a range of 0 to 255.

We have used this approach to great advantage when tuning our autonomous PIDcode.

You can use more than one tweak pot–you are limited to 16 by the RC.

Happy coding and Good Luck Teams!





Team 40 Does this as well but using the OI for wireless operation. This system works great for PID tuning.