|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Talk to rpi from crio
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?
|
|
#2
|
|||
|
|||
|
Re: Talk to rpi from crio
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!
|
|
#3
|
|||
|
|||
|
Re: Talk to rpi from crio
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 (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. |
|
#4
|
||||
|
||||
|
Re: Talk to rpi from crio
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/2013Visi...c/nt_client.py To set values in python: Code:
from nt_client import NetworkTableClient
nt = NetworkTableClient("Team Number")
nt.setValue("key name", data) # Data can be number, string, boolean
Code:
value = nt.getValue("key name")
Code:
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);
Code:
double number = table.getNumber("key name");
boolean bool = table.getBoolean("key name");
String str = table.getString("key name");
|
|
#5
|
||||
|
||||
|
Re: Talk to rpi from crio
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++. |
|
#6
|
||||
|
||||
|
Re: Talk to rpi from crio
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 Java Side: This is the code that actually ran the socket in a separate thread and parsed the data. ThreadedPi.java This is the Subsystem we used to Interface the system: ThreadedberryPi.java |
|
#7
|
||||
|
||||
|
Re: Talk to rpi from crio
So if I want to use the NetworkTable "tableData" in python using https://github.com/Team3574/2013Visi...c/nt_client.py it would be
Code:
client = NetworkTable("tableData")
Code:
NetworkTable table = NetworkTable.getTable("tableData");
|
|
#8
|
||||
|
||||
|
Re: Talk to rpi from crio
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/pynetwork...master/samples Windows binaries: http://firstforge.wpi.edu/sf/frs/do/...ktables.2014_1 |
|
#9
|
||||
|
||||
|
Re: Talk to rpi from crio
Quote:
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. Last edited by sparkytwd : 29-01-2014 at 13:46. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|