Go to Post Our coolant system consists of a freshman with a squirt bottle. - Holtzman [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 17-01-2016, 04:54
cantdecide cantdecide is offline
Registered User
FRC #5773 (YAFL Mechatronics)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2016
Location: Turkey
Posts: 31
cantdecide is an unknown quantity at this point
Easy communication between Raspberry Pi and roboRIO

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

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.
  #2   Spotlight this post!  
Unread 17-01-2016, 08:00
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,067
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Easy communication between Raspberry Pi and roboRIO

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/pynetwork...iverstation.py
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
  #3   Spotlight this post!  
Unread 17-01-2016, 08:10
cantdecide cantdecide is offline
Registered User
FRC #5773 (YAFL Mechatronics)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2016
Location: Turkey
Posts: 31
cantdecide is an unknown quantity at this point
Re: Easy communication between Raspberry Pi and roboRIO

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?
  #4   Spotlight this post!  
Unread 17-01-2016, 08:16
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,752
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Easy communication between Raspberry Pi and roboRIO

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
  #5   Spotlight this post!  
Unread 17-01-2016, 16:51
krieck's Avatar
krieck krieck is offline
Registered User
AKA: Keith
FRC #2846 (Firebears)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Minnesota
Posts: 49
krieck is an unknown quantity at this point
Re: Easy communication between Raspberry Pi and roboRIO

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.
  #6   Spotlight this post!  
Unread 18-01-2016, 12:46
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 332
fovea1959 will become famous soon enough
Re: Easy communication between Raspberry Pi and 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.
  #7   Spotlight this post!  
Unread 19-01-2016, 16:39
cantdecide cantdecide is offline
Registered User
FRC #5773 (YAFL Mechatronics)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2016
Location: Turkey
Posts: 31
cantdecide is an unknown quantity at this point
Re: Easy communication between Raspberry Pi and roboRIO

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.
  #8   Spotlight this post!  
Unread 19-01-2016, 18:01
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,067
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Easy communication between Raspberry Pi and roboRIO

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-visi...chpad/rio-mjpg
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
  #9   Spotlight this post!  
Unread 01-02-2016, 14:49
riftware riftware is offline
Parent Mentor
AKA: Andrew Chandler
FRC #0031
Team Role: Mentor
 
Join Date: Dec 2013
Rookie Year: 2011
Location: Tulsa
Posts: 27
riftware is an unknown quantity at this point
Re: Easy communication between Raspberry Pi and roboRIO

Quote:
Originally Posted by cantdecide View Post
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.
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?)

- Update - I found another thread that seems to show how to do it:
http://www.chiefdelphi.com/forums/sh....php?p=1525831 I'll try it tonight and update this post tomorrow.

Last edited by riftware : 01-02-2016 at 14:57. Reason: New Info
  #10   Spotlight this post!  
Unread 05-02-2016, 12:32
cantdecide cantdecide is offline
Registered User
FRC #5773 (YAFL Mechatronics)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2016
Location: Turkey
Posts: 31
cantdecide is an unknown quantity at this point
Re: Easy communication between Raspberry Pi and roboRIO

Quote:
Originally Posted by riftware View Post
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?)

- Update - I found another thread that seems to show how to do it:
http://www.chiefdelphi.com/forums/sh....php?p=1525831 I'll try it tonight and update this post tomorrow.
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".
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:53.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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