Robotics

Catkin ROS

When using the Robotics Operating System, you will at some point want to develop your software. For the ROS1 version which is in maintenance until 2025, you will use Catkin to compile your projects. If you do not plan to program yourself, note that you may have to compile other people’s software so learning the basics is useful in any case. For the case that you have already moved to ROS2, you will be using colcon to do the same thing.

What is Catkin?

This tool is developed for ROS, the robotics operating system, by the team building the ROS tools. It has a multitude of tools to build your robotics project. Using it will be necessary if you develop robots using ROS. You should be aware that there have been several generations of these tools over the last few years. This means you need to choose the newest! Catkin is installed with the full ROS noetic distribution; all you need to take care of is the configuration. You need to set the correct environment for running Catkin.

Setting up the directory/environment

Create a directory with sub-directory src/ inside it. MyRob/src. The examples are from the beginner tutorial.

catkin_make creates CMakelists.txt in the src directory. These point to the other files that make up a project.

Next, you want to create your packages.

Go in the src directory

catkin_createpkg
$ catkin_createpkg beginner_tutorials std_msgs ropy roscpp

Note the mistake in the command. This creates everything as if you were not mistaken. You can find the result in the files with grep.

$ grep -r ropy
ubuntu@noetic:/home/ubuntu/catkin_ws/src/beginner_tutorials
$ grep -r ropy.
./CMakeLists.txt:  ropy
./CMakeLists.txt:#  CATKIN_DEPENDS ropy roscpp std_msgs
./package.xml:  ropy
./package.xml:  ropy
./package.xml:  ropy

The next compile will fail. You now have two choices, edit the files or remove the entire directory. The script is usually fast so the easiest is to remove and re-run the create command. Once you have cleared those mistakes, you continue by building the package. Either way, when you have fixed it, go to the workspace root and run catkin_make again. As you move on with any project, you will always go back up to the workspace root to make the whole project. This only makes sure that everything exists correctly, there are some clever tricks so you don’t have to recompile the whole project every time.

$ cd ~catkin_ws/ $ catkin_make

If it succeeds this time, you have just created your first package. Remember to fix up your package.xml file. You should probably set your name correctly and the license. There are more settings, they are all easy to understand.

A small project

Now, do it again in a new directory and create your project. Or better yet: for practice, pick up a project from GitHub, see where it goes, and then start changing it to your liking. To do this, you can create a workspace for catkin with a src directory. In the source directory, you copy in the source code directories. From the example, above you need two steps, clone the directory and run catkin_make.

$ cd /src
$ git clone https://github.com/crkaushik93/Go-Chase-It-RSEND-Project-2.git
$ cd ..
$ catkin_make

To make a less deep tree, you may move each sub-directory up one step but this is optional. The last command will search the src/ directory and find all code.

Installing

You do not usually install packages on the development system only. However, you run install to create an install environment and a development environment. The catkin_make command creates these for you. As you move on you should source one for development and the other for testing. A direct install will create your directories, including the scripts to initialize the environments.

$ catkin_make install


You will not have the files installed on your system, only in the project directory. This is great because all you need to do is run the setup and start testing.

$ source devel/setup_bash

Or…

$ source install/setup_bash

The first is for you to run testing and find out what mistakes you have embedded in your code.

Only ROS?

So, is this only valid for ROS1? Yes, catkin is aimed only at the ROS1 libraries. One thing to note though is that most of the job is cmake. You will be able to translate many of the practices to other projects that uses CMake. You only need to do more work since Catkin has simplified many tasks for you. For ROS2, many things are similar but the solutions are more refined and have more features to control how much you compile each time. You can also program in both levels of ROS, there is a bridge between the two!

Conclusion

Catkin is a very strong and versatile set of tools that makes your work much simpler and lets you get through the grind of developing your robotics code. The practices, though are an excellent way to learn more about programming. So even if your robot project is only for your closest circle and bragging rights, you can benefit from knowledge for other projects.

About the author

Mats Tage Axelsson

Mats Tage Axelsson

I am a freelance writer for Linux magazines. I enjoy finding out what is possible under Linux and how we can all chip in to improve it. I also cover renewable energy and the new way the grid operates. You can find more of my writing on my blog.