Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Creating a custom NetworkTable? (http://www.chiefdelphi.com/forums/showthread.php?t=155328)

jcbaker4050 14-02-2017 12:04

Creating a custom NetworkTable?
 
Like a number of other teams, Team 4050 is getting into vision processing this year for the first time. Our processing is pretty rudimentary but so far seems really reliable in picking out the gear lift.

Again, like others, we're looking to run our vision code on a Raspberry Pi. (We were originally planning to use a Jetson, but that introduced more hurdles.) However, the issue that we have run into is our complete inexperience with NetworkTables. We want to create a custom NetworkTable that contains the data that the RPi needs to communicate to the roboRIO so that it knows how to control the robot (e.g., turn left, go forward at 50% speed, etc.) Our lead programmer and I have spent a bunch of time researching NetworkTables; however, in every example that we've found, it assumes that the NT already exists.

We feel we understand the client side of things. What we need to know is how to create the NetworkTable so that it's there for the client to update.

Any suggestions, advice, or examples would be greatly appreciated.

SamCarlberg 14-02-2017 12:20

Re: Creating a custom NetworkTable?
 
Networktables.getTable() will create a new table with that name if it doesn't already exist. Ditto for getSubtable()

Thad House 14-02-2017 12:23

Re: Creating a custom NetworkTable?
 
Quote:

Originally Posted by jcbaker4050 (Post 1644801)
Like a number of other teams, Team 4050 is getting into vision processing this year for the first time. Our processing is pretty rudimentary but so far seems really reliable in picking out the gear lift.

Again, like others, we're looking to run our vision code on a Raspberry Pi. (We were originally planning to use a Jetson, but that introduced more hurdles.) However, the issue that we have run into is our complete inexperience with NetworkTables. We want to create a custom NetworkTable that contains the data that the RPi needs to communicate to the roboRIO so that it knows how to control the robot (e.g., turn left, go forward at 50% speed, etc.) Our lead programmer and I have spent a bunch of time researching NetworkTables; however, in every example that we've found, it assumes that the NT already exists.

We feel we understand the client side of things. What we need to know is how to create the NetworkTable so that it's there for the client to update.

Any suggestions, advice, or examples would be greatly appreciated.

Do you already have the connection started? If not, use the following code on the client side to start up a connection. I'm going to assume your RPi is in Java for now, but these are all very similar in any other language.

Code:

NetworkTable.setClientMode();
NetworkTable.setTeam(xxxx);
NetworkTable.initialize();

(Replace xxxx with your team number).

From that point, you can call
Code:

NetworkTable table = NetworkTable.getTable("Table_Name_Here");
to get access to any table. You can call this function on both the robot side and the client side, and each will get a reference to the specified table, and you can use the newly created table variable to pass data between the two.

Note that on the robot, NetworkTables is already set up, so you only need to call the getTable function.

jcbaker4050 14-02-2017 13:34

Re: Creating a custom NetworkTable?
 
Quote:

Originally Posted by SamCarlberg (Post 1644819)
Networktables.getTable() will create a new table with that name if it doesn't already exist. Ditto for getSubtable()

That smacking sound that you just heard was me face-palming myself. We spent hours reading literally dozens of articles and threads trying to figure this out, and not once did anywhere ever mention getTable() creating tables. Thanks, Sam, for cluing us in.

Thanks to a post in another thread (https://www.chiefdelphi.com/forums/s...17#post1524417) I also figured out that I didn't have the "Windows/amd64" ntcore library in my NetworkTables.jar. (I'm currently working on my Win7 laptop.) I got that resolved.

I now can successfully write to a NetworkTable and see the new tables and values in Outline Viewer.

This just made my week! Thank you!

virtuald 14-02-2017 13:42

Re: Creating a custom NetworkTable?
 
If you were using python (a lot of teams find OpenCV easier to use in python), the pynetworktables documentation has a lot of examples of various networktables things you can look at: http://robotpy.readthedocs.io/projec.../examples.html

Curiously enough, I hadn't ever thought about the fact that one might think that a 'table' needs to be created. I'll add a note about that to our docs.

jcbaker4050 14-02-2017 14:04

Re: Creating a custom NetworkTable?
 
Quote:

Originally Posted by virtuald (Post 1644877)
If you were using python (a lot of teams find OpenCV easier to use in python), the pynetworktables documentation has a lot of examples of various networktables things you can look at: http://robotpy.readthedocs.io/projec.../examples.html

Curiously enough, I hadn't ever thought about the fact that one might think that a 'table' needs to be created. I'll add a note about that to our docs.

I have noticed that there are far more C++ and Python OpenCV examples and tutorials than for Java, which is where most of our experience currently is. (Well, most of it actually still is in LabVIEW.) Python will be something to think about for future years.

As far as the table creation, I work with databases in my 8-5, so in my mind, a table doesn't exist unless you create it explicitly. Kind of funny how experience can help determine perspectives.

Peter Johnson 14-02-2017 14:35

Re: Creating a custom NetworkTable?
 
Quote:

Originally Posted by jcbaker4050 (Post 1644891)
As far as the table creation, I work with databases in my 8-5, so in my mind, a table doesn't exist unless you create it explicitly. Kind of funny how experience can help determine perspectives.

Tables in NetworkTables are a convention to help organize keys into logical groupings by using "/" as a separator; the actual NetworkTables key namespace is flat. Tables themselves don't really exist (except as an object in your code to keep track of the table path for convenience sake), so it's not actually necessary to create or delete them.

For example, getTable("/").putNumber("foo/bar", 5) and getTable("/foo").putNumber("bar", 5) are exactly equivalent (both set the key "/foo/bar" to 5).

jcbaker4050 14-02-2017 14:40

Re: Creating a custom NetworkTable?
 
Quote:

Originally Posted by Peter Johnson (Post 1644914)
Tables in NetworkTables are a convention to help organize keys into logical groupings by using "/" as a separator; the actual NetworkTables key namespace is flat. Tables themselves don't really exist (except as an object in your code to keep track of the table path for convenience sake), so it's not actually necessary to create or delete them.

For example, getTable("/").putNumber("foo/bar", 5) and getTable("/foo").putNumber("bar", 5) are exactly equivalent (both set the key "/foo/bar" to 5).

Peter, thanks for the additional information. That's a bit different than Oracle database tables, which is what I'm used to. Makes sense, though. And seems easy enough to work with now that I've had my misconceptions cleared up.


All times are GMT -5. The time now is 15:29.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi