|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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.
|
|
#3
|
||||
|
||||
|
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");
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.
Happy SmartDashboarding! Last edited by Ginto8 : 02-17-2012 at 11:46 PM. |
|
#4
|
|||
|
|||
|
Re: Getting values from SmartDashboard
Quote:
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. |
|
#5
|
||||
|
||||
|
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?
|
|
#6
|
||||
|
||||
|
Re: Getting values from SmartDashboard
Quote:
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:
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. |
|
#7
|
||||
|
||||
|
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);
Code:
double pi = NetworkTable.getTable("SmartDashboard").getDouble("Pi");
Quote:
|
|
#8
|
||||
|
||||
|
Re: Getting values from SmartDashboard
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.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|