NetworkTable : Tables, SubTables

We are developing cRio software in C++, and using SmartDashboard with a custom Java extension we are developing. Our goal is to have the C++ cRio code detect targets, and display information within a custom WPICameraExtension on the smart dashboard.

On the robot, we create a “Camera” table via NetworkTable::GetTable(“Camera”). So far, so good.

Our next step: creating a “SubTable” for each detected Target (via NetworkTable::GetSubTable(“Target<TargetNum>”).

Some questions are coming up:

  1. Within the C++ code, it’s not clear how to create a SubTable. Do we “new” a NetworkTable and then use PutSubTable()? Or do we invoke NetworkTable::GetTable(subtablename) and then PutSubTable() w/the table that is returned?

  2. On the SmartDashboard side, we are retrieving the “Camera” Table via Robot.getTable().getTable(“Camera”). Is that correct? The hierarchy does not seem parallel between the Java and C++ code (e.g., the Java API seems to imply a “top-level, unnamed” table, whereas the C++ API seems to imply a set of named tables at the top-level.

  3. If we wanted to retrieve a sub-table on the SmartDashboard side, would we retrieve it via:

    Robot.getTable().getTable(“Camera”).getSubTable(“Target<targetnum>”)

Or

Robot.getTable().getTable("Target&lt;targetnum&gt;")

I would prefer to use sub-tables, as it seems a more clear way of expressing the “sub-tables” for detected targets. But I’m unclear as to the appropriate method for creating sub-tables before calling “putSubTable()”.

Perhaps some diagram showing the hierarchy of “top-level-table”, “named table” and “named sub-table” would be helpful… Or perhaps a code sample?

It seems like–in Java, at least–the tables are simply hash tables with buckets. Each bucket can contain any type of data…eg double, boolean, or even another NetworkTable. So adding a subtable in Java looks like:

NetworkTable add = new NetworkTable();
NetworkTable.getTable(“main”).putSubTable(“aSubTable”, add);

We have gotten errors if we try to access a subtable that we have not created yet.

NetworkTable.getTable(“main”).getSubTable(“camera”).putDouble(“x”, 40);
//does not work, unless you have put the “camera” subtable into the main table previously

Again, we are using Java, so it may be implemented somewhat differently in C++. Hope that helps, though.