|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hey! I'm trying to get NetworkTables working, and I have a list of things I want to send to the driver station. So I'm putting values into a Subtable on the robot, and trying to read them on the DS.
Is there a way to loop through every value in an ITable (which NetworkTables extends)? I assume there is, because the TableViewer program can do it (I compiled it but can't figure it out) Here's the code I use for putting the info into the NetworkTable. Code:
public void sendSubsystemInfo() {
Vector list = Warp7Robot.subsystem.subsystemList;
NetworkTable subtable = (NetworkTable) table.getSubTable("Subsystems");
for (int i = 0; i < list.size(); i++) {
Subsystem s = (Subsystem) list.elementAt(i);
subtable.putBoolean(s.getName(), s.isEnabled());
}
}
Last edited by Aero : 02-13-2014 at 06:34 PM. |
|
#2
|
|||
|
|||
|
Re: How do I use NetworkTables' SubTables?
The TableViewer application does not use NetworkTable objects exclusively, there's quite a bit of back-end.
You know the names of your subsystems; is there a reason you can't just use ITable.getBoolean("NAME_HERE")? |
|
#3
|
|||
|
|||
|
Re: How do I use NetworkTables' SubTables?
I could, but it's kind of annoying to have to edit the driver station program every time I add or remove a subsystem. I'd much prefer dynamicism
|
|
#4
|
||||
|
||||
|
Re: How do I use NetworkTables' SubTables?
Once you connect, you can call NetworkTableClient.getEntryStore().list() to get a list of all the existing key names in your client's copy of the table.
A listener will give you updated keys and values as they come in, so even if you don't get all the existing key names when you first connect, you'll be able to build a complete list of keys pretty quickly if you are sending them out in periodic(). |
|
#5
|
||||
|
||||
|
Re: How do I use NetworkTables' SubTables?
I just reread your post, and something hit me...
Where are you trying to see what values are in the table? The FRC Driver Station software, the dashboard, or another team-written program running on the driver station PC? |
|
#6
|
||||
|
||||
|
Re: How do I use NetworkTables' SubTables?
...and I just checked, and dumping the keys at the beginning is unnecessary. When you connect, it appears you get update events for every existing value in the table, so you can just set up a listener and watch the names and values stream in...
|
|
#7
|
|||
|
|||
|
Re: How do I use NetworkTables' SubTables?
Quote:
Thanks again! |
|
#8
|
||||
|
||||
|
Re: How do I use NetworkTables' SubTables?
super straightforward: I implemented ITableListener, then called networkTableClient.addTableListener (this, true).
If you need to see connections and disconnections, implement IRemoteConnectionListener, and call networkTableClient.addTableListener(this,true). of course, you can have different objects for your listener (so you wouldn't use this), but hopefully you'll get the gist of it. your valueChanged() can be a little tricky: you could get back an array or just a single variable of unknown type, and you don't know ahead of time what it will be. I had a few instance operators in there to sort stuff out. For display purposes, this worked nice: Code:
if (o instanceof Object[]) {
for (Object o1 : (Object[]) o) {
sb.append("\t");
sb.append(o1.toString());
} else {
sb.append("\t");
sb.append(o.toString());
}
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|