On the smart dashboard side, we transition to Teleop mode, enable it in the driver station, and then add the “RobotPreferences” widget, but the above preferences don’t show up. (Actually, nothing shows up in the widget). Other controls are communicating Ok w/the robot code, just not the Preferences.
So we push the “Save” button on the smart dashboard side, reboot the robot, and still nothing shows up in the “RobotPreferences” widget.
Just getting the preference doesn’t ensure that the preference exists in the file. You need to get it there somehow (either by putting a value in there in your program or by entering in with the smartdashboard widget and then saving it).
If you want to do it programatically, you can check if the preference exists, and if it doesn’t exist, put a value and then save.
So w/the code shown above, do you think this sequence should work?
A) Start robot (runs above code).
B) In SmartDashboard, in Preferences widget, add a variable w/same name as declared in the code above.
C) Then, press SAVE.
D) Then, reboot robot, restart smart dashboard, and the value should show up in the Preferences widget.
I ask this nit-picky question because when we tested it, we performed all of these steps - except B. Instead, we performed A, C and D. Our assumption was that the robot code’s default values would get saved when “SAVE” was pressed in the widget, but that appears not to be the case.
Hmmm - no joy. Performed steps A-D, and the robot still uses the “default” preference values. After restarting the robot, the Robot Preferences widget shows no values, and they didn’t appear in the NetworkTables viewer either.
We noted that smart dashboard doesn’t prompt for any data type when adding a preference. I assume the smart dashboard is adding a string. If so, is there a problem because the dashboard-added string is not the same datatype that the robot code is expecting?
Perhaps we have to modify the robot code to only use strings, converting them ourselves to doubles/ints/etc within the robot code?
I would suggest using the Prefs.PutNumber function in the RobotInit to get the keys in the table.
Then in TeleopPeriodic use:
PIDNAME->SetPID(Prefs->GetNumber(“TiltP”. 1.0), Prefs->GetNumber(“TiltI”, 0.0), Prefs->GetNumber(“TiltD”. 0.0));
Replacing PIDNAME with your PID.
Also, why don’t you use LiveWindow to tune the PID and then hard code those parameters once they are set?
Great idea, PutNumber (but not “Save”) in the Robot. Thanks…
We are using LiveWindow to tune PIDs, but have multiple robots (competition, practice) and want to use the same code for each - and differences in robot weight mean PID coefficients may be different. Plus have some other calibration constants (angle sensor offsets, etc.) that differ on each robot.
Was there anything in the TableViewer before restarting? Is there anything in the wpilib-preferences.ini file on the robot (you can FTP to the robot to retrieve it).
We noted that smart dashboard doesn’t prompt for any data type when adding a preference. I assume the smart dashboard is adding a string. If so, is there a problem because the dashboard-added string is not the same datatype that the robot code is expecting?
Perhaps we have to modify the robot code to only use strings, converting them ourselves to doubles/ints/etc within the robot code?
I’ve only looked at the java implementation, but C++ should be similar. Internally, everything is transmitted and stored as strings, and then the string is parsed and converted to the right format based on the type you specify in the get (eg int, float, boolean, string, etc). You shouldn’t need to do that in your own code.
Are you using the latest C++ update from March 4th? There have been at least two bugs in the preferences class that have been fixed this year.
We’re still struggling to get the C++ Preferences class to actually save values to a file on the CRio. We’ve verified we’re using the latest (3/4/2013) WPILibrary update and v47 of the Crio firmware.
Here’s the robot startup code that populates the preferences:
The Preference values, which are added by the robot at startup and are showing upon the Dashboard, show up in and can successfully be edited in the “Robot Preferences” control.
We deleted the preferences file (wpilib-preferences.ini) on the robot and restarted the robot, and the file gets re-created by the robot startup code. However it still only has the [Preferences] header and no key/value entries in it.
The “PutDouble” code invoked by the robot startup code definitely populates the values into the NetworkTables (since they show up on the dashboard).
So in summary, since the Preferences class is actually re-creating a preferences file after we had previously deleted it, and is populating the NetworkTables, but no key/value pairs are written to the preferences file, it appears that the “PutDouble” code in the robot is not putting the values into the internal m_values table. We’ve also verified the string names of the variables being added to the Preferences are unique.