Setting robot preferences from SmartDashboard
The Robot Preferences class is used to store values in the flash memory on the roboRIO. The values might be for remembering preferences on the robot such as calibration settings for potentiometers, PID values, etc. that you would like to change without having to rebuild the program. The values can be viewed on the SmartDashboard and read and written by the robot program.
Sample program that reads and writes preference values
Often potentiometers are used to measure the angle of an arm or the position of some other shaft. In this case, the arm has two positions, "ArmUpPosition" and "ArmDownPosition". Usually programmers create constants in the program that are the two pot values that correspond to the positions of the arm. When the potentiometer needs to be replaced or adjusted then the program needs to be edited and reloaded onto the robot.
Rather than having "hard-coded" values in the program the potentiometer settings can be stored in the preferences file and read by the program when it starts. In this case the values are read on program startup in the robotInit() method. These values are automatically read from the preferences file stored in the roboRIO flash memory.
Displaying the Preferences widget in SmartDashboard
Viewing and editing the preference values
The values are shown here with the default values from the code. This was read from the robot through the NetworkTables interface built into SmartDashboard. If the values need to be adjusted they can be edited here and saved. The next time the robot program starts up the new values will be loaded in the robotInit() method. Each subsequent time the robot starts, the new values will be retrieved without having to edit and recompile/reload the robot program.