ROS Workspace and Packages – Week II

Refer to: Martinez’s Learning ROS Chap. 2, Gentle Intro to ROS 2.4 ~ 4

Note: We have ROS version Jade in both the computer and the laptop – there shouldn’t be too much differences yet, but nonetheless I should have informed you all earlier.

The distributed nature of ROS development (allowing different developers to contribute to ROS) required ROS to adapt to an effective package system. Without such system, the difficulty involved with integration and compilation of external code would have prevented ROS from taking off.

Accordingly, ROS has a convenient (relatively) package system called Catkin, and ROS’s promotion of Github allows for an easy integration with the external code. Catkin is a variant of the Makefile system – a program/format that automates a large part of the compiling task. With Catkin and Make systems, you just need to specify the C++/Python files with the respective libraries in text files. For Catkin system in ROS, the text file used is called CMakeLists.txt and package.xml, which are in each ROS packages.

ROS packages, each represented by the folders in Catkin Workspace (catkin_ws), contains the compiling instructions (the two text files above), as well as the source files of the package. Furthermore, they could contain msg files (for specifying topic), launch files (files that can be used to launch multiple programs at once), and so on – containing every code or configuration that is needed to do a specific task. Given that ROS packages largely exist for organization purposes, it is considered a good practice to only specify one function to each of the packages.

With all the files set up in the packages, the typical workflow goes as follows:

  1. First, I type out the program in C++ or Python and place it in the correct folder (src for C++, scripts for Python is recommended). Note that I am talking about src and scripts folder inside the package folder! So like ~/catkin_ws/package/src/ ...
  2. I specify the files and the libraries they need in CMakeLists.txt so that Catkin system may find them and compile/turn files executable.
  3. In the catkin_ws folder, I run source devel/setup.bash, which sets up the Catkin system so that it may be able to detect all the packages.
  4. I run catkin_make in the catkin_ws folder – which causes the Catkin system to start compiling all the packages in the src directory of catkin_ws. Also, msg and srv files are made into C++ header files, allowing you to import the topic messages into the program (by header files, just know for now that it would provide specification/type/function that the message requires to function).
  5. The compiled programs (if compilation was successful) end up in the build directory, able to be executed via rosrun <package_name> <file_name>.
  6. As a side note, you can disable compilation of certain packages by making an empty file called CATKIN_IGNORE in the package folder. To easily do that in the directory, use the command touch CATKIN_IGNORE.

Here is the workflow I use for integrating another package from Github into my project:

  1. I find the Github page for the package I want to download – let’s say https://github.com/ros/ros_tutorials – usually the Github page is at the top of the ROS wiki.
  2. I enter ~/catkin_ws/src.
  3. I make sure that the package is for the right ROS version (in our case, Jade) and I use the command git clone https://github.com/ros/ros_tutorials, which copies over the contents of the git repository into the ~/catkin_ws/src/ros_tutorials folder.
  4. EXTRA: I remove the .git file in the ros_tutorials (not one inside the src folder!!). .git file contains the git information (file changes, etc) and indicates that the folder with it is a separate git repository. To integrate the package into our own repository, we need to remove it. If not, you can keep it in.

Do read Martinez’s Learning ROS Chapter 2 – it has a detailed information about ROS package system.

Task: Download turtle_sim package and make a publisher that makes the turtle move in place in “circles”.

 

1 thought on “ROS Workspace and Packages – Week II”

Leave a Reply

Your email address will not be published. Required fields are marked *