# Embedded Motion Control 2012

Guide towards the assignment
'A-MAZE-ING JAZZ'

# Introduction

This course is about acquiring the knowledge that is necessary to be able to design and implement embedded software for real-time control systems. The book "Real-time concepts for embedded systems" by Li and Yao will be taken as a starting point. The participating students themselves will give lectures to their peers about parts of this book. The accompanying assignment is about applying this knowledge to a real-life robotics task in which ROS will be the standard software framework.

## Course Schedule

Lectures will be given on Mondays from 10.45 - 12.30 in Gemini-Zuid 3A12. The course schedule is as follows:

 April, 23th Introduction May, 7th Chapter 1, 4 Ch 1: Group 1, Ch 4: Group 2 May, 14th Chapter 5, 6 Ch 5: Group 3, Ch 6: Group 4 May, 21th Chapter 7, 8 Ch 7: Group 5, Ch 8: Group 6 May, 29th Chapter 9, 10 Ch 9: Group 7, Ch 10: Group 8 June, 4th Corridor competition June, 11th Chapter 11, 14 Ch 11: Group 9, Ch 14: Group 10 June, 18th Chapter 15 Ch 15: Group 11 June, 29th Final Contest Start: 09.00

## Exam Schedule, Please fill in

The final contest will be held some day between June 25th and July 6th. In order for us to find a proper date and time which does not interfere with your exams, please add your exam dates and times to the table below. Deadline: May 13th

 Date Time Time June, 25th 09:00 - 12:00 14:00 - 16:00 June, 26th 09:00 - 12:00 June, 27th 14:00 - 17:00 June, 28th 09:00 - 12:00 14:00 - 17:00 June, 29th 14:00 - 17:00 July, 2rd 14:00 - 17:00 July, 3rd 09:00 - 12:00 14:00 - 17:00 July, 4rd 09:00 - 12:00 14:00 - 17:00 July, 5th 09:00 - 12:00 July, 7th 09:00 - 12:00 14:00 - 17:00

## Pico test schedule, maze

In order to test your software on the Pico robot, each group has one one hour time slot a week available, on either Wednesday or Thursday. You can reserve your test slot in the table below. Make sure to keep at least one hour in between you slot and the previous and next ones, since Pico needs some time to recharge in between the time slots!

 Date Time Group Wednesday June, 13th 09:00 - 10:00 Group 9 Wednesday June, 13th 11:00 - 12:00 Group 5 Wednesday June, 13th 13:00 - 14:00 Group 3 Wednesday June, 13th 16:00 - 17:00 Group 6 Thursday June, 14th 09.00 - 10.00 Group 1 Thursday June, 14th 11.00 - 12.00 Group 7 Thursday June, 14th 13.00 - 14.00 Group 2 Thursday June, 14th 15.00 - 16.00 Group 8 Thursday June, 14th 16.30 - 17.30 Group 1 Wednesday June, 20th 10.00 - 11.00 Group 5 Wednesday June, 20th 12.00 - 13.00 Group 3 Wednesday June, 20th 14.00 - 15.00 Group 6 Wednesday June, 20th 16.00 - 17.00 Group 9 Thursday June, 21st 09.00 - 10.00 Group 1 Thursday June, 21th 11.00 - 12.00 Group 7 Thursday June, 21st 13.00 - 14.00 Group 2 Thursday June, 21st 15.00 - 16.00 Group 8 Thursday June, 21st 17.00 - 18.00 Group 11 Wednesday June, 27th 15:00 - 16:00 Group 6 Wednesday June, 27th 9:00 - 10:00 Group 7 Wednesday June, 27th 11:00 - 12:00 Group 9 Wednesday June, 27th 13:00 - 14:00 Group 3 Thursday June, 28th 09.00 - 10.00 Group 1 Thursday June, 28th 11.00 - 12.00 Group 5 Thursday June, 28th 13.00 - 14.00 Group 2 Thursday June, 28th 15.00 - 16.00 Group 8 Thursday June, 28th 17.00 - 18.00 Group 11

## Slides

The slides from the first lecture (April 23th) can be found here:

The slides from the first lecture (May 7th) can be found here:

The slides from the second lecture (May 7th) can be found here:

The slides from the lecture of May 29th can be found here:

# Goal

The goal of the assignment is to get the real-time concepts in embedded software design operational.

The concrete task that has to be solved is to let the Jazz robot find his way out of a maze. The final demonstration by each participating group of 4-5 students will be performed during a contest, the winner of which is the group that exits the maze in the shortest amount of time. To prepare for this competition the following guidelines have to be considered:

• to test with Jazz and to prepare for the final contest, a simulator will be made available that mimics the in and outputs to the real Jazz robot. Specifics of this simulator will be presented in the first lecture on September 4th
• the maze of the final competition will be constructed just before the competition. The maze presented in the simulator is therefore different from the real one used in the final contest.
• both on the real and simulated Jazz robot, three sources of sensor information will be available to perceive the environment and to derive the state of the robot:
• laserdata provided by the forward pointing laser scanner,
• images captured by the monocular camera,
• odometry provided by the base controller
• the robot can be actuated by sending information to the base controller
• during the final contest, it is highly imperative that the Jazz robot refrains from colliding with the walls in the maze. Colliding with the walls will result in severe time-penalties.
• the walls of the maze will contain several types of pointers to the exit, which can potentially help Jazz to speed up execution of the task. Click here for a pdf file containing the arrow we will use. Also, we have uploaded a zip file with multiple images of these arrows captured on the real PICO robot. Furthemore, we captured PICO's camera topics in a bag file while the robot was looking at the arrow. You can play this bag file as follows:
rosbag play pico_camera_arrow.bag
The topics /robot/body/head/camera/camera_info and /robot/body/head/camera/image_raw should then become available. For example, while playing the bag file, use
rosrun image_view image_view image:=/robot/body/head/camera/image_raw
to view the camera images.

An intermediate review will be held on September 24th, during the corridor competition. During this challenge the students have to let the robot drive through a corridor and then take the first exit. The precise location of this exit will not be given in advance.

During the final contest, the groups are expected to give a short (5 minute) presentation about their progress and design decisions.

# Hardware

The moving Jazz robot with monocular camera and laser range finder with a working ROS interface. In addition, we provide a Jazz simulator for offline testing.

# Installation

This manual describes how to the install the necessary and sufficient software to start programming the Jazz robot.

## Ubuntu

Go to The official Ubuntu site and download and install Ubuntu 12.04, which is the latest Long Term Support release. Make sure that you download the appropriate architecture i.e., 32- or 64-bit. Of course you can also bring your notebook to the ICT servicedesk and ask them to install Ubuntu. If you want to keep using Windows next to Ubuntu the most easy way is to have a dual-boot system, i.e., during startup you can choose to boot either Ubuntu or Windows.

### Ubuntu Terminal

Most of your interaction with Ubuntu will be done through the terminal, the number-one way of interacting with Ubuntu using your keyboard. A terminal can be started as follows: Application -> Accessories -> Terminal, or by pressing ctrl-alt-t. It might be a good idea to drag the terminal icon in the menu to the Ubuntu panel, as you will be using it a lot.

Although the terminal commands may seem somewhat puzzling at first, you'll soon find out that the terminal is a nifty tool and allows for faster and more powerful access to all of Ubuntu's possibilities than the graphical interface and mouse. If you don't know your way around the terminal, have a look at this page.

A convenient tool to avoid having a large amount of terminals is Terminator, so you can have multiple terminals in one window. To make Terminator start up with some screen setup:

• 1. Open “Terminator”
• 2. Make the set-up to be saved: some split ups
• a. Right click
• b. Choose “split horizontally” or “split vertically”
• c. Continue the previous step, until you are happy
• 3. Right click
• 4. Choose “preferences”
• 5. Pick tab “layout”
• 7. Enter a name (= <your chosen name>)
• 8. Press "enter"
• 9. Click "close"
• 10. Right click the button to open “Terminator”
• 11. Choose “properties”
• 12. Enter in “command” : “terminator -l <your chosen name>”
• 13. Click close
• 14. To test: open “Terminator”

## ROS

In this project we will use the Robotic Operating System (ROS) which aids the testing and development of robot software. ROS provides a nice open-source framework for dealing with the communication between and management of different modules, and comes with a large amount of software that can be used out of the box, including device drivers, libraries, low- and high-level software, visualizers and more. More information about ROS and its goals can be found here. The ROS tutorial can be found here.

To install ROS Fuerte under Ubuntu 12.04, do the following:

1. Add the ROS Debian source to your sources.list such that Ubuntu knows where to download ROS from. Open a terminal (Applications -> Accessories -> Terminal) and enter:
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu precise main" > /etc/apt/sources.list.d/ros-latest.list'
1. To be able to connect with the server, you need to add its public key to your keys:
wget http://packages.ros.org/ros.key -O - | sudo apt-key add -
2. Make sure you have re-indexed the ROS.org server such that you get the latest changes:
sudo apt-get update
3. Then, install a ROS desktop:
sudo apt-get install ros-fuerte-desktop

If you ran into problems, be sure to check the installation guide on the ROS website.

## SVN

In this project, an SVN will be used for sharing and versioning the software within your group. Every group has its own space on the SVN, and an account which has only permissions for that particular part.

To set up the directory to where the code is checked out from the SVN, open a terminal and do the following:

1. First, create a directory in your home directory in which you will put all ROS-related code, files and data:
mkdir ~/ros
2. Then, go to that folder
 cd ~/ros
and check out your group folder from the SVN. For example, for group 1:
svn co https://roboticssrv.wtb.tue.nl/svn/emc/2013/groups/emc01
3. Furthermore, check out the general folder, which contains the robot simulator:
svn co https://roboticssrv.wtb.tue.nl/svn/emc/2013/general

You now have the latest version of all the code that is available on your computer. If you make any changes or improvements, you can save these changes on your disk without interacting with the SVN.

Once you are done with your work, or if you want to save intermediate results on the SVN, you can commit your changes by going to the folder where you have made the changes and then typing:

 svn ci -m 'a description of the changes you made' file_I_want_to_commit.cpp

Please note that this will only upload the changes of files that are already on the SVN. If you want to add new files to the SVN you first have to add them by typing:

svn add file_I_want_to_add.cpp

You can add a folder recursively (with all files included in the folder) by typing:

svn add folder_I_want_to_add

Note that after adding you still have to commit your changes in order to store them on the SVN. You can delete files on the same way by typing delete rather then add.

Note: make sure you do not add auto-generated files, such as executables, to your SVN.

## Environment Set-up

So far we've installed ROS and created a local copy of the SVN. However, before you can start working, you need to do some additional set-ups to make sure Ubuntu knows where to find all ROS-related packages, scripts, etc. More specifically, every time you start up a terminal, the correct environment variables need to be set. The file .bashrc in your home directory is your friend: it's a script which runs every time a a new terminal is opened. We basically need to add some lines to this file, so open the file with a text editor:

gedit ~/.bashrc

Append the following text to the end of the file:

source /opt/ros/fuerte/setup.bash

This will set-up all ROS-related scripts etc. every time you open a terminal. Furthermore, ROS needs to known where your software is located. Therefore, also add the following command to ~/.bashrc:

export ROS_PACKAGE_PATH=~/ros:$ROS_PACKAGE_PATH That's it. Next time you open a terminal, .bashrc is executed, which will in turn execute the script and set the path specified above. Since the script only runs when a new terminal is opened, the changes are not active in your current terminal. If you want to see it working directly without starting a new terminal, explicitly source .bashrc from the terminal: source ~/.bashrc To see whether it worked, try one of commands that are now at your disposal. For example, change your directory to the roscpp package: roscd roscpp ## Integrated Development Environments To keep the code in your packages clear and manageable, it is advised to use an Integrated Development Environment (IDE) to edit your C++ code. Two editors that are commonly used are Qt Creator and Eclipse. ### Qt Creator #### Installation 1. Download Qt Creator for Linux: 32-bit or 64-bit (Find out which one you need here 64_bit_or_32_bit ) (Visit the website here). Best is to go to the website and get the most current version. Don't use the software centrum to get Qt, then all this will not work properly 2. Open a terminal, cd to the folder where you downloaded the file (probably ~/Downloads) 3. Make the file executable: chmod +x <INSTALL_FILE> 4. Run the installation: ./<INSTALL_FILE> 5. Make sure Qt Creator launches with the ROS environment available: 1. Open the launcher properties (right-click Applications -> Edit Menus -> Programming -> Qt Creator -> Properties 2. In the 'Command' field, add bash -i -c in front of the existing command. Now you can correctly launch Qt Creator from the menu. #### Use with ROS ##### Creating a ROS package To create a ROS package, follow the usual steps, i.e., use the roscreate-pkg command. ##### Open an existing ROS package 1. Make sure your package is in the ROS_PACKAGE_PATH 2. Start Qt Creator 3. File -> Open File or Project 4. Navigate to and open the CMakeLists.txt file of your package 5. Change the build directory into <YOUR_PACKAGE_DIR>/build (that is: a / instead of a -). Click 'Next'. 6. Click 'Run CMake'. This will automatically look for and include dependencies in the manifest.xml file, see which .cpp files you use, etc, based on your CMakeLists.txt. 7. Click 'Finish' Now you are ready to start developing your code. Pressing Ctrl-b will build the active project. If you change the manifest.xml or CMakeLists.txt file, you only have to run CMake again (Build -> Run CMake). ##### Show header files in the 'Projects View' Qt Creator only shows your .cpp files in the 'Project View', which can be a bit of a nuisance. To also show your header files, perform the following trick: 1. Open CMakeLists.txt 2. Add the following line before rosbuild_add_executable: file(GLOB_RECURSE HEADER_FILES include/*.h) This looks for all .h files in the include folder of your package, and stores them in the variable HEADER_FILES. 3. Add${HEADER_FILES} to your rosbuid_add_executable list. For example:
rosbuild_add_executable(my_program src/program.cpp \${HEADER_FILES})
4. Within Qt Creator, run CMake (Build -> Run CMake)

You should now be able to see all .h files in the include folder of your package.

##### Troubleshoot
###### CMake Error

If you try to open your project in Qt Creator and you get the following message when running CMake:

CMake Error: The current CMakeCache.txt directory <YOUR_PACKAGE>/build/CMakeCache.txt is different
than the directory <OTHER_DIR>/build where CMakeCache.txt was created. This may result in binaries
being created in the wrong place. If you are not sure, reedit the CMakeCache.txt


you have probably moved your package without cleaning it (make clean). This means the absolute paths that where generated during building do not make sense anymore. To solve this, do the following:

• Clean your project, i.e., run make clean
• Make sure there is no CmakeLists.txt.user in your package (it is auto-generated by Qt Creator)
• Try to open your project again

### Eclipse

Eclipse is an IDE widely used for Java, C, C++ and many more languages. This section explains how it can be configured to be easily used with ROS packages.

To install Eclipse, do the following:

2. Find Eclipse IDE for C/C++ Developers and select the appropriate version on the right (32-Bit or 64-Bit Linux).
3. Extract Eclipse into a folder of your choice
4. You can create a launcher to Eclipse to your panel by alt + right clicking the panel, choosing 'Add to panel' and selecting 'Custom Application Launcher'. Then browse to the Eclipse executable, and enter a name. If you want you can add the Eclipse icon by clicking the image on the left and browsing to the icon in the Eclipse folder.

Now, to make sure your package can be viewed properly in Eclipse, do the following:

1. Create a custom package in your ~/ros directory with optional dependencies:
cd ~/ros
roscreate-pkg <package-name> [dependencies...]
2. Enter in a terminal:
roscd <package name>
make eclipse-project
3. Open Eclipse
• You will be prompted to select a path for the workspace. The default (/home/YOUR_NAME/workspace) is fine here. This folder will not contain the software (that is stored in ~/ros), but simply pointers to the software and some administration files for Eclipse.
4. Go to “file” → “Import”
5. Click “General”
6. Then “Existing Projects into Workspace”
7. Click “next”
8. Browse for the package

All environment settings should be set automatically. You can build the package using ctrl-b. Note that you have to remake the eclipse-project in your package every time you change the manifest or if you switch to a new version of ROS. If you're having trouble or want to know more about the possibilities of using eclipse with ROS, check the ROS wiki.

# Getting Started

To get started, please do the following tutorials:

# FAQ

## Ubuntu

### I installed Ubuntu, but my wireless internet is not working.

You're wireless card is not supported by Ubuntu 10.04. One possible fix is to download the latest wireless drivers here, see Where to download bleeding edge. This page also contains detailed info on how to install the drivers. This basically boils down to:

1. Extract the tar ball into a folder
2. Open a terminal, and cd to the directory
3. Compile the driver against the kernel:
make
This may take a while.
4. Install the driver:
sudo make install
5. After a reboot, your wireless should be working.

Note: Since you build the driver against the kernel, you need to rebuild it after every kernel update, i.e., you have to again do the compilation and installation step described above.

### I installed Ubuntu, but my screen is flickering (IBM Lenovo T60).

The following command shows the supported packages:

sh ./ati-driver-installer-9-3-x86.x86_64.run --listpkg

Result (among others):

Ubuntu Packages:
Ubuntu/7.10
Ubuntu/8.04
Ubuntu/8.10
Ubuntu/9.04
Ubuntu/gutsy
Ubuntu/hardy
Ubuntu/intrepid
Ubuntu/jaunty
Ubuntu/source


Unfortunately, Ubuntu 10.04 is not supported by this driver and therefore, installing this driver will results in an error like this:

Error: ./default_policy.sh does not support version
default:v2:i686:lib::none:2.6.32-41-generic; make sure that the version is being
correctly set by --iscurrentdistro


Try to install the driver by using the following command:

./ati-driver-installer-9-3-x86.x86_64.run --buildpkg Ubuntu/9.04

The driver for Ubuntu 9.04 is runnning without problems on my T60 with Ubuntu 10.04. Since this solution still caused some problems, I now installed Ubuntu 11.10 which seems to work well...

### I try connect to the svn but I need the GNOME keyring password.

1. Go to console
cd ~/.subversion
nano config
2. Go to [auth] and enter below [auth] the following "password-stores =".
3. Press ctrl+x and save the file with the same name (config).
4. Open a new console and now it works fine.

### I start the jazz_simulator but my maze is blinking very fast (HP Elitebook 8540w).

1. Go to "System" --> "Administration" --> "Hardware Drivers".
2. Remove the "ATI/AMD proprietary FGLRX graphics driver" (Ubuntu recommended to install this)
3. Restart Ubuntu

## RViz

### I cannot display odometry information in RViz

In order to visualize the odometry information, RViz needs a tf (transform) from /odom to /base_footprint which is not published by the simulated controller. Since this tf is not available on the real robot either, we will not add it to the simulator. If you really want to visualize the information, or need the transform for some other reason, you will have to publish the tf yourself. See http://ros.org/wiki/tf for more info.

### I've got an error with RViz and it doesn't start

If the error looks like this:

  The program 'rviz' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadDrawable (invalid Pixmap or Window parameter)'.
(Details: serial 22 error_code 9 request_code 136 minor_code 3)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)
[rviz-6] process has died [pid 1978, exit code 1].


The following solutions can be tried:

In section 3.4 Segfault during startup from RViz troubleshooting page.

Open a terminal without Gazebo running and just type:

  export OGRE_RTT_MODE=Copy


If this does not work, just follow the next steps:

1 rosrun rviz rviz --sync ( add the --sync it even says in the error message)
2 don't give up even with sync it will fail,maybe...try it 2-3 times
3 if it still fails do rosmake rviz rviz and repeat step 1


### Graphics drivers issues

Using the wrong graphics drivers may cause Gazebo and/or rviz to crash. To solve this problem, please follow the following steps:

• First try installing/updating the graphics driver using Hardware Drivers (System->Administration->Hardware Drivers)

You can test the driver from working properly by launching AMIGO in Gazebo and looking at the pointcloud data. This data should be refreshed when AMIGO for instance drives around or if you draw a big block in front of AMIGO.

## Global Q&A

Group 2
Q: Can it be assumed that all corners are 90 degrees?
A: Yes, it can (but be aware that in practice it may be 88 or 92 degrees as well...).
Q: Do arrows insinuate driving direction only or do they provide information on next crossroads as well?
A: The camera can only look in front of the robot meaning that arrows to the left or right in a corridor are hard to recognize. They will be placed in spots where you drive towards them. They only give information about the driving direction at the location of the arrow.

# Group Wiki Pages

Group 01 - Visit Wiki - Tutor: Jos Elfring -

Group 02 - Visit Wiki - Tutor: Rob Janssen -

Group 03 - Visit Wiki - Tutor: Janno Lunenburg -

Group 04 - Visit Wiki - Tutor: - -

Group 05 - Visit Wiki - Tutor: Sjoerd van den Dries -

Group 06 - Visit Wiki - Tutor: - -

Group 07 - Visit Wiki - Tutor: Jos Elfring -

Group 08 - Visit Wiki - Tutor: Rob Janssen -

Group 09 - Visit Wiki - Tutor: Janno Lunenburg -

Group 10 - Visit Wiki - Tutor: Sjoerd van den Dries -

Group 11 - Visit Wiki - Tutor: Jos Elfring -

# Contact Details

## Student Assistent

Yanick Douven - y dot g dot m dot douven at student dot tue dot nl

## Tutors

Sjoerd van den Dries - S dot v dot d dot Dries at tue dot nl

Luis Ferreira - L dot F dot Bento dot Ferreira at tue dot nl

Janno Lunenburg - J dot J dot M dot Lunenburg at tue dot nl

# Group Wiki Pages

Group 01 - Visit Wiki - Tutor: Jos Elfring - Ton Peters, Scott van Venrooij, Jeroen Graafmans, Rein Appeldoorn, Bart Peeters

Group 02 - Visit Wiki - Tutor: Janno Lunenburg - D.H.J.M. Van den Hoogen, V.J.M. Holten, T.H.A. Dautzenberg, B. Sleegers

Group 03 - Visit Wiki - Tutor: Rob Janssen - X. Luo, R.V. Bobiti, G.C. Rascanu, A.I. Pustianu

Group 04 - Visit Wiki - Tutor: Sjoerd van den Dries - Sander Hoen, Marc Meijs, Adnien Stieniec, Mikdaj Kabaanski

Group 05 - Visit Wiki - Tutor: Jos Elfring - Fabien Bruning, Yanick Douven, Joost Groenen, Luuk Mouton, Ramon Wijnands

Group 06 - Visit Wiki - Tutor: Janno Lunenburg - Roel de Natris, Daniel Hilgersom, Daan Gerrits, Johan van Uden, A.J. van der Hoeven

Group 07 - Visit Wiki - Tutor: Rob Janssen - Patrick Vaes, Siddhi Imming, Bart Moris, Roger Pouls

Group 08 - Visit Wiki - Tutor: Sjoerd van den Dries - Alexandru Gabriel Dinu, Thomas Theunisse, Alejandro Morales Medina, Ambardeep Das

Group 09 - Visit Wiki - Tutor: Jos Elfring - Harm Weerts, Dennis Klein, Ryvo Octaviano, Weitian Kou, Thomas Meerwaldt

Group 10 - Visit Wiki - Tutor: Janno Lunenburg - Ziyang Li, Libo Zu, Juan Chen, Fengjiao Yang

Group 11 - Visit Wiki - Tutor: Sjoerd van den Dries - Christiaan Gootzen, Sander van Zundert

# Contact Details

## Tutors

Sjoerd van den Dries - S dot v dot d dot Dries at tue dot nl

Jos Elfring - J dot Elfring at tue dot nl

Rob Janssen - R dot J dot M dot Janssen at tue dot nl

Janno Lunenburg - J dot J dot M dot Lunenburg at tue dot nl

# Presentations

Chapter 7 - File:Presentation.pdf