View Single Post
  #2   Spotlight this post!  
Unread 22-02-2012, 08:11
charrisTTI charrisTTI is offline
Ramblin' Wreck
AKA: Charles Harris
FRC #0623
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Vienna, VA
Posts: 106
charrisTTI has a spectacular aura aboutcharrisTTI has a spectacular aura about
Send a message via AIM to charrisTTI
Re: Preferences : Write on SmartDasboard, read from cRio/C++

To get preferences to work to/from the smartdashboard here is what I had to do in java. C++ will be similar.


Code:
On the robot:

// declare variable

NetworkTable preferencesTable;

// in robotInit get or create singleton instance (getTable will get instance if it exists or create one if it does not.

preferencesTable = NetworkTable.getTable("Preferences");

// write some test data

preferencesTable.putString("pref1", "998899");
preferencesTable.putString("pref2", "77777");


// in teleopPeriodic for test purposes get the data
System.out.println( "pref1 = " + preferencesTable.getString("pref1", "Empty"));
System.out.println( "pref2 = " + preferencesTable.getString("pref2", "Empty"));
Start running smartdashboard on the DS with the Preferences grid open.

Start program on robot with above code included. The two initial values for pref1 and pref2 should show on the grid. Enable teleop and you should see the two values on the console. Now edit the values in the preferences grid on the smartdashboard, the values should change on the console.

One caveat, use putString and getString not one of the other methods such as getDouble, getInt, etc. In my first test I used putInt to set the initial values and getInt to retrieve them. When I changed the values on the smartdashboard, they stopped displaying in the console. Smartdashboard sends everything as a string. You will need to parse to a number on the cRio.

The save button is not necessary unless you want to save the table values to flash memory on the crio. They could then be read in at startup. There is a cautionary comment that too much saving can damage the flash memory of the crio. Don't do it in your periodic or continuous methods, only when necessary.
__________________
FRC 623 2003,2004,2005,2006,2007,2008, 2009, 2010, 2011
FRC 1900 2007
FVC 60 and 193 2006
FVC 3271 2007
FTC 226 and 369 2008, 2009, 2010, 2011
FTC 3806 2010
Reply With Quote