Go to Post What can you do? The more time you waste here speculating the less time you have to work on the robot. Go! Build Robots! Now! - Jessica Boucher [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 18:38.

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