Easy communication between Raspberry Pi and roboRIO

Hello everyone, this is my first post in here so forgive me if I make any mistakes :D.

Last year, in the Turkey 2015 FRC Off-Season, we used OpenCV on a Raspberry Pi to locate the high goal and rotate towards it in autonomous. The RPi code worked wonders, but we had problems getting the roboRIO to communicate with the RPi. As a last minute solution, I wired up an Arduino between the two, so that the Python script on the RPi printed its output to the virtual TTY created by the Arduino, and then I wrote a small script for the Arduino which converted coordinates read from the serial input into 2 digital outputs(0,1 for ‘turn right’, 1,0 for ‘turn left’ and so on) which we hooked up to the roboRIO, which worked but wasn’t the greatest solution ever.

This year, I’d like to use a cleaner solution for this, so I looked into I2C(we had problems with it back then). However, I could only find the WPILib class documentation which is fairly basic and even recommends against the use of the class except internally for sensor classes. I wrote some test code using ReadOnly, but couldn’t get it to work(I currently don’t have access to the code since I’m home, but I’ll try to post it here on Monday). What mainly confused me was that the API wanted a register address, but no such thing is used in to Arduino Wire library. If any team has gotten I2C with Arduino to work on a master reader/slave writer basis, please let me know on how you achieved it.

My question is, are there any resources on how to do very basic communication between a Raspberry Pi and the roboRIO? At the moment, we only require one-way communication(RPi writes, roboRIO reads) but we could use a more versatile solution. I’ve looked into NetworkTables but the resources on how to use it with a roboRIO and another device was even scarcer than I2C.

Oh, and by the way, we use C++ but I posted this on the Programming forum because of how similar WPILib is between languages.

If you’re using a python script for OpenCV, pynetworktables is the way to go. Check out the example program for a coprocessor at https://github.com/robotpy/pynetworktables/blob/master/samples/nt_driverstation.py

Great! I’ll be sure to check that out. Is there anything special I need to do on the RPi such as static IP configuration or will it automatically obtain an IP?

If you use the radio configuration that FIRST recommends, it will hand out IPs. You may try using the device name of your rPI, or you can set static IPs compatible with the DHCP of the robot radio.

Greg McKaskle

We ran a raspberry pi last your to handle lights animation on our robot. We used network tables from Java code for the communication.

For us, it was essential to set a static IP address on the roboRIO.

We had a Python scripts on the raspberry pi sending UDP packets to the roborio; we encoded the data as JSON. If you install Avahi on the rPi, then you can do the IP address lookups by name (both ways).

If you look in our code drop, you can see the roboRIO/Java end of things (reads the UDP packets, decodes the JSON, and puts the result in a global for the rest of the code to act on): http://www.chiefdelphi.com/media/papers/3189.

We didn’t get around to publishing the Raspberry Pi end of things, so I don’t know about the legality of sharing the code post-kickoff, but the libraries to make up a JSON string and do UDP sends are part of Python, and Google will help there.

The NetworkTables solution worked great, now we have bi-directional communication between the roboRIO and the Raspberry Pi. Thanks to the amazing team behind RobotPy and pynetworktables! You guys rock.

I have one question though. Is it viable bandwidth and latency wise to send image data over NetworkTables, or will I have to resort to a traditional HTTP server implementation for that? I’m asking because I’d like to display output from the OpenCV script in SmartDashboard but all the solutions I’ve seen for video streaming from Python use a basic web server implementation and I don’t feel like I’d be able to pull that off without concurrency problems since I’m a novice at Python.

pynetworktables has a latency of up to 50ms, and isn’t designed for streaming data. NetworkTables3 (which pynetworktables does not support) … might have support for that? But, probably not.

The HTTP approach would be best. I might get to something like that later in the season…

We had a crappy non-http server implementation that we prototyped last year. https://github.com/frc1418/2015-vision/tree/master/scratchpad/rio-mjpg

My lead programmer wasn’t sure how to get network tables installed on the Pi. We’re a Java (or in a pinch c++ team) - does anybody have a reference on how to get them there? (or are they there to begin with?)

It really depends on which programming language you’re using on the Pi. We use Python, so all I had to do was run “pip install pynetworktables”.