Subtables not being read in Network Tables

Hello CD,

I’m having a hard time reading subtables in Java.


In the photo, I have the subtable “pathTable”, along with 2 basic entries “-turret-feedback” and “-turret-y_offset”.

I can read the 2 basic entries by writing:

private NetworkTableEntry turret = SmartDashboard.getEntry("-turret-feedback");

turret.getDouble(1.0);

However, when I change “-turret-feedback” to “pathTable” such that I am accessing a subtable rather than a double, there is no get method for turret to read its value.

Also, when I do:

turret.getKeys().toString();

it prints the turret feedback and offset, but not pathTables.
It’s like it doesn’t recognize the subtable as part of Smartdashboard.

I looked at What is NetworkTables — FIRST Robotics Competition documentation for help, but when I did this:

public TestSub() {
  NetworkTableInstance inst = NetworkTableInstance.getDefault();  
  smartTable = inst.getTable("pathTable");
}

  @Override
  public void periodic() {
    System.out.println(smartTable.getSubTables().toString());
  }

it resulted in just printing an empty array, despite me having various datafields within the subtable.

Basically I was wondering if anyone has any tips reading subtables that I’m missing.

Fundamentally NetworkTables is a flat namespace. Subtables are completely notional things and not actually stored as such, but rather just prefix the entry key with the subtable with “/” separators. For example, SmartDashboard → pathTable → -turret-feedback is actually stored as a single string “/SmartDashboard/pathTable/-turret-feedback”. This means you can’t actually “access” a subtable. You can only access the individual entries within it. All of the functions like getSubTables() work by seeing what keys start with that prefix.

The SmartDashboard class also prefixes all entries it creates with “/SmartDashboard/”. So SmartDashboard.getEntry(“blah”) is really accessing the key “/SmartDashboard/blah”. The raw NetworkTables functions don’t do this. That’s why your third bit of code doesn’t work… it is accessing “/pathTable” not “/SmartDashboard/pathTable”.

1 Like

Now, if they would document the Network Tables entry on the official document as such, it would make a lot of newer folks lives a lot better.

I usually just tell the kids that it’s a virtual spreadsheet and it’s just a 2 column rows of cells with name on one side and values on the other side. Any structure are not real and just flat key->value only.

Like this, from What is NetworkTables — FIRST Robotics Competition documentation?

Actually NetworkTables has a flat namespace for the keys. Having tables and subtables is an abstraction to make it easier to organize your data. So for a table called “SmartDashboard” and a key named “xValue”, it is really a single key called “/SmartDashboard/xValue”. The hierarchy is not actually represented in the distributed data, only keys with prefixes that are the contained table.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.