Disclaimer: I have only been programming for a little over a year, so I am still somewhat of an amateur.
My team is thinking of using our driver station to do image processing and sending data to and from the robot. I did some digging around and learned about WPILib’s NetworkTable, and I heard about how simple it is to use. However, I’m having some trouble finding sufficient documentation to learn how to use NetworkTable. This is the only thing I could find:
However, the most crucial part of the documentation (“The client (laptop) side of the program”) is written in Java, which I have been unable to successfully translate into C++. Do any of you know where I could find similar documentation on NetworkTable, specifically for C++? If not, could anyone sort of summarize how it should be used and provide examples in C++? Thank you!
We only supplied a Java desktop version of NetworkTables. Is it possible that you can use that for your application? The problem was that the Windows networking was different enough from our linux test version that it made it difficult to port.
In that case, are there any C++ based alternatives that you could suggest similar to NetworkTables that can easily send data to and from the robot? I would rather avoid using Java if at all possible, because none of the mentors on my team are familiar with that language.
I wouldn’t mind teaching myself some network socket programming if need be. If you could direct me to documentation of any kind relating to communicating between the robot and the driver station, that would be great. Thanks for the response!
We have recently made good progress in building a prototype interface between C++ and the networktables-desktop.jar java library on the drive laptop Windows platform by using JNI (Java Native Interface).
It’s a little subtle, though.
Basically, the plan is:
-create a JVM instance with its class path pointing at the networktables-desktop.jar
-find and call the appropriate Java methods
If using Visual Studio 2010 C++, which is what we are doing, one has to take some care that the system PATH environment variable is set correctly for the JRE (Java Runtime), etc.
If there is interest, I may be able to post very rough but working code samples via GitHub.
I look forward to responses.
(one of many)
Mentor(s) to FRC team 3045 - SWAT - San Mateo, CA
PS - where is the original NetworkTables java code kept - in GitHub? The WPI FirstForge code doesn’t seem to be the most current.
(and other interested parties):
Here is a kludgy first pass:
to test it out without a robot, run TableViewer in server mode on, say, the local host. Let’s say that localhost’s IP address is 184.108.40.206. Change the IP address in the code to “220.127.116.11”. (and the PATH environment variable needs to be right, and this code assumes that networktables-desktop.jar is at C:\Windriver\WPILib\desktop-lib) The JDK and/or the JRE needs to be installed already. I suspect that I have left some dangling references in, which may be why the destroyJVM call had to be commented out.
This is NOT a complete interface to NetworkTables; additional methods can be added. I’ll try to post the method signatures for the whole NetworkTables as an additional commit later.
Please let me know if you have any questions.
I’m guessing everyone here that has posted here has already considered / tried this already, but why not just use TCP / UDP? My team has tried sending data from computer to computer with success, and there’s a lot of documented instances of teams using either protocol to send information to and from the cRIO (most of what I’ve seen have been in regards to sending stills gathered from vision processing to the DS). What we’ve tried hasn’t been particularly difficult, but we have yet to try to integrate with the cRIO…
I don’t think it’s practical, but I based on what I’ve seen in the NetworkTables code in WPIlib, it appears that VxWorks uses the Berkeley (BSD)/POSIX sockets API (so most Linux / Unix socket code should function). If I’m wrong about that, I’m sure that this thread has sufficient information on how to do it (just skip past all the pessimism in the first few posts)
The operating system supports TCP/IP via the Berkeley socket interface. Support via the WPI and/or NI libraries is unnecessary. Most Linux networking example code on the net will run with few or no changes on the robot (in C or C++).
The pynetworktables project provides bindings to NetworkTables in python. They have been tested on Linux, Windows, and OSX.
The python bindings are based on the C++ WPILib source releases. Some changes have been made to support building on other platforms, like windows. You can find the fixed version of WPILib (which includes NetworkTables) on github, you should be able to build it on Windows without any problems if you create a usable build environment for it. Note that you will need your own implementations of some of the WPILib/vxWorks components to build it – the components that pynetworktables uses is found here.
Correct. The python stuff is just a wrapper around the C++ implementation
More importantly to note, the C++ implementation is the same implementation that the robot is running (e.g., that’s why the repository is called WPILib), with some minimal changes to make it work on Windows/Linux. So ideally, the code should work as well as the code that’s running on the robot.