Send data from raspberry pi to roboRIO using c++

Hello, we are working on a raspberry pi and trying to get vision working on it. We already have c++ code that works, we just need to transfer the data from the raspberry pi to the roboRIO over networks tables. Ive seen the python network tables, however, we would prefer not porting our vision code to python because we do not have that much experience with python.

Any options?

What you want is probably the network tables located here. You will need to make a teamforge account to do a git clone and download the source, but I believe this is exactly what you will need.

Alright thanks!

Near identical thread:

Essentially, the code is also on github ( and you should be able to use cmake and gcc 4.8+ to build it.

Hello, I have successfully built and installed the NetworkTables on the raspberry pi. However, I am having trouble getting it integrated with my vision program.

I am a bit of a newbie when it comes to linux, compilers, and stuff like that. I don’t really know what to include in program. Right now I have

#include <ntcore/ntcore_cpp.h>

but it says it cannot find it. Also, when I am compiling the code I use this command

g++ -std=c++0x -lntcore vision2.cpp -o vision2 ‘pkg-config --cflags --libs opencv’

It does not work because it cannot file the include.

Also, I cant seem to find any documentation on how to use NetworkTables to send information from the server side. I have looked through the source code but that doesn’t help me that much.

Any help is appreciated!


You need to add -I<path to ntcore/include directory> to the g++ command line, and the include line should just be #include <ntcore.h> (which will bring in both ntcore_c.h and ntcore_cpp.h).

Even better, if you #include <networktables/NetworkTable.h>, you’ll get the same classes/functions you use on the robot program, so e.g. you can call NetworkTable::GetTable() et al. The only difference between this and your robot program is you’ll need to run NetworkTables as a client rather than as the server, so first call NetworkTable::SetTeam() and then NetworkTable::SetClientMode() prior to calling NetworkTable::GetTable().

Thanks! I’ll try this when I get to robotics today!

I tried adding the -I<ntcore/include> file but I am still getting an error:

/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/crtl.o: In function `_start': /build/glibc-H706YU/glibc-2.19/csu/../ports/sysdeps/arm/start.S:119: undefined reference to main `main' collect2: error: ld returned 1 exit status

this is what I used to compile:

g++ -std=c++0x -I<ntcore/include> -lntcore vision.cpp -o test_colour pkg-config --cflags --libs opencv

We think the reason is because it cannot find a main function even though we have a main function in vision.cpp

EDIT: when we added the library path, we forgot to source it to make the program see the lib path.

Thanks for your help!

To be clear, I didn’t literally mean “-I<ntcore/include>” but rather the location where the ntcore/include directory is, e.g. -I/home/something/ntcore/include. Also it may have trouble finding -lntcore without a -L/home/something/ntcore/build/…

Yep. Thank you for the help.

Alright, I got the code to compile and I am trying to send the actual data now. However, I am not getting any values in the outline viewer. Here is my setup:

  • Raspberry pi hooked up through ethernet to router which is also connected to roborio.

  • Here is my code on the robot side:


static std::shared_ptr<NetworkTable> table;
table = NetworkTable::GetTable("vision");


distanceToCenter = Robot::table->GetNumber("center", 0.0);

  • On the raspberry pi side

std::shared_ptr<NetworkTable> visionTable;
visionTable = NetworkTable::GetTable("vision");
visionTable->PutNumber("center", distanceCenter);

I’m not sure if I am doing this correctly. I’m not getting any errors but I’m not getting any values either.

  • Drew

Your robot needs to be the server. There’s actually code in some of the top-level classes which preconfigures it to be a server before it enters your code, and that’s what the driver station dashboards etc assume. The raspberry pi should be set up as the client. So you should move the


lines to your raspberry pi, changing the IP address to the robot IP (or robot name, e.g. “roborio-2053-frc.local”). Using NetworkTable::SetTeam(2053) should do the latter for you.

Alright, now I’m getting the error:

NT: ERROR: select() to roboRIO-2053-frc.local
port 1735 error 111 - Connection refused (TCPConnector.cpp:157)

Do you have robot code running with the SetClientMode lines removed? You will get this error on the client (it should retry about once a second) until the robot code is running and thus the NetworkTable server is running.

Yep. I removed them. All I have is:
std::shared_ptr<NetworkTable> visionTable;
visionTable = NetworkTable::GetTable(“vision”);

Alright, I think the issue is the hostname. Right now when I use IPAddress with the ip of roborio ( it works, but not with SetTeam();

This is very strange.