Setup Development environment for ROS and OpenCV on Raspberry Pi

Setup Development environment for ROS and OpenCV on Raspberry Pi

TL;DR

In my rover car project, ROS is the framework to communicate among all components, including motors, camera, user input and algorithms. OpenCV is the framework for image processing like lane detection and line following. ROS Indego is the TLS version, which is easy to install with Ubuntu 14.04. ROS Jade is easy to install, too. If you install Ubuntu 15 or later, then you need to build ROS from sources. This article shows how to install ROS Jade.
At the very beginning of this rover project, I wrote my C++ codes in different modules, and run them in different processes. It worked well, however, to handling message passing and scalability, it soon became a lot of hassle, especially when it is a test platform, and you do lots of change everyday. I can make these things in a framework, however, to use existing one got some benefits; it saves your time and your components are easy to share. ROS (Robot Operating System) is the choice. I'll introduce it in my other articles. I choose OpenCV for the same reason, which it has lots of ready-to-use routines for usual image processings, and you can write your algorithms with all supplemental functions.

OpenCV

ROS packages may depend on OpenCV, so it is better to install it first. The easy way is to install it from package depot
sudo apt-get install libopencv-dev

ROS

If you have Ubuntu 14.04 installed, then you can just install ROS from pre-compiled repository by following this link. Here are my steps you can follow
Setup your locale
sudo update-locale LANG=C LANGUAGE=C LC_ALL=C LC_MESSAGES=POSIX
Setup your sources.list
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu trusty main" > /etc/apt/sources.list.d/ros-latest.list'
Setup the keys
wget https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -O - | sudo apt-key add -
Installation, first, make sure package index is up-to-date
sudo apt-get update
Then, get the package you want, this example is to get base packages (ROS packages, build and communication tools.)
sudo apt-get install ros-jade-ros-base
To work with ROS, an initial setup is needed. First, to install and initialize rosdep
sudo apt-get install python-rosdep
sudo rosdep init
rosdep update
Then, setup environment variables
echo "source /opt/ros/jade/setup.bash" >> ~/.bashrc
source ~/.bashrc
If you can not get these pre-compiled packages (you have Ubuntu other than 14.04, or just want to do it from scratch,) then build from sources is another way to get ROS. Here are my steps
Get pip install
sudo apt-get install python-pip
Then, install tools
sudo pip install -U rosdep rosinstall_generator wstool rosinstall
Next is to prepare build environment. ROS use catkin as build system, follow these steps
 
Prepare workspace
mkdir ~/ros_catkin_ws
cd ~/ros_catkin_ws
Get source codes
rosinstall_generator desktop_full --rosdistro jade --deps --wet-only --tar > jade-desktop-full-wet.rosinstall
wstool init -j8 src jade-desktop-full-wet.rosinstall
Then a tricky step is to change your Ubuntu version to vivid (15.04) or trusty (14.04), such that rosdep can get as many dependencies for you, or you have to get them all which is overwhelming. Back up /etc/lsb-release file first. Then edit /etc/lsb-release
sudo vi /etc/lsb-release
Change your content to be (I use 15.04 as example)
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=15.04
DISTRIB_CODENAME=vivid
DISTRIB_DESCRIPTION="Ubuntu 15.04"
Resolve all dependencies
rosdep install --from-paths src --ignore-src --rosdistro jade -y
If this step returns error, that probably means you have to get those dependencies by yourself. If you do experience any error, follow following steps to install all components. And remember to restore /etc/lsb-release.
 
Poco library
Get codes from this link, and extract codes to a folder
Then, build by
cd [Your Poco library folder]
./configure
make
Install Python sip
sudo apt-get install python-sip-dev
Install Google gtest
sudo apt-get install libgtest-dev
Install python-qt4-dev
sudo apt-get install python-qt4-dev
Install lz4
sudo apt-get install liblz4-dev
Install BZip2
sudo apt-get install libbz2-dev
Install yaml-cpp
sudo apt-get install libyaml-cpp-dev
Install qhull
sudo apt-get install libqhull-dev
Install assimp
sudo apt-get install libassimp-dev
Install gazebo
sudo apt-get install libgazebo5*
Install collada dom
get source from sourceforge and follow instructions to build.
Install pcl
sudo apt-get install libpcl1.7*
sudo apt-get install libpcl1.7
sudo apt-get install libpcl-dev
Install flann
visit flann web site to get file and build instructions.
Install ogg
sudo apt-get install libogg-dev
Install fltk
sudo apt-get install libfltk1.3-devv
Install theora
sudo apt-get install libtheora-dev
Then, buid it. It will take a while on Raspberry Pi.
./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release
Above command will build release version of ROS. To set _DCMAKE_BUILD_TYPE=Debug will build ROS with debug information, which is good for debugging.
To allow ROS system to work properly, you have to run a shell script to setup environment variables
source ~/ros_catkin_ws/install_isolated/setup.bash
That's it. Your ROS and OpenCV are ready to serve. Check if your ROS works, try these in a termianl, which starts the master host of ROS.
roscore
And, you can list installed packages in your system by
rospack list
Check out these tutorials to get some ideas of ROS, or check out my other posts. Several ROS packages are ready to use, and are well-tested. Be sure to check them first before you do it, which should save your time, and you can still improve them for its open-source naure. If you want to install more ROS packages, you can find list of ROS package here, get name of the package, then install it by
sudo apt-get install ros-jade-packagename
Be sure to replace all underline of packagename to hyphen '-'. And, this is for jade packages, to install packages fo Indego, replace jade by indeto. For example, to install multimaster_msgs_fkie, your command is
sudo apt-get install ros-jade-multimaster-msgs-fike
For Indego, it is like
sudo apt-get install ros-indego-multimaster-msgs-fike
 
Last modified on Thursday, 04 February 2016 10:50

© Copyright 2007- Yi Systems, Inc. All rights reserved.

5009 Asteria St, Torrance, CA, 90503, U.S.A. | +1-310-561-7237 | requestinfo@yisystems.com