Embedded Motion Control 2013

From Control Systems Technology Group
Revision as of 16:44, 30 August 2013 by SDries (talk | contribs)
Jump to navigation Jump to search

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

Gostai-Jazz-500x500.jpg

Introduction

This course is about software design and how to apply this in the context of autonomous robots. 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:

September, 4th Introduction Assignment and basic computer setup
September, 11th Localization C++ and ROS Concepts
September, 18th Navigation Software design
September 25th Corridor competition
October, 2nd Separation of Concerns: the 5 C's
October 9th State estimation Whole-body motion planning and control
October 16th Intelligent agents
October 23th Final competition

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

Slides

The slides of the various lectures will be available a.s.a.p.

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 PICO 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 PICO and to prepare for the final contest, a simulator will be made available that mimics the in and outputs to the real 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 PICO 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 PICO 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 PICO to speed up execution of the task Click here for a pdf file containing the arrow we will use. We also 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 2013-10-08-15-35-04.bag
    The topics /pico/camera and /pico/camera_info should then become available. For example, while playing the bag file, use
    rosrun image_view image_view image:=/pico/camera
    to view the camera images.


Corridor Competition

An intermediate review will be held on May 16th, 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. Some facts:

Corridor example.jpg
  • The exit can be either left or right
  • It is not known beforehand how far the exit is located from the start (somewhere between 1 and 10 meters)
  • It is not known beforehand if the opposing end wall (on the far end) will be open or closed
  • The walls are approximately parallel to each other
    • Note: the walls might not be perfectly straight
  • The distance between the walls is not known in advance, but will be reasonable (somewhere between 0.5 and 1.5 meters).
    • The distance between the walls will be fairly constant throughout the corridor, 'fairly' meaning that we build the corridor by hand, and the distance may change a little along the corridor.
  • PICO will start with its laser range finder between the walls
  • PICO will be approximately facing the end of the corridor. (Notice: approximately, so don't just drive forward for n seconds!)
  • At the exit, the finish line is located approximately 30 cm from the side of the corridor (Notice: approximately, so don't just drive forward for 30 cm!). The walls that can be used to align PICO will be a little bit longer.
  • You have finished the assignment if PICO did not drive into walls, took the correct turn, the castor wheels are across the finish line.
  • Hitting the wall will result in 0 points!

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

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 Pico robot.

Ubuntu

Download Ubuntu 12.04 using these direct links: 32-bit or 64-bit. Then go to this page and follow the instructions to create a bootable USB stick. Reboot your computer with the newly created USB stick, and 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. Of course you can also bring your notebook to the ICT servicedesk and ask them to install Ubuntu (but mention that you need version 12.04, not 14.04).

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. Read more

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.

We will be using ROS Groovy. Install ROS Groovy using the installation instructions on the ROS wiki. After the installation, you should do the ROS tutorials. The ROS tutorial can be found here. In some of the tutorials you can choose between catkin and rosbuild (for example in this tutorial. Make sure you select rosbuild (above the content text box).

Before you continue, make sure you understand the basic ROS concepts, such as:

  • package
  • node
  • topic
  • subscriber
  • publisher
  • message
  • callback function
  • ...

In addition it is important to know the concept of the ROS_PACKAGE_PATH. ROS_PACKAGE_PATH is a variable which informs ROS on the location of your packages. ROS will only be able to find packages which are located in a folder which is part of your package path! To print the value of the ROS_PACKAGE_PATH variable, you can simply type:

echo $ROS_PACKAGE_PATH

in a terminal.

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. Make sure you read the following SVN instruction carefully! Not reading them might cost you a lot of time in the end!


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/groovy/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/emc:$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. This command tells ROS to look in the emc/ros folder whenever it is looking for your code. 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

This command forces the terminal to reload all variables without restarting the terminal. 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. Both of these editors have the advantage of understanding you code up to some extend. This means they can be used to, e.g., autocomplete names of variables and functions or get compilation error message in a nice way. We recommand using Qt or Eclipse. Continue here.

Gazebo

We will use the robot simulator [Gazebo] to simulate the PICO robot and its environment. This includes simulation of the physics and sensors of the robot. To install Gazebo:

  1. Open a terminal (ctrl-alt-t)
  2. Setup your computer to accept software from packages.osrfoundation.org:
    sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu precise main" > /etc/apt/sources.list.d/gazebo-latest.list'
  3. Retrieve and install the keys for the Gazebo repositories:
    wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
  4. Update apt-get and install Gazebo.
    sudo apt-get update
    sudo apt-get install gazebo
  5. Initialize.
    gzserver
    Wait until you get a message like Publicized address: ....

You can try if your Gazebo installation was successfull by either executing a gazebo client on a seperate terminal:

gzclient

Or by running the program alone:

gazebo

Simulator

Installation

If you followed all steps specified on the installation page , you will already have downloaded the simulator Gazebo and our specific Jazz simulator. To be able to use the Jazz simulator, you first have to compile the downloaded ROS packages:

  1. Open a terminal (ctrl-alt-t)
  2. Make sure rosdep is initialized and up to date:
    sudo rosdep init
    rosdep update
  3. Build and compile the jazz simulator and other necessary packages:
    rosmake jazz_gazebo gazebo_map_spawner

Furthermore, Gazebo needs to know where to find the robot description (located in jazz_description) which includes its meshes, textures, kinematic chain, etc, and where to find the plugins for the controllers and sensors. This information can be set in the environment variables GAZEBO_PLUGIN_PATH and GAZEBO_MODEL_PATH:

  1. Open a terminal (ctrl-alt-t)
  2. Open .bashrc:
    gedit ~/.bashrc
  3. Add the following lines:
    export GAZEBO_PLUGIN_PATH=~/ros/emc/general/jazz_gazebo/lib:~/ros/emc/general/tue_gazebo_plugins/lib:$GAZEBO_PLUGIN_PATH
    export GAZEBO_MODEL_PATH=~/ros/emc/general/jazz_description:$GAZEBO_MODEL_PATH
  4. and source your .bashrc:
    source ~/.bashrc
    or start a new terminal.

Starting the Simulator

  1. Start Gazebo:
    gazebo
  2. Start another terminal and spawn the maze:
    rosrun gazebo_map_spawner spawn_maze
  3. Spawn PICO:
    roslaunch pico_gazebo pico.launch

Notice that the Jazz robot is spawned in the Gazebo world. The Gazebo GUI shows how the world actually is. We can also visualize how the robot perceives it through its sensors, by using the ROS tool Rviz. You can start RViz with a pre-defined config showing most of Jazz' sensors using:

rosrun jazz_visualization rviz

In fact, this simply runs the following command:

rosrun rviz rviz -d ~/ros/general/jazz_visualization/rviz/jazz.vcg

If you are running the Gazebo simulation, you will see the Jazz robot model and white dots which represent the sensor data originating from the (simulated) laser range finder. RViz allows you to visualize many more things. For example, to show the data from the camera:

  1. Click on the Add button in the lower left
  2. Select Camera and click OK. A Camera item will pop up in the Displays view on the left.
  3. Click in the field right next to Image Topic and click the ... button. Now you can select the camera topic (/pico/camera/image)

You will see the camera images visualized in the lower left of your screen.

Examples

Here are some examples on how to use the simulator and how to practice the corridor competition in simulation.

Jazz Driving Example

  1. Have a look at the file jazz_node.cpp in the src folder of the jazz_example package. You should be able to understand what the program will do.
  2. Build the package:
    rosmake jazz_example
  3. Run the node (make sure the simulator is still running):
    rosrun jazz_example jazz_node
    Check the result in both Gazebo and RViz.
  4. Feel free to use this example as a start for your project

Jazz Safe Driving Example

  1. First of all, make sure you have the latest version of the jazz_example package:
    1. roscd jazz_example
    2. svn up
  2. Take some time to have a good look at the file safe_drive.cpp in the src folder of the jazz_example package. It contains a quite elaborate explanation of what is going on in the code, which will hopefully clarify quite some things.
  3. Build the package:
    rosmake jazz_example
  4. Run the node (make sure the simulator is still running):
    rosrun jazz_example safe_drive
    Check the result in both Gazebo and RViz.
  5. Feel free to use this example as a start for your project


Troubleshoot

Gazebo does not stop gracefully upon exit or interrupt (ctrl-c)

You may get the warning:

Warning [gazebo_main.cc:59] escalating to SIGKILL on server

when stopping Gazebo. This is a known bug and has no consequences, other than that it takes a bit longer to kill Gazebo.

Getting Started

To get started, please do the following tutorials:

FAQ

Ubuntu

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

Gazebo

Gazebo keeps crashing

  1. Try to run it in gdb: enter
    gdb gzserver
    to start gdb and enter
    run
    to actually start the server. The same holds for the client (visualization):
    gdb gzclient
    and again type
    run
    to start it.

PICO does not drive and does not publish any odometry

  1. Try rosmaking pico-gazebo with pre-cleaning:
    rosmake pico_gazebo --pre-clean

RViz

RViz gives a segmentation fault and crashes

Try to run RViz in gdb:

gdb /opt/ros/groovy/lib/rviz/rviz

And then type

run

You can load an RViz configuration using File -> Open Config and then navigating to the correct file, e.g. in pico_visualization.

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 1 - Wouter
Q: There was a ubuntu update (2013-10-11) which also updated gazebo, now my I cannot spawn any maps anymore.
A: To be certain; first remove all folders from ~/ros/emc/general/. Then do svn update. Now make all the nodes rosmake jazz_description jazz_gazebo jazz_visualization tue_gazebo_plugins gazebo_map_spawner. You should be able to spawn mazes again by now. However when you start rviz you will see that pico has errors regarding the RobotModel and the LaserScan, to fix this set the fixed frame in Global Options to /pico/base instead of /pico/odom


Image_view

Q: When trying the command :rosrun image_view image_view image:=/pico/asusxtion/rgb/image_color
i get the following response:
[rospack] Error: stack/package image_view not found

A: You need to install image_view:
sudo apt-get install ros-groovy-image-view