Network Tables?

Was just hoping someone could give me the down low on what they are used for/ how to use them?

NetworkTable object can be used to pass data to/from robot code and another program running on another computer on the network. SmartDashboard uses it to pass data to/from robot.

We use it to pass data from image processing software running on the driver station back to the robot.

Here is example code:


//========================================
//Robot Code
// declare object
NetworkTable cameraTable;

// getinstance (table is a singleton, if one does not exist then one will
// be created otherwise returns reference to existing instance
cameraTable = NetworkTable.getTable("camera");

// get data element from the table
// default values returned if no data has been provided from another source yet

cameraTable.beginTransaction();
Boolean imageFound = cameraTable.getBoolean("found", false );
Double imageOffset = cameraTable.getDouble("offset", -1.0);
Double imageDistance = cameraTable.getDouble("distance", -1.0);
cameraTable.endTransaction();

System.out.println( "found = " + imageFound);
System.out.println( "offset = " + imageOffset);
System.out.println( "distance = " + imageDistance);

//=======================================
// Driver Station PC
// camera image processing is done in C# application on DS

// declare it
private NetworkTable table;

// Init NetworkTable
NetworkTable.setIPAddress("10.6.23.2");  // ip of crio
table = NetworkTable.getTable("camera");


// in the image processing loop

table.beginTransaction();
table.putBoolean("found", true);
table.putDouble("distance", distance);
table.putDouble("offset", offset);
table.endTransaction();


Charles, we are interested in doing something with NetworkTable but we are not familiar with it, so here are a few questions:

  1. On the Robot side, I can see WPILib has provided the NetworkTable class, so that part seems straight forward.
  2. On the PC side, who provides the NetworkTable class. Is there an SDK of some sort we need to download? We are planning to develop with C++ on the PC side with Microsoft Visual Studio (C# is fine too if necessary).

NetworkTable is part of smartdashboard, available at

http://firstforge.wpi.edu/svn/repos/smart_dashboard

We were looking at a number of solutions to get from PC into smartdashboard or directly to robot.

Just the other day I came across IKVM.

http://www.ikvm.net/

You can use this tool to “convert” a jar file into a .net assembly.

run IKVM.exe NetworkTable_Client.jar and you get NetworkClient_Table.dll.

Add it as a reference to your managed code project and start “talking” to your robot (see attached screen shot)





Thanks. I don’t have svn at work so I will download the smartdashboard code tonight and take a look. Without looking at the code, I am hoping the NetworkTable_Client.jar file is not overly long and complex. If so, in theory, I could just port it to C++ by hand. C++ and Java are similar enough that it should not be too difficult.

BTW, I did try to look for the NetworkTable_Client.jar file over the web browser interface but the source tree has many branches and very deep. Do you happen to know the path to that file?

Thanks.

Here is the full url to NetworkTable_Client:

http://firstforge.wpi.edu/svn/repos/smart_dashboard/trunk/NetworkTable/Client/Java/trunk

It was more than I wanted to recode.

I just figured out how to put and read data on the preferences grid of the Smartdashboard using Network Tables but there’s is this harmless yet annoying issue that’s bugging me.

I changed the name of the Key / Value in my code but instead of it replacing the old one, it made a second one. the old one is still there on the smartdashboard preferences grid and i can’t figure out how to get rid of it… any ideas?

There is a python implementation of NetworkTables available in RobotPy. See the source tree in github.

This doesn’t work. I’m using eclipse on a windows 7 pc and the wpi lib.

package org.usfirst.frc.team2585.robot;
import edu.wpi.first.wpilibj.tables.ITable;
import edu.wpi.first.wpilibj.tables.ITableListener;
import edu.wpi.first.wpilibj.networktables.NetworkTable;

public class VisionCalib implements ITableListener{
	private double xCoord;
	private double yCoord;
	private double distance;
	private NetworkTable nt;
	//private ITableListener table;
	/**
	 * 
	 */
	public VisionCalib() {
		nt = NetworkTable.getTable("SmartDashboard");
		nt.addTableListener(this);
	}
	
	private void update(){
		System.out.println("Hello");
		nt.beginTransaction();
		xCoord = nt.getNumber("COG_X", 1);
		yCoord = nt.getNumber("COG_Y", 0);
		distance = nt.getNumber("TL_TARGET_DISTANCE", 0);
		nt.endTransaction();
	}
	
	public void valueChanged(ITable itable, String key, Object obj, boolean isNew)
	{
		update();
	}
	public void setNums()
	{
		nt.putNumber("COG_X", 0.0);
		nt.putNumber("COG_Y", 0.0);
		nt.putNumber("TL_TARGET_DISTANCE", 0.0);
	}
	public double getDistance() {return distance;}
	public double getX() {return xCoord;}
	public double getY() {return yCoord;}
	public NetworkTable getNt() {
		return nt;
	}
	public void setNt(String table) {
		this.nt = NetworkTable.getTable(table);
	}
	@Override
	public String toString()
	{
		update();
		String s="";
		s+="xCoord = "+xCoord;
		s+="
"+"yCoord = "+yCoord;
		s+="
"+"Distance = "+distance;
		return s;
	}
}