View Single Post
  #3   Spotlight this post!  
Unread 17-02-2012, 23:31
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Getting values from SmartDashboard

Well, the SmartDasboard's entire communication interface is run via NetworkTables, so you have to work with those. On the SmartDashboard end, you probably want to make some sort of extension, with those options possibly as properties for the extension. Then, when these properties change, you change a value in a NetworkTable, then retrieve it on the robot end with a get<Type>(<key>).

That was a terribly generic description, so let's spice it up with an example! Let's say you have a SmartDashboard extension (what it does doesn't matter for the scope of this example), and it has a property called "speed". On the extension's end, you have 2 ways to do this, and each has a corresponding way of accessing it on the robot.
The first way:
Code:
// SmartDashboard end
NetworkTable table = Robot.getTable();
table.beginTransaction();
table.putDouble("speed",SpeedProperty.getValue()),
table.endTransaction();

// Robot end
double speed = NetworkTable.getTable("SmartDashboard").getDouble("speed");
Note that on the SmartDashboard end, you could replace Robot.getTable() with NetworkTable.getTable("SmartDashboard") and it would do the exact same thing.
Now for the second method (which is really the same thing, just put together slightly differently):
Code:
// SmartDashboard
NetworkTable table = NetworkTable.getTable("Super awesome extension of awesome coolness XTREME!"); // note the custom table name
table.beginTransaction();
table.putDouble("speed",SpeedProperty.getValue()),
table.endTransaction();

// Robot
double speed = NetworkTable.getTable("Super awesome extension of awesome coolness XTREME!").getDouble("speed"); // if the table name is the same on both ends, it will work as though it's really just one table.
Just keep in mind the basic rules of NetworkTables: surround all puts with begin/endTransaction bits, and don't expect instant transfer.

Happy SmartDashboarding!

Last edited by Ginto8 : 17-02-2012 at 23:46.
Reply With Quote