Difference between revisions of "ROS summary"

From AIRWiki
Jump to: navigation, search
(Created page with "This page is dedicated to two classes of ROS elements: commands (i.e. programs that you can run from the command line to perform specific tasks, such as [http://ros.org/wiki/r...")
 
m
Line 2: Line 2:
  
 
The most commonly used of these are described in a condensed form by the [http://www.ros.org/wiki/Documentation?action=AttachFile&do=get&target=ROScheatsheet.pdf ROS Official Cheat Sheet].
 
The most commonly used of these are described in a condensed form by the [http://www.ros.org/wiki/Documentation?action=AttachFile&do=get&target=ROScheatsheet.pdf ROS Official Cheat Sheet].
 +
 +
[http://www.ros.org/wiki/Documentation?action=AttachFile&do=get&target=ROScheatsheet.pdf ROS Official Cheat Sheet]
 +
 +
== ROS installation and package creation ==
 +
=== Configure your environment ===
 +
If you followed the [http://www.ros.org/wiki/ROS/Tutorials/InstallingandConfiguringROSEnvironment ROS tutorial] to configure your environment, the variable $ROS_PACKAGE_PATH should be set. This can be easily verified by check if the command <code> echo $ROS_PACKAGE_PATH </code> returns an output similar to:
 +
 +
: <code> /home/your_user_name/fuerte_workspace/sandbox:/opt/ros/fuerte/share:/opt/ros/fuerte/stacks </code>
 +
 +
If you use a different path (e.g.: ''~/eclipse_workspace'') you should add it to the $ROS_PACKAGE_PATH variable. The simplest way to achieve this is to edit the ''.bashrc'' file located in your home directory and add the line
 +
 +
: <code> export ROS_PACKAGE_PATH=~/eclipse_workspace:${ROS_PACKAGE_PATH} </code>
 +
 +
'''NOTE:''' Please be sure to add this command AFTER the following line (that you should have added to your .bashrc, according to the tutorial) or you will get an error running make eclipse-project:
 +
 +
: <code> source /opt/ros/[ros_distribution_name]/setup.bash </code>
 +
 +
=== IDEs ===
 +
If you use an IDE (in this example [http://www.eclipse.org/ Eclipse] will be used), in order to reuse your shell environment it is advisable to launch it with the following command:
 +
 +
: <code> bash -i -c /usr/lib/eclipse/eclipse </code>
 +
 +
If you use '''Eclipse''' you can also use the following command to let ROS create the Eclipse project files.
 +
 +
:<code> make eclipse-project </code>
 +
 +
Note that if you change anything to your ''manifest.xml'', you will have to run this script again, which will overwrite your Eclipse project file and thereby reverting all manual changes to the project settings. Please refer to [http://www.ros.org/wiki/IDEs this page] if you need further information.
 +
 +
Finally, to add the project to Eclipse select File --> Import --> General --> Existing Projects into Workspace, select the project's root directory and be sure that the "Copy projects into workspace" option is NOT selected.
 +
 +
== Package management ==
 +
ROS packages can be managed using your linux distribution package manager and/or with the built-in ROS package manager.
 +
 +
=== ROS package environment ===
 +
* initialize the ROS package management environment:
 +
::<code> (as root) rosdep init </code>
 +
 +
* update the package list:
 +
::<code> rosdep update </code>
 +
 +
=== ROS package installation ===
 +
* Find a package:
 +
:browse to [http://www.ros.org/browse/ this page] to browse a list of available packages.
 +
 +
* Check if a ROS package or stack is installed with the following command:
 +
 +
::<code> rospack find package_name
 +
::rosstack find [stack_name] </code>
 +
 +
* If you get an error, install the stack that contains the package with the package manager of your linux distribution (e.g.: <code> sudo apt-get install ros-distribution_release_name-stack_name </code>), then check again if rospack can find the package and, if not, install it with the command:
 +
 +
::<code> (as root) rosdep install package_name </code>
 +
 +
=== New package creation ===
 +
This command creates a new package in the current directory:
 +
 +
:<code> roscreate-pkg package_name package_dependency_1 package_dependency_2 package_dependency_3 ... </code>
 +
 +
Please note that package dependencies can be explicitly specified when the package is created, but they can also be manually added afterwards to the ''manifest.xml'' file or with the ''rospack command''. Take a look at [http://www.ros.org/wiki/ROS/Tutorials/CreatingPackage#ROS.2BAC8-Tutorials.2BAC8-rosbuild.2BAC8-CreatingPackage.First-order_package_dependencies this page] if you need further information.
 +
 +
==== CMakeLists.txt ====
 +
<code><pre>
 +
cmake_minimum_required(VERSION 2.4.6)
 +
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
 +
 +
# Set the build type.  Options are:
 +
#  Coverage      : w/ debug symbols, w/o optimization, w/ code-coverage
 +
#  Debug          : w/ debug symbols, w/o optimization
 +
#  Release        : w/o debug symbols, w/ optimization
 +
#  RelWithDebInfo : w/ debug symbols, w/ optimization
 +
#  MinSizeRel    : w/o debug symbols, w/ optimization, stripped binaries
 +
# Usage:
 +
#    set(ROS_BUILD_TYPE build_type)
 +
set(ROS_BUILD_TYPE Debug)
 +
 +
rosbuild_init()
 +
 +
# Set the default path for built executables to the "bin" directory
 +
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
 +
# Set the default path for built libraries to the "lib" directory
 +
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
 +
 +
# Uncomment if you have defined messages
 +
#rosbuild_genmsg()
 +
 +
# Uncomment if you have defined services
 +
#rosbuild_gensrv()
 +
 +
# **** Common commands for building c++ executables and libraries ****
 +
 +
# To add an executable cpp file:
 +
# Usage:
 +
#    rosbuild_add_executable(${PROJECT_NAME} executable_path)
 +
rosbuild_add_executable(test_read_map src/test_read_map.cpp)
 +
 +
# To add a library:
 +
# Usage:
 +
#    rosbuild_add_library(${PROJECT_NAME} libraries_path)
 +
rosbuild_add_library(map
 +
                    src/map/map_cspace.cpp
 +
                    src/map/map_draw.c)
 +
 +
# To link a library to an executable file:
 +
# Usage:
 +
#    target_link_libraries(${PROJECT_NAME} library_name)
 +
target_link_libraries(test_read_map map)
 +
 +
# To add boost directories:
 +
# rosbuild_add_boost_directories()
 +
 +
# To link boost:
 +
# rosbuild_link_boost(${PROJECT_NAME} thread)
 +
 +
# To add the dynamic reconfigure api:
 +
# rosbuild_find_ros_package(dynamic_reconfigure)
 +
# include(${dynamic_reconfigure_PACKAGE_PATH}/cmake/cfgbuild.cmake)
 +
# gencfg()
 +
# rosbuild_add_executable(dynamic_reconfigure_node src/dynamic_reconfigure_node.cpp)
 +
# rosbuild_add_executable(FIRST_dynamic_reconfigure_node src/FIRST_dynamic_reconfigure_node.cpp)
 +
 +
</pre></code>
 +
 +
==== Makefile ====
 +
Be sure that the following line is present in the Makefile in order for the command <code> make eclipse-project </code> to work:
 +
 +
<code> include $(shell rospack find mk)/cmake.mk </code>
 +
 +
==== Manifest.xml ====
 +
<code><pre><nowiki>
 +
<package>
 +
  <description brief="brief description of your package">
 +
 +
    [write here your package name]
 +
 +
  </description>
 +
  <author>Your name</author>
 +
  <license>BSD</license>
 +
  <review status="unreviewed" notes=""/>
 +
  <url>http://ros.org/wiki/package_name</url>
 +
  <depend package="package dependance 1"/>
 +
  <depend package="package dependance 2"/>
 +
  ....
 +
</package>
 +
</nowiki></pre></code>
  
 
== ROS filesystem commands ==
 
== ROS filesystem commands ==

Revision as of 11:17, 20 December 2012

This page is dedicated to two classes of ROS elements: commands (i.e. programs that you can run from the command line to perform specific tasks, such as roscd) and external programs (i.e. software dedicated to specific functions that is run separately when needed, such as rviz).

The most commonly used of these are described in a condensed form by the ROS Official Cheat Sheet.

ROS Official Cheat Sheet

ROS installation and package creation

Configure your environment

If you followed the ROS tutorial to configure your environment, the variable $ROS_PACKAGE_PATH should be set. This can be easily verified by check if the command echo $ROS_PACKAGE_PATH returns an output similar to:

/home/your_user_name/fuerte_workspace/sandbox:/opt/ros/fuerte/share:/opt/ros/fuerte/stacks

If you use a different path (e.g.: ~/eclipse_workspace) you should add it to the $ROS_PACKAGE_PATH variable. The simplest way to achieve this is to edit the .bashrc file located in your home directory and add the line

export ROS_PACKAGE_PATH=~/eclipse_workspace:${ROS_PACKAGE_PATH}

NOTE: Please be sure to add this command AFTER the following line (that you should have added to your .bashrc, according to the tutorial) or you will get an error running make eclipse-project:

source /opt/ros/[ros_distribution_name]/setup.bash

IDEs

If you use an IDE (in this example Eclipse will be used), in order to reuse your shell environment it is advisable to launch it with the following command:

bash -i -c /usr/lib/eclipse/eclipse

If you use Eclipse you can also use the following command to let ROS create the Eclipse project files.

make eclipse-project

Note that if you change anything to your manifest.xml, you will have to run this script again, which will overwrite your Eclipse project file and thereby reverting all manual changes to the project settings. Please refer to this page if you need further information.

Finally, to add the project to Eclipse select File --> Import --> General --> Existing Projects into Workspace, select the project's root directory and be sure that the "Copy projects into workspace" option is NOT selected.

Package management

ROS packages can be managed using your linux distribution package manager and/or with the built-in ROS package manager.

ROS package environment

  • initialize the ROS package management environment:
(as root) rosdep init
  • update the package list:
rosdep update

ROS package installation

  • Find a package:
browse to this page to browse a list of available packages.
  • Check if a ROS package or stack is installed with the following command:
rospack find package_name
rosstack find [stack_name]
  • If you get an error, install the stack that contains the package with the package manager of your linux distribution (e.g.: sudo apt-get install ros-distribution_release_name-stack_name ), then check again if rospack can find the package and, if not, install it with the command:
(as root) rosdep install package_name

New package creation

This command creates a new package in the current directory:

roscreate-pkg package_name package_dependency_1 package_dependency_2 package_dependency_3 ...

Please note that package dependencies can be explicitly specified when the package is created, but they can also be manually added afterwards to the manifest.xml file or with the rospack command. Take a look at this page if you need further information.

CMakeLists.txt

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

# Set the build type.  Options are:
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
#  Debug          : w/ debug symbols, w/o optimization
#  Release        : w/o debug symbols, w/ optimization
#  RelWithDebInfo : w/ debug symbols, w/ optimization
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
# Usage:
#     set(ROS_BUILD_TYPE build_type)
set(ROS_BUILD_TYPE Debug)

rosbuild_init()

# Set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# Set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

# Uncomment if you have defined messages
#rosbuild_genmsg()

# Uncomment if you have defined services
#rosbuild_gensrv()

# **** Common commands for building c++ executables and libraries ****

# To add an executable cpp file: 
# Usage:
#     rosbuild_add_executable(${PROJECT_NAME} executable_path)
rosbuild_add_executable(test_read_map src/test_read_map.cpp)

# To add a library:
# Usage:
#     rosbuild_add_library(${PROJECT_NAME} libraries_path)
rosbuild_add_library(map
                    src/map/map_cspace.cpp
                    src/map/map_draw.c)

# To link a library to an executable file:
# Usage:
#     target_link_libraries(${PROJECT_NAME} library_name)
target_link_libraries(test_read_map map)

# To add boost directories:
# rosbuild_add_boost_directories()

# To link boost:
# rosbuild_link_boost(${PROJECT_NAME} thread)

# To add the dynamic reconfigure api:
# rosbuild_find_ros_package(dynamic_reconfigure)
# include(${dynamic_reconfigure_PACKAGE_PATH}/cmake/cfgbuild.cmake)
# gencfg()
# rosbuild_add_executable(dynamic_reconfigure_node src/dynamic_reconfigure_node.cpp)
# rosbuild_add_executable(FIRST_dynamic_reconfigure_node src/FIRST_dynamic_reconfigure_node.cpp)

Makefile

Be sure that the following line is present in the Makefile in order for the command make eclipse-project to work:

include $(shell rospack find mk)/cmake.mk

Manifest.xml

<package>
  <description brief="brief description of your package">

     [write here your package name]

  </description>
  <author>Your name</author>
  <license>BSD</license>
  <review status="unreviewed" notes=""/>
  <url>http://ros.org/wiki/package_name</url>
  <depend package="package dependance 1"/>
  <depend package="package dependance 2"/>
  ....
</package>

ROS filesystem commands

  • To change directory directly to a package or stack directory:
roscd package_name

or

roscd stack_name

ROS visualization system - rviz

  • To open rviz you will need roscore running in background (execute roscore in a different shell) and then run the following command:
rosrun rviz rviz
The rviz interface will pop up, to visualize something published by a node you will have to
  • Add a type by clicking Add and selecting a display type (e.g.: poing cloud)
  • Set the topic that you want to listen (the one specified in the node that is publishing)
  • Set in the Global Options menu the desired Fixed Frame (typically /map )