I’ve noticed WPILib made a major overhaul to the NetworkTables package, and I was wondering if anyone knows how to write code in Java using the new package equivalent to the the NetworkTable.getTable(""); function in the wpilibj NetworkTables package from last year? I’ve been having a lot of trouble with this new NetworkTable package and if anyone could link additional documentation that would be appreciated :yikes: !
Here is the Javadoc for NetworkTable:
http://first.wpi.edu/FRC/roborio/release/docs/java/edu/wpi/first/networktables/NetworkTable.html
NetworkTable.getInstance().getTable is the answer I found in the javadocs.
It’s
NetworkTableInstance.getDefault().getTable("table_name");
Keep in mind that it’s possible to have multiple multiple instances running at the same time, and each network table only exists on a single instance at a time. WPILib uses the default instance, but it’s always possible to create new ones for your own use (eg communicating with coprocessors on a separate connection)
We’re working on more “tutorial” documentation for the new NT API, but keep in mind the “old” NT package/classes are still available and still work just fine this year! There’s no need to change your code for this season unless you want to get ahead of the curve for a future year. In WPILib, we try as much as possible to mark things as deprecated for at least a year (and often multiple years) before removing them. In some cases that’s not possible due to language limitations, but in general we do try to minimize the required code changes each year compared to the previous year.
Hey,
So when I try to use the old network tables I get a super weird red cross over my code. Does that still mean that it would work?
Here’s an image - https://imgur.com/a/PEb0O
Yes. That’s just Eclipse trying to be helpful in telling you that it’s been marked deprecated. You’ll find it still compiles just fine.
Hey, could I ask a question about this? What is the advantage of running separate instances of Networktables vs. say creating separate tables within one instance?
This feature is mainly useful for coprocessors and unit testing. It allows a single program to be a member of two completely independent Networktables “networks” that contain completely different (and unrelated) sets of tables. For most general usage, you should use tables within the single instance, as all current dashboard programs can only connect to a single NT server at a time.
Normally the “default” instance is set up on the robot as a server, and used for communication with the dashboard program running on your driver station computer. This is what the SmartDashboard and LiveWindow classes use.
If you had a coprocessor and wanted to have a set of tables that’s shared only between the coprocessor and the robot, you could set up a separate instance in the robot code that acts as a client (or a server) and connect the coprocessor to it, and those tables will NOT be sent to the dashboard.
Similarly, if you wanted to do unit testing of your robot program’s NT communications, you could set up your unit tests such that they create a separate client instance (still within the same program) and have it connect to the server instance that the main robot code is running.
Another example might be having two completely separate dashboard programs. You could set up two networktables server instances in your robot program (on different TCP ports of course), set up different tables on each one, and have each dashboard connect to a different server instance. Each dashboard would only see the tables on its instance.