Log in

View Full Version : Talk to rpi from crio


Merfoo
24-01-2014, 22:35
Hello, so we're using opencv python on the raspberry pi this year for vision process and we're wondering how we get/send data like booleans, doubles, ints, strings to the pi from the crio in java. I've seen posts talking about i2c and udp but they dont talk how to do it/show code examples. Are there any examples to help us get started?

daniel_dsouza
25-01-2014, 00:04
i am working on pretty much the same idea. I don't have any code yet, as my past week has been spent dealing with team administration issues, but if you don't have something by the time I have finished mine, I would be happy to share what I will write with you!

bijan311
25-01-2014, 00:28
I'm not sure how much this will help you because it is written in C++ and not java, but my team has successfully created a camera tracking program on the raspberry pi that sends the data to the CRio via udp packets. The code can be found here (https://github.com/robotics1714/2014-Code) (the code used on the raspberry pi is in the raspberry pi folder and the rest is robot code).

To send the integer values to the CRio, we just used a some if statements to convert them to strings, and when receiving the data we converted them back into integers.

I hope this helps. If you have any more questions I will try to respond to them as soon as possible.

amreuland
27-01-2014, 11:34
Since you are using python, you can use a NetTables implementation.
I found that Team 3574's try at it is pretty good.
https://github.com/Team3574/2013VisionCode/blob/master/src/nt_client.py

To set values in python:
from nt_client import NetworkTableClient

nt = NetworkTableClient("Team Number")
nt.setValue("key name", data) # Data can be number, string, boolean

To get values in python:
value = nt.getValue("key name")

To get the value in java:
import edu.wpi.first.wpilibj.networktables.NetworkTable;

NetworkTable table = NetworkTable.getTable("Table Name");
table.putNumber("key name", double);
table.putBoolean("key name", boolean);
table.putString("key name", String);

To set values:
double number = table.getNumber("key name");
boolean bool = table.getBoolean("key name");
String str = table.getString("key name");

gluxon
27-01-2014, 12:45
My question is, Why would you need to? For most vision processing configurations, the Raspberry Pi would talk directly with the camera, then send data to the cRIO one-way.

If you must go the other way, I would recommend the NetworkTables as well. Otherwise, a simple udp server and client should do it for C++.

gixxy
27-01-2014, 14:59
Last year Team 3946 used a network Socket Connection to talk between the crio and rpi.

Basically we had a Socket Server running in Python on the RPI and a Socket Client in Java on the cRIO.

Here is the code we used:

Python Side:
PyGoalFinder (https://github.com/frc3946/PyGoalFinder)

Java Side:

This is the code that actually ran the socket in a separate thread and parsed the data.
ThreadedPi.java (https://github.com/frc3946/UltimateAscent/blob/master/src/org/usfirst/frc3946/UltimateAscent/ThreadedPi.java)

This is the Subsystem we used to Interface the system:
ThreadedberryPi.java (https://github.com/frc3946/UltimateAscent/blob/master/src/org/usfirst/frc3946/UltimateAscent/subsystems/ThreadedberryPi.java)

Merfoo
29-01-2014, 00:41
So if I want to use the NetworkTable "tableData" in python using https://github.com/Team3574/2013Visi...c/nt_client.py it would be
client = NetworkTable("tableData")
and in java it would be
NetworkTable table = NetworkTable.getTable("tableData");
?

virtuald
29-01-2014, 01:16
I would recommend using pynetworktables. It's a cross-platform python wrapper (so everything in NetworkTables is implemented) around the official WPILib implementation of NetworkTables, and has sample code that comes with it.

Github site: https://github.com/robotpy/pynetworktables
Samples: https://github.com/robotpy/pynetworktables/tree/master/samples
Windows binaries: http://firstforge.wpi.edu/sf/frs/do/viewRelease/projects.robotpy/frs.pynetworktables.2014_1

sparkytwd
29-01-2014, 13:05
So if I want to use the NetworkTable "tableData" in python using https://github.com/Team3574/2013Visi...c/nt_client.py it would be
client = NetworkTable("tableData")
and in java it would be
NetworkTable table = NetworkTable.getTable("tableData");
?

For python it would be

client = NetworkTableClient("955")

You can run nt_client.py from the command line like so:

python nt_client.py 955 and it will set some test values for you.