Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Send data from raspberry pi to roboRIO using c++ (http://www.chiefdelphi.com/forums/showthread.php?t=145382)

jreneew2 07-03-2016 21:21

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?
Drew

snekiam 07-03-2016 22:33

Re: Send data from raspberry pi to roboRIO using c++
 
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.

jreneew2 07-03-2016 22:34

Re: Send data from raspberry pi to roboRIO using c++
 
Alright thanks!

Peter Johnson 08-03-2016 02:01

Re: Send data from raspberry pi to roboRIO using c++
 
Near identical thread: http://www.chiefdelphi.com/forums/sh...d.php?t=144496

Essentially, the code is also on github (https://github.com/PeterJohnson/ntcore) and you should be able to use cmake and gcc 4.8+ to build it.

jreneew2 18-03-2016 18:30

Re: Send data from raspberry pi to roboRIO using c++
 
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!

-Drew

Peter Johnson 19-03-2016 01:19

Re: Send data from raspberry pi to roboRIO using c++
 
Quote:

Originally Posted by jreneew2 (Post 1559527)
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.

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().

jreneew2 19-03-2016 06:23

Re: Send data from raspberry pi to roboRIO using c++
 
Thanks! I'll try this when I get to robotics today!

jreneew2 19-03-2016 11:51

Re: Send data from raspberry pi to roboRIO using c++
 
I tried adding the -I<ntcore/include> file but I am still getting an error:

Code:

/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!

Peter Johnson 20-03-2016 02:11

Re: Send data from raspberry pi to roboRIO using c++
 
Quote:

Originally Posted by jreneew2 (Post 1559676)
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`

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/...

jreneew2 20-03-2016 10:31

Re: Send data from raspberry pi to roboRIO using c++
 
Yep. Thank you for the help.

jreneew2 21-03-2016 11:58

Re: Send data from raspberry pi to roboRIO using c++
 
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:

Robot.cpp
Code:

static std::shared_ptr<NetworkTable> table;
NetworkTable::SetIPAddress("10.20.53.21");
NetworkTable::SetClientMode();
NetworkTable::Initialize();
table = NetworkTable::GetTable("vision");

GoalAlign.cpp
Code:

distanceToCenter = Robot::table->GetNumber("center", 0.0);
- On the raspberry pi side
Code:

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

Peter Johnson 21-03-2016 12:20

Re: Send data from raspberry pi to roboRIO using c++
 
Quote:

Originally Posted by jreneew2 (Post 1560446)
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:

Robot.cpp
Code:

static std::shared_ptr<NetworkTable> table;
NetworkTable::SetIPAddress("10.20.53.21");
NetworkTable::SetClientMode();
NetworkTable::Initialize();
table = NetworkTable::GetTable("vision");

GoalAlign.cpp
Code:

distanceToCenter = Robot::table->GetNumber("center", 0.0);
- On the raspberry pi side
Code:

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.

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
Code:

NetworkTable::SetIPAddress("10.20.53.21");
NetworkTable::SetClientMode();
NetworkTable::Initialize();

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.

jreneew2 21-03-2016 13:04

Re: Send data from raspberry pi to roboRIO using c++
 
Alright, now I'm getting the error:

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

Peter Johnson 21-03-2016 13:09

Re: Send data from raspberry pi to roboRIO using c++
 
Quote:

Originally Posted by jreneew2 (Post 1560486)
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.

jreneew2 21-03-2016 13:13

Re: Send data from raspberry pi to roboRIO using c++
 
Yep. I removed them. All I have is:
std::shared_ptr<NetworkTable> visionTable;
visionTable = NetworkTable::GetTable("vision");

jreneew2 21-03-2016 13:42

Re: Send data from raspberry pi to roboRIO using c++
 
Alright, I think the issue is the hostname. Right now when I use IPAddress with the ip of roborio (10.20.53.20) it works, but not with SetTeam();

This is very strange.


All times are GMT -5. The time now is 20:04.

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