Go to Post I suggest that FIRST should include a "big red button" in the KOP next year to make everyone happy. :p - Jay H 237 [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 13-02-2014, 16:19
Aero Aero is offline
consumes pizza, produces code
AKA: Ari Lotter
FRC #0865 (Warp7)
Team Role: Programmer
 
Join Date: May 2013
Rookie Year: 2013
Location: Toronto
Posts: 30
Aero is on a distinguished road
Unhappy Can I loop through a NetworkTable?

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 : 13-02-2014 at 18:34.
Reply With Quote
  #2   Spotlight this post!  
Unread 13-02-2014, 19:48
irvingc irvingc is offline
Registered User
FRC #0948 (Newport Robotics Group)
Team Role: Leadership
 
Join Date: Jan 2014
Rookie Year: 2011
Location: Bellevue, WA
Posts: 31
irvingc is on a distinguished road
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")?
Reply With Quote
  #3   Spotlight this post!  
Unread 13-02-2014, 21:47
Aero Aero is offline
consumes pizza, produces code
AKA: Ari Lotter
FRC #0865 (Warp7)
Team Role: Programmer
 
Join Date: May 2013
Rookie Year: 2013
Location: Toronto
Posts: 30
Aero is on a distinguished road
Re: How do I use NetworkTables' SubTables?

Quote:
Originally Posted by irvingc View Post
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")?
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
Reply With Quote
  #4   Spotlight this post!  
Unread 14-02-2014, 09:55
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 336
fovea1959 will become famous soon enough
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().
Reply With Quote
  #5   Spotlight this post!  
Unread 14-02-2014, 09:57
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 336
fovea1959 will become famous soon enough
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?
Reply With Quote
  #6   Spotlight this post!  
Unread 14-02-2014, 10:03
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 336
fovea1959 will become famous soon enough
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...
Reply With Quote
  #7   Spotlight this post!  
Unread 14-02-2014, 10:25
Aero Aero is offline
consumes pizza, produces code
AKA: Ari Lotter
FRC #0865 (Warp7)
Team Role: Programmer
 
Join Date: May 2013
Rookie Year: 2013
Location: Toronto
Posts: 30
Aero is on a distinguished road
Re: How do I use NetworkTables' SubTables?

Quote:
Originally Posted by fovea1959 View Post
...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...
Awesome! We're using a custom piece of software for the client-side, as the SmartDashboard didn't really offer what we were looking for. Is there any example code for adding an ITableListener (I think that's what I want, not sure)? I can probably figure it out tonight, but I'm just wondering.
Thanks again!
Reply With Quote
  #8   Spotlight this post!  
Unread 14-02-2014, 11:06
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 336
fovea1959 will become famous soon enough
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());
}
You *could* also get the type by going back to the client.getEntryStore().getEntry(name).getType(), but I didn't need it. I did grab client.getEntryStore().getEntry(name).getSequenceN umber() so I could see if we had updates that didn't get to the client (this is from our telemetry receiver).
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 13:26.

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