Go to Post Now go out, get some sleep, and build the greatest robot you have ever made. - nicholsjj [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 Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 06-02-2015, 00:49
kylelanman's Avatar
kylelanman kylelanman is offline
Programming Mentor
AKA: Kyle
FRC #2481 (Roboteers)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Tremont Il
Posts: 186
kylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to all
RoboRio Losing WPILib Preferences

Team 2481 is trying to use the Preferences class in WPILib this year to store persisted settings rather than using our own similar solution from previous years. The smart dashboard widget is primarily what made it appealing. We are storing things like encoder offsets and PID values for our closed loop controllers.

Modifying code and redeploying works as we would expect. The settings we put into the preferences are persisted to flash and they load back up when we relaunch our program. For what it is worth we are calling save when we change settings.

When the robot is rebooted or power cycled it is hit or miss whether or not our settings get completely blown away or if they load up. About 1 in 3 reboots we loose our settings. The settings all still show up in the SmartDashboard but in order for the robot to actually use them we have to change them slightly then change them back to the actual value that should have been persisted.

Has anyone else experienced similar results or is this problem unique to us.

Thanks in Advance!!

Kyle
__________________
"May the coms be with you"

Is this a "programming error" or a "programmer error"?

Reply With Quote
  #2   Spotlight this post!  
Unread 06-02-2015, 19:43
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 152
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: RoboRio Losing WPILib Preferences

That sounds a bit strange. I'm sure it's frustrating! I wonder if the preferences mechanisms under the hood are not yet ready when you're trying to access them programatically. Maybe doing a few experiements...

- Assign a button on a joystick to load the values and print them out or display them. When you see they are not loaded, wait a minute and then use the joystick button to load them. If this works, then it's a bug in the preferences allowing the load to happen too soon. Just a hunch.

- Another thought - if you store a preference item ... call it MAGICCOOKIE and set it equal to something you know - like your team number - or a string like "FRC"... then when you load preferences, you could immediately check for your MAGICCOOKIE value being correct. If it's not correct, you could Wait() and try again - and again - for some period of time. If this solves/heals it in a few trys / seconds upon initialization, this could work for you.

My team did use preferences a few years back but found only strings to be functional and so we used strings and sscanf() to scan those formatted strings into variables. I doubt the same issue is here but thought I'd throw it out there just in case it rings a bell for you.

bob
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
Reply With Quote
  #3   Spotlight this post!  
Unread 07-02-2015, 09:51
kylelanman's Avatar
kylelanman kylelanman is offline
Programming Mentor
AKA: Kyle
FRC #2481 (Roboteers)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Tremont Il
Posts: 186
kylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to all
Re: RoboRio Losing WPILib Preferences

Good Call.

We are currently using Preferences::GetInstance().Gettype("key", default) in the constructor of static instances of Subsystems.

We confirmed with printf that the values being returned are the defaults.

Looking at the source for Preferences we found a potential race condition such that the .Gettype() call gets the lock on m_tableLock before the ReadTask is fully spun up. If this occurs then the values are retrieved prior to being loaded from the file.

One solution would be serializing this process and not forking another thread/task to read the file.

The other solution would be to use the Contains("[i]key[I/]") and Wait() as you proposed in a loop.

Thanks Again!

Kyle
__________________
"May the coms be with you"

Is this a "programming error" or a "programmer error"?

Reply With Quote
  #4   Spotlight this post!  
Unread 12-02-2015, 01:34
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 152
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: RoboRio Losing WPILib Preferences

Excellent to hear a confirmation there. We had a problem with network tables a few years ago which was a race condition too. We actually had to play around with how we started up and initiated things in order to "tease" it into not winding up in the race condition.
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
Reply With Quote
  #5   Spotlight this post!  
Unread 12-02-2015, 09:01
MrRoboSteve MrRoboSteve is offline
Mentor
AKA: Steve Peterson
FRC #3081 (Kennedy RoboEagles)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Bloomington, MN
Posts: 570
MrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond repute
Re: RoboRio Losing WPILib Preferences

Kyle -- I don't see a bug report for this -- could you enter one?

https://usfirst.collab.net/sf/tracke...cker.4_defects
__________________
2016-17 events: 10000 Lakes Regional, Northern Lights Regional, FTC Burnsville Qualifying Tournament

2011 - present · FRC 3081 Kennedy RoboEagles mentor
2013 - present · event volunteer at 10000 Lakes Regional, Northern Lights Regional, North Star Regional, Lake Superior Regional, Minnesota State Tournament, PNW District 4 Glacier Peak, MN FTC, CMP
http://twitter.com/MrRoboSteve · www.linkedin.com/in/speterson
Reply With Quote
  #6   Spotlight this post!  
Unread 12-02-2015, 09:19
Ken Streeter's Avatar
Ken Streeter Ken Streeter is offline
Let the MAYHEM begin!
FRC #1519 (Mechanical Mayhem)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 2005
Location: Team: Milford, NH; Me: Bedford, NH
Posts: 468
Ken Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond repute
Re: RoboRio Losing WPILib Preferences

Quote:
Originally Posted by kylelanman View Post
We are currently using Preferences::GetInstance().Gettype("key", default) in the constructor of static instances of Subsystems.
We addressed this issue in our code by moving the calls to Preferences.getInstance().GetFoo() to not be in the constructors of our subsystems, but instead in an "init()" method for the subsystem. The "init()" method is called out of robotInit(), which is quite later in the startup sequence.

Below is our current robotInit() which shows the calls to init() in our subsystems that have some "late initialization" needs.

Code:
    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {
    	
      System.out.println("robotInit");
      SmartDashboard.putString("Auto Prog",  "Initializing...");
      
      DriverStation.reportError("About to construct Autonomous Subsystem... \n", false);      
	  autonomous = new Autonomous();
      DriverStation.reportError("Done constructing Autonomous Subsystem.\n", false);
      
      DriverStation.reportError("About to construct OI... \n", false);      
	  oi = new OI();
      DriverStation.reportError("Done constructing OI.\n", false);
      
      // initialize the subsystems that need it
      drive.init();
      elevator.init();
      
      // instantiate the command used for the autonomous period
      autonomousCommand = new RunAutonomous();
      DriverStation.reportError("Constructed auto command.\n", false);
      SmartDashboard.putString("Auto Prog",  "Done.");
      Autonomous.updateDashboard();
    }
__________________
Ken Streeter - Team 1519 - Mechanical Mayhem (Milford Area Youth Homeschoolers Enriching Minds)
2015 NE District Winners with 195 & 2067, 125 & 1786, 230 & 4908, and 95 & 1307
2013 World Finalists & Archimedes Division Winners with 33 & 469
2013 & 2012 North Carolina Regional Winners with teams 435 & 4828 and 1311 & 2642
2011, 2010, 2006 Granite State Regional Winners with teams 175 & 176, 1073 & 1058, and 1276 & 133
Team 1519 Video Gallery - including Chairman's Video, and the infamous "Speed Racer!"
Reply With Quote
  #7   Spotlight this post!  
Unread 18-02-2015, 01:13
kylelanman's Avatar
kylelanman kylelanman is offline
Programming Mentor
AKA: Kyle
FRC #2481 (Roboteers)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Tremont Il
Posts: 186
kylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to all
Re: RoboRio Losing WPILib Preferences

I didn't realize this thread picked back up....As we were doing additional testing we ran into instances where calling save was not actually saving the file. We verified this with 'watch -n1 cat filename' in an ssh session. At that point we ripped out Preferences and used our own implementation from last year because we knew it was reliable. I will try to submit a bug report in the next couple of days with the details.
__________________
"May the coms be with you"

Is this a "programming error" or a "programmer error"?

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 02:59.

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