ROS on RaspberryPi

From JR
Jump to: navigation, search


ROS (Robot Operating System) on Raspberry Pi

8-Mar-2014 - ROS Hydro with rosserial_arduino

This install is based almost exactly on this ROS wiki page (~ Nov 2013) by JonStephan, with only a few details changed.

This install starts with the Raspberry Pi Foundation NOOBS v1.3.4 zip file I downloaded 7 March 2014. Select the Raspian OS for installation. Default values should work for all the installation options.


Building this installation from source took a good fraction of my weekend, but it doesn't have to take your weekend.

I have made a gzipped copy (as described here) of the 16GB SD card I used for this exercise up through the Arduino test. Get the HydroPi.gz file (2.9GB) here.

sha1sum is 3fce7acb04f002fc93d88edeafa2d2d87b65de7a

This image does not automatically source the ROS setup script from .bashrc, so if you want this feature, do

echo "source ~/ros_catkin_ws/install_isolated/setup.bash" >> .bashrc
source .bashrc

That's the shortcut; here's the long way. Start with a fresh Raspian installed from NOOBS, then:

Install dependencies

sudo sh -c 'echo "deb raring main" > /etc/apt/sources.list.d/ros-latest.list'
wget -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-pip
sudo pip install rosdistro
sudo pip install wstool
mkdir ~/Downloads
cd ~/Downloads
tar xvf setuptools-1.1.6.tar.gz
cd setuptools-1.1.6
sudo python install
sudo apt-get install python-stdeb
sudo pip install rosdep
sudo pip install rosinstall-generator
pypi-install rospkg

pypi-install finished with an error "xmlrpclib.ProtocolError: <ProtocolError for 301 Moved Permanently>", but seemed to successfully install rospkg into /usr/local/lib/python2.7/dist-packages. Alternatively, sudo pip install -U rospkg should work. Now continuing the install...

sudo apt-get install python-rosdep python-rosinstall-generator build-essential

ROS Hydro install

This installs the "Bare Bones" (ros_comm) variant. Larger variants (e.g. desktop_full) may tax the resources of the RPi and/or your patience. This process already takes half a day.

sudo rosdep init
rosdep update
mkdir ~/ros_catkin_ws
cd ~/ros_catkin_ws
rosinstall_generator ros_comm --rosdistro hydro --deps --wet-only > hydro-ros_comm-wet.rosinstall
wstool init src hydro-ros_comm-wet.rosinstall
cd src

Based on JonStephan's experience, I immediately removed roslisp to avoid an unmeetable dependency.

wstool rm roslisp
rm -rf roslisp

If you wish to have additional packages in your ros_catkin_ws install, beyond the ros_comm Bare Bones, this would be a good time merge them in, as described below for common_msgs. However, since I didn't do this I am continuing here with the actual sequence I followed.

cd ~/ros_catkin_ws
rosdep install  --from-paths src --ignore-src --rosdistro hydro -y --os=debian:wheezy
./src/catkin/bin/catkin_make_isolated --install
echo "source ~/ros_catkin_ws/install_isolated/setup.bash" >> .bashrc
source .bashrc

At this point there is a functional base installation. Roscore runs, "rostopic list" works.

In order to use the RPi as a rosserial host, however, we will also need the common_msgs package. I discovered this later, so I followed JonStephan's template for adding a package to ros_catkin_ws. (He added turtlesim; I added common_msgs.)

First I had to get the python-rosinstall package which should probably be part of the initial dependencies load above. Then I added common_msgs to the workspace, added the missing rosbag_migration_rules files, and rebuilt:

sudo apt-get install python-rosinstall
cd ~/ros_catkin_ws/src
roslocate info common_msgs | rosws merge -
rosws update
cd ~/ros_catkin_ws/src
git clone
rosdep install  --from-paths src --ignore-src --rosdistro hydro -y --os=debian:wheezy
./src/catkin/bin/catkin_make_isolated --install

Note JonStephan reported needing another manual step for the console_bridge package, but it built automagically for me.

Rosserial install

Start a fresh "working" catkin workspace at ~/catkin_ws and install rosserial into it.

source ~/ros_catkin_ws/install_isolated/setup.bash
sudo apt-get install python-serial
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
cd ~/catkin_ws/src
git clone
cd ~/catkin_ws/
catkin_make install

Note that I installed my own rosserial fork from The official version at should also work fine.

Test rosserial with arduino

Build a sample application from rosserial_arduino and install on an Arduino board. It's easiest to do the Arduino build using a laptop/desktop PC (though it should be possible on the RPi); instructions are here. Here is the program I used on an Arduino Uno, which reads 6 analog channels and reports their values every 100 milliseconds (i.e. at 10 Hz). You can copy and paste it into the Arduino IDE:

 * rosserial ADC Example
 * This is a poor man's Oscilloscope.  It does not have the sampling 
 * rate or accuracy of a commerical scope, but it is great to get
 * an analog value into ROS in a pinch.

#include <ros.h>
#include <rosserial_arduino/Adc.h>
#include <std_msgs/UInt16.h>

ros::NodeHandle nh;

rosserial_arduino::Adc adc_msg;
ros::Publisher p("badboy", &adc_msg);

uint32_t reportIntervalMs = 100;

void messageCb( const std_msgs::UInt16& msg){
  reportIntervalMs =;

ros::Subscriber<std_msgs::UInt16> sub("report_interval", messageCb );

uint32_t next_report_time;

void setup()
  pinMode(13, OUTPUT);
  next_report_time = millis();

//We average the analog reading to elminate some of the noise
int averageAnalog(int pin){
  int v=0;
  for(int i=0; i<4; i++) v+= analogRead(pin);
  return v;

void loop()
  if ((int32_t)(millis()-next_report_time) > 0) {
    next_report_time += reportIntervalMs;
    adc_msg.adc0 = averageAnalog(0);
    adc_msg.adc1 = averageAnalog(1);
    adc_msg.adc2 = averageAnalog(2);
    adc_msg.adc3 = averageAnalog(3);
    adc_msg.adc4 = averageAnalog(4);
    adc_msg.adc5 = averageAnalog(5);

Connect the Arduino to the RPi's USB port.

cd ~/catkin_ws/
source install/
roscore &
rosrun rosserial_python /dev/ttyACM0 &
rostopic echo /badboy

Here it is talking to an Ubuntu PC (thru a few ssh terminals and the ROS Hydro visualization application rqt). I have increased the report rate from 10 Hz to 50 Hz by sending a message on topic /report_interval. The CPU usage on the RPi is noticeably less than in the previous Fuerte test (see below). Here is a screenshot of the PC: RosserialHydro.png

Note that rqt is part of the desktop Hydro installation; you can't get this graphical display on the RPi alone without installing a lot more packages on it.

rosbridge to the web

The rosbridge_suite provides a JSON interface to ROS for web-based apps. I want to learn about this so I looked at this page and installed

cd ~/catkin_ws/src
git clone -b hydro-devel
git clone

It seems some entries are missing in the rosbridge_server CMakelists.txt, so

 nano ~/catkin_ws/src/rosbridge_suite/rosbridge_server/CMakeLists.txt

Expand the install(PROGRAMS block with two "" artifacts so it reads


Make and install

cd ~/catkin_ws/
catkin_make install
source ~/catkin_ws/install/

Now start the webservice with

roslaunch rosbridge_server rosbridge_websocket.launch

The next step is running the Beginner's Tutorial, but so far I am getting a "TypeError: values is not an object roslib.js:633" from Firefox' javascript engine when loading the included Work in progress...

ROS Fuerte (historical)

Someone else's tutorial here.

I started to play with ROS, Raspberry Pi, and Arduino.

Also putting Rosserial on Arduino Due (ARM3 board). Maybe on PSoC4 (ARM0 board).

10-Sep-2012 Webcam on RPi

Webcam on Raspberry Pi!


Camera is Logitech C310 running about 30fps at QVGA (320x240). This camera does run up to 1280x960, but RPi with guvcview will only handle a few frames per second at that size. Perhaps the processor is working pretty hard decompressing the camera's MJpeg video stream to the console display.

Although I was running a debian wheezy build, it still required updating the RPi software to get USB video working:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo wget -O /usr/bin/rpi-update
sudo chmod +x /usr/bin/rpi-update
sudo rpi-update
sudo reboot

About rpi-update here. The sync command before reboot may be important to avoid corrupting the SD card boot partition.

My ros/fuerte is only a partial install, and does not include OpenCV...yet.

5-Sep-2012 Rosserial-arduino on RPi

An interim report on the Raspberry Pi as ROS communications controller:

I have three devices connected together

1. Arduino nano, running a small program which collects data from 6 A/D channels at 50Hz and reports it using rosserial protocol to...

2. Raspberry Pi, running debian/wheezy and ros/fuerte. I installed the rosserial_arduino package and its dependencies (with a few hitches). One process,, handles the host side of the rosserial protocol and participates as a full ros node on the network, publishing the stream of measurements. The RPi is running an XDE desktop at 1920x1080, but I don't have any graphical apps open right now.

3. An ordinary desktop box, running ubuntu 12.04 and ros/fuerte, connected to the Raspberry Pi over an ethernet LAN. On the desktop I ran rxplot (a graphical realtime "strip chart" app) to visualize the data from a sine/square oscillator feeding two of the Arduino input channels. I also SSH'd into the RPi and ran top for a view of resource usage.

The result is shown in the several windows of the attached screenshot from the desktop machine.


The performance is not stunning. From the sinewave, I'd say timing jitter looks to reach 40 or 50 millisec peak (although it is usually much less). This single task takes up an awful lot of the RPi processor; top shows only 25% idle time in this snapshot. The python process running is hogging most of the cycles.


I finally succeeded in installing the ros fuerte image from ROS Fuerte Raspbian Image on the 8GB SD card using my Windows XP laptop. The problem last night was that Win32DiskImager is not very compatible with laptop built-in SD card readers (bug), so I used the flashnul technique described here: Copying the image to an SD Card on Windows if first option isn't successful

Personal tools

Puzzle Pieces
Wiki tools
Operations plan
For staff