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:
- 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
- I specify the files and the libraries they need in CMakeLists.txt so that Catkin system may find them and compile/turn files executable.
- 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.
- I run
catkin_makein 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).
- The compiled programs (if compilation was successful) end up in the build directory, able to be executed via
rosrun <package_name> <file_name>.
- 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
Here is the workflow I use for integrating another package from Github into my project:
- 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.
- I enter
- 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
- EXTRA: I remove the
.gitfile in the ros_tutorials (not one inside the
.gitfile 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”.