Tutorial: Part 3 – Gumstix on the iRobot Create 2

July 6, 2015 | William Phan

In part three of the series, we’ll create a custom Yocto Project image to deploy on gumstix to control the iRobot Create 2.

Catch up on any tutorials you’ve missed:

Tutorial 1
Tutorial 2
Tutorial 3 (You are here)
Tutorial 4
Tutorial 5

You can download the source files for the project here.

Problems with the gscam Package on meta-ros

meta-ros is an OpenEmbedded Linux layer that provides a stable cross-compilation build system for many popular ROS packages. We will be baking this layer into our Yocto Project build later, but you may first be interested in some problems encountered while trying to get a live video feed from a webcam attached to a target system. See this discussion on the meta-ros mailing list for details.

The mentioned fixes have been implemented and will be pointed out later when we write the bitbake recipe.

1 Preparing the Yocto Build Environment (on Host)

We will be running an image built with the Yocto Project on our target COM. Please follow steps 1-4 in this excellent tutorial written by Adam Lee for setting up the Yocto Project build environment.

Once you’ve reached step 5, “Build an image,” return here as we will need to make some modifications to install the necessary packages before building the image. Be sure to pick the dev branch when initializing the repo client.

2 Preparing the Bitbake Recipes

You may find the Yocto Project BitBake Recipe Manual helpful for this section.

A bitbake recipe tells the build system where to get the source files from a particular package from, where to build the package, patch files to apply if there are any, and if there are any build or runtime dependencies.

2.1 Writing a Bitbake Recipe

Note: this is included in the tarball of source files

First we will create a bitbake recipe for the irobotcreate2 package mentioned above that you either cloned or created. We will be placing this under the meta-gumstix-extras layer.

Move to the meta-gumstix-extras layer and create the bitbake recipe using your favourite text editor (vim, gedit, nano etc…):

$ cd .../yocto/poky/meta-gumstix-extras/recipes-ros
$ mkdir irobotcreate2 && cd irobotcreate2
$ vim irobotcreate2_0.0.1.bb

Paste the contents of the irobotcreate2 bitbake recipe:

1 DESCRIPTION = "iRobot Create2 Driver Package"
2 SECTION = "devel"
3 LICENSE = "BSD"
4 LIC_FILES_CHKSUM = "file://package.xml;beginline=9;endline=9;md5=8acbd5f3893ce074720cec0584d189fd"
5
6 DEPENDS = "rospy roscpp catkin"
7 RDEPENDS_${PN} = "rospy roscpp python-pyserial gscam"
8
9 EXTERNALSRC = "/home/%USERNAME%/catkin_ws/src/irobotcreate2/"
10 EXTERNALSRC_BUILD = "/home/%USERNAME%/catkin_ws/build/"
11
12 S = "/home/%USERNAME%/catkin_ws/src/irobotcreate2/"
13
14 inherit catkin

You will need to change EXTENRALSRC, EXTERNALSRC_BUILD and S to reflect your source and build directories.

2.2 Modifying a bitbake Recipe

Now we will edit gumstix-console-image.bb to include the necessary packages, Yocto refers to this recipe when building our specific image:

$ vim .../yocto/poky/meta-gumstix-extras/recipes-images/gumstix/gumstix-console-image.bb

Edit the UTILITIES_INSTALL variable to contain the following packages necessary for meta-ros and our irobotcreate2 package:

UTILITIES_INSTALL = " \
coreutils \
camera-info-manager-py \
diffutils \
findutils \
git \
git-perltools \
gpsd \
grep \
joy \
gzip \
less \
nano \
packagegroup-cli-tools \
packagegroup-cli-tools-debug \
packagegroup-ros-comm \
python-distutils \
python-email \
python-rosinstall \
python-pyserial \
python-wstool \
irobotcreate2 \
sudo \
std-msgs \
message-generation \
message-runtime \
tar \
vim \
wget \
zip \
"

Add the following GSCAM_INSTALL variable under the UTILITIES_INSTALL variable:

GSCAM_INSTALL = " \
gscam \
nodelet \
cv-bridge \
roscpp \
theora-image-transport \
sensor-msgs \
camera-calibration-parsers \
camera-info-manager \
gst-plugins-good-video4linux2 \
gst-plugins-base-app \
"

Note: If you read the discussion on the meta-ros mailing list about my problems with gscam (linked above), you will notice that I used smart update and smart install gst-plugins-good-video4linux2 to install V4L2 and base-app plugins. This was done on the COM after baking the image. Putting these entries directly in the bitbake recipe will create an image with these packages already installed! This will save us a considerable amount of time since we don’t have to wait for smart update to run.

Next we add our new GSCAM_INSTALL variable to IMAGE_INSTALL to get:

IMAGE_INSTALL += " \
${FIRMWARE_INSTALL} \
${SYSTEM_TOOLS_INSTALL} \
${DEV_TOOLS_INSTALL} \
${NETWORK_TOOLS_INSTALL} \
${MEDIA_TOOLS_INSTALL} \
${GRAPHICS_LIBS} \
${UTILITIES_INSTALL} \
${GSCAM_INSTALL} \
"

Finally lets patch the v4l.launch file in gscam to work with JPEG webcams.

cd to the gscam bitbake recipe under the meta-ros layer:

$ cd .../yocto/poky/meta-ros/recipes-ros/gscam/gscam

Move the provided patch file (included in the source tarball) to this directory:

$ sudo mv .../v4l_jpeg_webcam.patch ./

Next, edit the gscam recipe to include this new patch:

$ vim ../gscam_0.1.3.bb

You only need to do the following to include our new patch:

13 SRC_URI += "file://0001-gscam_nodelet.h-include-scoped_ptr.hpp-to-compile-wi.patch \
14 file://v4l_jpeg_webcam.patch"

That’s it for preparing recipes, next we’ll bake the image and put it on the microSD card for our COM.

3 Bitbaking the Image

Now we will bake a console image following the recipes we prepared above.

Move to your Yocto Project build environment and initialize the environment:

$ cd .../yocto
$ export TEMPLATECONF=meta-gumstix-extras/conf
$ source poky/oe-init-build-env

You should be automatically put into the build/ directory, now we edit local.conf to tell Yocto what board we’re building the image for:

$ vim conf/local.conf

You will need to go to around line 70 and uncomment the target you are building for (in this case pepper):

69 # This sets the default machine to be overo if no other machine is selected:
70 #MACHINE ?= “overo”
71 MACHINE ?= “pepper”
72 #MACHINE ?= “duovero”

Now run let’s bake an image! (make sure you have at least 25GB of free space on your host for this process)

If this is your first time bitbaking, it can take several hours, depending on the speed of your machine and your internet connection.

$ bitbake gumstix-console-image

Note: If the bitbake process throws a MD5(or SHA256) checksum error, and provides you with a new MD5 (or SHA256) sum, copy that and update the md5 (or SHA256) value in the specified *.bb file.

After baking, create a bootable uSD card (it will have to be at least 2GB):

Use the Yocto wic tool to create a dd-able image:

$ wic create sdimage-gumstix -e gumstix-console-image

Flash the dd-able image to your uSD card (replace /dev/sdX with the path to your uSD card):

$ sudo dd if=/var/tmp/wic/build/sdimage-gumstix-201506231742-mmcblk.direct of=/dev/sdX

And we’re done! Next, in part four, we’ll go over connecting to your Gumstix and starting the ROS package.