As a lover of technology, I tend to accumulate bits and pieces of interesting devices. Usually, these are purchased for use on unrelated projects, and on occasion, I have the opportunity to bring them together into a single project in a previously unanticipated way. Such is the case with my Arduino and Raspberry Pi. Both are interesting microcomputers with their own strengths and weaknesses, so it was when I learned that they could be made to work together with the help of Robot Operating System, I had to give it a shot.
ROS is an open-sourced project that is dedicated to providing a framework of libraries for performing common tasks under the general heading of robotics. It also includes drivers that allow you to easily interface with common hardware. The core of ROS is a reactor model of observables and observers that send messages to one another, typically over a serial connection, allowing any number of controllers to interface with one another and form a unified whole.
rosserial_arduino library is a project that allows ROS on a Raspberry Pi (or other *nix device) to interface with an Arduino over a USB serial connection, thereby combining the computing power and versatility of a Linux-based microcomputer with the IO capabilities of an Arduino.
What You’ll Need to Get Started
Installing Raspbian on the Pi
If your Pi already has an operating system on it, you can probably skip this step. If, however, it’s straight out of the box, you’ll need to install the Raspbian distribution.
As of this writing, the latest version of Raspbian is Jesse, released in September of 2015. I wasn’t able to get ROS working with this version, and backed down to the Wheezy release from May of 2015 instead. To install the operating system, I did the following:
- Download the Raspbian Wheezy image via a bittorrent client.
- When the download is complete, follow these instructions to copy the image file to your MicroSD card.
- Unmount the card, insert it into your Pi, and hook up the power. Your device should boot into a command prompt. From here, you can run
raspi-config to customize the installation, or get right to installing ROS.
Once the installation is complete, be sure to check for updates:
pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get upgrade
An up to date system is a safe system.
Once your Pi has an operating system, you can switch to interacting with it via SSH. My TV is the only “monitor” in my house that has an HDMI input on it, so SSH works much better for me.
Make sure that
sshd is running on your Pi:
pi@raspberrypi ~ $ sudo service sshd status
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled)
Active: active (running) since Thu 2015-10-08 12:17:06 UTC; 4 days ago
Main PID: 506 (sshd)
└─506 /usr/sbin/sshd -D
If everything is working, you should see the text
active (running) in the result. Once we know that an ssh server is running, we can check our ip address with the
ifconfig command. The output should look something like this:
pi@raspberrypi ~ $ ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:b9:49:cd
inet addr:192.168.0.109 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5150 errors:0 dropped:51 overruns:0 frame:0
TX packets:565 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:552488 (539.5 KiB) TX bytes:60766 (59.3 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:1104 (1.0 KiB) TX bytes:1104 (1.0 KiB)
If your Pi is connected to a LAN cable, you’ll want to look at the
eth0 section. If it’s connected to WiFi, look for a
wlan0 section. Both sections should have an
inet addr field whose value starts with a
192.168.x.x address. In my case, it’s
192.168.0.109. From a terminal on my computer, I can connect with:
jfritz@IDEAPAD-UBUNTU:~$ ssh email@example.com
When prompted to accept the Pi’s RSA key, I do, and when prompted for a password, I enter the default password
raspberry. If you intend to leave the Pi connected to your network for long periods of time, you should change this password or add key-based authentication to the system.
If you have problems getting connected, check out the official instructions on the Raspberry Pi website.
Installing ROS on the Pi
As of this writing, the most recent version of ROS is Indigo, released in July of 2014. To get it running on the Pi, you’ll want to follow the official ROSberryPi installation instructions on the ROS website.
While following these instructions, I had a few false starts. It’s important to read the instructions carefully, as they’re fairly generic, and can be used to install different configurations of ROS on different versions of Raspbian. I found that the instructions for the
ros_conn configuration worked best on Raspbian’s Wheezy release.
The trickiest part of the instructions is section 2.2 Resolve Dependencies. It took me a couple of reads to realize that if you’re installing ROS Indigo’s
ros_conn configuration on Raspbian Wheezy, you only need to compile two packages from source:
liblz4-dev. Installing any other packages at this step just costs you time, and may introduce problems down the road.
I also found that the install process went much smoother when the Pi was connected to a LAN rather than WiFi. The WiFi signal in my house is relatively weak, and the Realtek #814B is really cheap, so downloading a lot of files while maintaining an SSH connection is a big ask.
Once the installation is complete, open up your
~/.bashrc file, and add two lines to the end:
# export ROS environment variables
This will make sure that the appropriate environment variables are set to interact with ROS on every startup. You can check that it worked by rebooting your Pi and running
pi@raspberrypi ~ $ printenv | grep ROS
If you see all of the ROS_* environment variables print out, then everything is set up and ready to go. Now it’s time to start on some tutorials.
Eventually, I want to get the Raspberry Pi communicating with the Arduino, and use the latter as a sensor platform and motor controller for some kind of a robot. For now, I need to find my way around ROS.