![]() |
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 |
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.
|
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 endNow for the second method (which is really the same thing, just put together slightly differently): Code:
// SmartDashboardHappy SmartDashboarding! |
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. |
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?
|
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. |
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:
|
Re: Getting values from SmartDashboard
Quote:
|
| All times are GMT -5. The time now is 09:14. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi