View Single Post
  #1   Spotlight this post!  
Unread 10-05-2015, 07:51 PM
rod@3711 rod@3711 is offline
Registered User
AKA: rod nelson
FRC #3711 (Iron Mustangs)
Team Role: Mentor
 
Join Date: May 2014
Rookie Year: 2014
Location: Trout Lake, WA
Posts: 64
rod@3711 is an unknown quantity at this point
Read/Write Preferences in C++

The 2015 SmartDashboard description gives a code example to set Preferences, then display them by adding a Robot Preferences widget.

Last year we made program changes for some timing and positioning variables that we would have preferred to set via the SmartDashboard and have them preserved.

I added the code to a Sample Robot project and can not get it to work.

The lines we added have // %rod comments in the following snippet.

////////////////////////////////////////////////////////////////////
class Robot: public SampleRobot
{
RobotDrive myRobot; // robot drive system
Joystick stick; // only joystick

Preferences *prefs; // %rod

public:
Robot() :
myRobot(0, 1), // these must be initialized in the same order
stick(0) // as they are declared above.
{
myRobot.SetExpiration(0.1);
prefs = Preferences::GetInstance(); // %rod
}

void RobotInit(){ // all new %rod
double x;
double y;
SmartDashboard:utString("Version","1.1");
x = prefs->GetDouble("x Pref",33);
y = prefs->GetDouble("y Pref",66);
}
//////////////////////////////////////////////////////

The SmartDashboard will display the version 1.1 data, but when we add the Robot Preferences widget, it is blank.

I then spent several hours trying prefs->PutDouble, prefs->Save..., etc. and have now given up.

Is there a working example of C++ using Preferences?
Reply With Quote