Skip to content

Instantly share code, notes, and snippets.

@alexanderkoumis
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexanderkoumis/ed531b0cc7dec297e06d to your computer and use it in GitHub Desktop.
Save alexanderkoumis/ed531b0cc7dec297e06d to your computer and use it in GitHub Desktop.
ROS Quick Start Notes

ROS Packages

What makes up a catkin package?

my_package/
  CMakeLists.txt
  package.xml

package.xml provides meta information about the package. CMakeLists.txt contains build instructions for CMake, and must use catkin CMake variables.

Recommended development flow

Maintain a single development workspace, called 'catkin workspace', containing all catkin packages. Aliased as catkin_ws by setup.bash (see next section).

workspace_folder/        -- WORKSPACE
  src/                   -- SOURCE SPACE
    CMakeLists.txt       -- 'Toplevel' CMake file, provided by catkin
    package_1/
      CMakeLists.txt     -- CMakeLists.txt file for package_1
      package.xml        -- Package manifest for package_1
    ...
    package_n/
      CMakeLists.txt     -- CMakeLists.txt file for package_n
      package.xml        -- Package manifest for package_n

Customizing package.xml

Sample package.xml:

<?xml version="1.0"?>
<package>
  <name>beginner_tutorials</name>
  <version>0.1.0</version>
  <description>The beginner_tutorials package</description>

  <maintainer email="you@yourdomain.tld">Your Name</maintainer>
  <license>BSD</license>
  <url type="website">http://wiki.ros.org/beginner_tutorials</url>
  <author email="you@yourdomain.tld">Jane Doe</author>

  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>

  <run_depend>roscpp</run_depend>
  <run_depend>rospy</run_depend>
  <run_depend>std_msgs</run_depend>

</package>

Customizing CMakeLists.txt

Must follow the following format:

cmake_minimum_required()
project()
# Only use for build (!run) time dependencies, message_generation usually
# pulled in transitively
find_package(catkin REQUIRED COMPONENTS <ros_package_dependencies> message_generation)

# ROS stuff
add_message_files(FILES
	MyMessage1.msg
	MyMessage2.msg
)
add_service_files(FILES
	MyService.srv
)
add_action_files(FILES
	MyAction.action
)
generate_messages(DEPENDENCIES std_msgs sensor_msgs actionlib_msgs)

# Specify package build info export
# Must be called before declaring any targets with add_library() or add_executable
catkin_package( 
   INCLUDE_DIRS include
   LIBRARIES ${PROJECT_NAME}
   CATKIN_DEPENDS roscpp nodelet
   DEPENDS eigen opencv)
add_library()
add_executable()
target_link_libraries())
catkin_add_gtest()
install()

Message files

These are simple text files for specifying data structure of message.

Setting up catkin workspace

source /opt/ros/indigo/setup.bash
mkdir ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace

To build workspace:

cd ~/catkin_ws/
catkin_make

Sourcing ROS environment variables

source ~/catkin_ws/devel/setup.bash
echo $ROS_PACKAGE_PATH # make sure proper environment variables set

Creating catkin package

cd ~/catkin_ws/src
# catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
cd ~/catkin_ws
catkin_make

This will create a similar structure in ~/catkin_ws/devel as found in /opt/ros/$ROSDISTRO_NAME

Sourcing built workspace to ROS environment:

~/catkin_ws/devel/setup.bash

Building packages in catkin workspace

catkin_make

This will build any packages in the source space (/catkin_ws) to the build space (/catkin_ws/build)

roscd <package_name>/src
# Add/edit source files
roscd <package_name>
# Update CMakeLists.txt to reflect change to sources
cd ~/catkin_ws
catkin_make -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON
# Source either the `devel` or `install` space
# To source devel space:
#   source ~/catkin_ws/devel/setup.bash
# To source install space:
#   catkin_make install
#   source ~/catkin_ws/install/setup.bash

To add a new package to a previously compiled workspace:

catkin_make --force-cmake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment