Go to Post Pneumatic components always give me gas... - Alan Anderson [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 21-02-2012, 12:36
slibert slibert is offline
Software Mentor
AKA: Scott Libert
FRC #2465 (Kauaibots)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2005
Location: Kauai, Hawaii
Posts: 343
slibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud of
Preferences : Write on SmartDashboard, read from cRio/C++

Our C++ robot code reads settings via the WPILib Preferences class, but we want to edit these values on the smart dashboard.

We added the Robot Preferences widget on the dashboard. None of the robot-defined preference names are seen there, even though the dashboard shows other NetworkTable status data from the robot.

We pressed SAVE on the preferences widget, then rebooted robot and dashboard and when we restart both and connect, the dashboard preferences widget still shows no robot-defined preference values.

Does anyone know how we can edit the robots preferences from the Smartdashboard's preferences widget?

Last edited by slibert : 21-02-2012 at 14:12.
Reply With Quote
  #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
  #3   Spotlight this post!  
Unread 22-02-2012, 21:44
devodl devodl is offline
Registered User
AKA: Steve Deal
FRC #0578 (R3 - Red Raider Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Rochester, NY
Posts: 21
devodl is just really nicedevodl is just really nicedevodl is just really nicedevodl is just really nicedevodl is just really nice
Re: Preferences : Write on SmartDasboard, read from cRio/C++

Thank you so much for your timely posting. I've been trying to use the SmartDashboard for Driver/Operator input to set values. Your example and point about using String was the key piece.

One of the students explained that the Tab key can be used to "enter" a new value since the Enter key will disable the robot.

One question. I accidentally used the Save button and now the table has a variable that I no longer use.
How can I clear the saved entries from the cRIO flash memory?

update: Perhaps the way to remove bad entries is with the Preferences.remove() method?

Thanks again,
Steve

Last edited by devodl : 23-02-2012 at 12:10.
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 12:35.

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