Hey everyone, I was looking some sort of quick or easy explanation to what network tables are or what they are used for on the basic level. I’m new to FRC and Java and any help would be greatly appreciated. Thanks!
NetworkTables is an implementation of a distributed “dictionary”. That is named values are created either on the robot, driver station, or potentially an attached coprocessor, and the values are automatically distributed to all the other participants. For example, a driver station laptop might receive camera images over the network, perform some vision processing algorithm, and come up with some values to sent back to the robot. The values might be an X, Y, and Distance. By writing these results to NetworkTable values called “X”, “Y”, and “Distance” they can be read by the robot shortly after being written. Then the robot can act upon them.
NetworkTables can be used by programs on the robot in either C++, Java or LabVIEW and is built into each version of WPILib.
The wplib slideshow is a great starting place. Network tables allow you to communicate from your Robo rio to an off board co processor or driver station.
A java example
On the co-processor side or whatever that puts the data into the network tables.
// declare it
private NetworkTable table;
// Init NetworkTable
NetworkTable.setClientMode();
NetworkTable.setTeam(6325);
NetworkTable.setIPAddress("roborio-6325-frc.local"); // ip of roborio
NetworkTable.initialize();
table = NetworkTable.getTable("LiftTracker"); // what table data is put in
// in the processing
table.putDouble("distanceFromTarget", distanceFromTarget());
table.putDouble("angleFromGoal", getAngle());
Then on the roborio you get the values
NetworkTable table = Robot.table;
liftTable = NetworkTable.getTable("LiftTracker");
Double angleFromGoal = liftTable.getNumber"angleFromGoal", -1.0);
Double distanceFromTarget = liftTable.putNumber("distanceFromTarget", -1.0);
The first value is key. The second part is default values.
I can not edit my post but all the putDouble methods are depreciated and you must use putNumber.
When I explain NetworkTables to anyone who’s a professional software developer, in order to try to dissuade them from creating their own solution to this problem I describe it as “A built-in way to multi-cast any data in a JSON-like way to all clients on the robot’s network”. It still doesn’t seem to work; everyone still wants to do their own thing with comms :rolleyes:.