Go to Post Don't put any weight into the OPR. It's ugly and its momma dresses it funny. - wilsonmw04 [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 05-10-2015, 19:51
Happy Birthday! 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
  #2   Spotlight this post!  
Unread 13-10-2015, 22:07
Happy Birthday! 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
Red face Re: Read/Write Preferences in C++

Finally got back to looking at Preferences and found my mistake.

The string names for the Keys can not have spaces.

x = prefs->GetDouble("x Pref",33);

changed "x Pref" to "xPref" and everything worked as expected.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 14:04.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi