Go to Post I found another student once at a Cross Country meet because she was wearing a team shirt. I must say, I was surprised. I should start wearing my team shirt around more often. - TheBoulderite [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 02-17-2012, 08:32 PM
cooltext cooltext is offline
Registered User
FRC #0835
 
Join Date: Jan 2012
Location: Michigan
Posts: 32
cooltext is an unknown quantity at this point
Getting values from SmartDashboard

how do I use the SmartDashboard to control values while the robot is running, so say I want to change a variable's value while the robot is running, I could type the new value into the SmartDashboard and the robot would read that new value?

thanks
Reply With Quote
  #2   Spotlight this post!  
Unread 02-17-2012, 11:04 PM
neal's Avatar
neal neal is offline
Neal
FRC #1777 (Viking Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2009
Location: United States
Posts: 56
neal is an unknown quantity at this point
Re: Getting values from SmartDashboard

I haven't tried it, but seems like the getDouble() and the other get methods is what you're looking for.
Reply With Quote
  #3   Spotlight this post!  
Unread 02-17-2012, 11:31 PM
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 : 02-17-2012 at 11:46 PM.
Reply With Quote
  #4   Spotlight this post!  
Unread 02-19-2012, 12:26 AM
Sunstroke Sunstroke is offline
Programmer
AKA: Joe Grinstead
FRC #3504 (Girls of Steel)
Team Role: Mentor
 
Join Date: Apr 2009
Rookie Year: 2009
Location: New England
Posts: 49
Sunstroke is an unknown quantity at this point
Re: Getting values from SmartDashboard

Quote:
Originally Posted by Ginto8 View Post
Just keep in mind the basic rules of NetworkTables: surround all puts with begin/endTransaction bits, and don't expect instant transfer.

Happy SmartDashboarding!
I'm excited someone understands the SmartDashboard and stuff so well, but I would like to correct you on this point.

It is actually worse if you surround things with begin and end transactions. If all you care about is sending one value, don't use a transaction.

If you want two or more values to be linked together, that is when you want to use a transaction.
Reply With Quote
  #5   Spotlight this post!  
Unread 08-19-2012, 11:41 AM
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Getting values from SmartDashboard

I'm a bit of a newb at this, so if you don't mind me asking where do I need to put the code on the SmartDashboard end?
Reply With Quote
  #6   Spotlight this post!  
Unread 08-19-2012, 06:02 PM
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

Quote:
Originally Posted by Sunstroke View Post
I'm excited someone understands the SmartDashboard and stuff so well, but I would like to correct you on this point.

It is actually worse if you surround things with begin and end transactions. If all you care about is sending one value, don't use a transaction.

If you want two or more values to be linked together, that is when you want to use a transaction.
Thanks for the correction! I wasn't entirely sure how the whole transaction situation was handled when I wrote that post, but now I understand it a bit better.

However, I'd like to point out that, in most situations, the overhead of the beginTransaction/endTransaction cycle would be mostly negligible. Transactions have a few extra steps (and a few more synchronized() calls), but unless you're doing an insane amount of transactions, the performance difference should be minimal - the main difference is the use of a NetworkQueue, which is just a specialized linked list.

That said, don't use transactions unless you're trying to send more than one entry at a time!


Quote:
Originally Posted by F22Rapture View Post
I'm a bit of a newb at this, so if you don't mind me asking where do I need to put the code on the SmartDashboard end?
You would put the code wherever you want to send or receive a new value - for example, if you have an extension that retrieves the state of the robot's drive train, you could have a TimerTask which periodically refreshes it, and the data retrieval would go in there.

I'm pretty sure that there's also some way to have the data automatically refreshed when it changes, but I haven't figured out how to use it yet - though I'm guessing it's possible by implementing NetworkListener or NetworkAdditionListener.
Reply With Quote
  #7   Spotlight this post!  
Unread 08-20-2012, 10:00 PM
Djur's Avatar
Djur Djur is offline
WPILib
AKA: Sam Carlberg
no team
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Massachusetts
Posts: 182
Djur will become famous soon enough
Re: Getting values from SmartDashboard

To answer OP's question, you could call NetworkTable.putDouble() in a widget to send a number and then call NetworkTable.getDouble() in the robot's code to retrieve it.

Driver's side:
Code:
NetworkTable.getTable("SmartDashboard").putDouble("Pi", 3.14159);
Robot side:
Code:
double pi = NetworkTable.getTable("SmartDashboard").getDouble("Pi");
Slightly offtopic here; this is aimed towards Ginto8.
Quote:
Originally Posted by Ginto8 View Post
You would put the code wherever you want to send or receive a new value - for example, if you have an extension that retrieves the state of the robot's drive train, you could have a TimerTask which periodically refreshes it, and the data retrieval would go in there.

I'm pretty sure that there's also some way to have the data automatically refreshed when it changes, but I haven't figured out how to use it yet - though I'm guessing it's possible by implementing NetworkListener or NetworkAdditionListener.
Don't bother with using a TimerTask; the new NetworkTables will use listeners to update values when they change in the table.
__________________
WPILib dev (RobotBuilder, SmartDashboard, GRIP)
Reply With Quote
  #8   Spotlight this post!  
Unread 08-21-2012, 03:11 AM
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

Quote:
Originally Posted by Djur View Post
Don't bother with using a TimerTask; the new NetworkTables will use listeners to update values when they change in the table.
I wasn't saying to update values in the table, I was saying to update values from the table. But Looking at the NetworkTable library, I realize that a NetworkListener would be a much better choice in this context.
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 07:26 AM.

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