3pi Parameter Menu
This is a simple revision of the Pololu PID line-following program that adds a menu to allow changes to the working parameters. In addition to the ability to change the parameters without a recompile upload cycle, the program uses the eeprom to store the values. That makes them non-volatile. When the robot is turned on it remembers the parameters from the last time it was used.
Changing Parameters
One of the fun things to do with the 3pi robot trying to find the best values for the parameters it uses to follow a line. It is a very good way to get an understanding of how the robot functions and how control systems work. One sticking point is that the sample requires a cycle of edit the source file, compile and upload the program to change these values. That gets old quickly. It takes time and it pulls you away from the line course you are trying to follow. It would be much better if we could use some kind of menu to change the parameters as part of the function of the robot. (What parameters are we talking about?)
Simple Menu
Several of the sample programs use the combination of the LCD display and the three user buttons to manage some interaction like a menu. It is fairly easy to use those elements to add a mechanism to change the values of the line-following parameters. It turns out that with a few catches, this is easy. The problems come from the difference in speeds between the microcontroller and the human it interacts with. One way to solve that difference is for the computer to start an action when a button is pushed down and wait until the button is released to finish that action. The Pololu library has functions that make it easy to do just that. The menu is a mixture of the library routines and some subroutines that change the values on demand.
Saving Parameter Values
This whole exercise is much easier if the robot can remember the values for all of the parameters between sessions. The 3pi robot has eeprom, or Electrically Erasable Programmable Read-Only Memory, for non-volatile storage. That gives us a place to save the values between sessions. The gcc suite of tools has routines to read and write to this batch of memory. All we need to do is write the values of the parameters to the eeprom any time they are changed. Then any time the program is started it can read the values that we used the last time the program was run from there.
Using The Program
This program is a simple collection of menus to allow us to start and stop the robot and inspect and change values for the parameters used. When it is first started it displays a series of messages and stops on a display of the battery voltage and prompt to press button B. When the button is pressed it will do a routine to calibrate the sensors and proceed to the main menu. This menu has three choices. The letter G is for go. It starts the line following routine and is associated with button A. The S is for stop, it stops the line following routine and clears out any temporary values and it is button B. Button C is labelled C and goes into a loop to display the parameter values. While in this loop button B will toggle between the parameters used. First is the speed parameter, then the proportional one, then integral, then derivative and then back to proportional. The loop will continue to display values until button A is pressed, which returns to the main menu. While in the parameter loop you can change the value of any parameter by first pressing the C button. That sets an edit mode. In that mode button B increases the value and button C decreases it. In this mode button A will return to the parameter loop. This easier then it sounds. If you forget what part of the menu you are in pressing button A three times will always get you to the line following routine.
Source code
Here is a link to the source code for this program.