The first time I heard its name was 3 years ago in a robotic course. It seemed to be a big complex stuff for me which I tried to escape as much as I could. Soon after building the first ROS application, my interest increased in such a way that I like to ROS-ify almost every project that I’m involved in. This post explains the basic concept behind ROS and its benefits.
1. It’s all about message passing
I’ll go through the details of ROS step-by-step. But for now, imagine ROS as a super-big library that is installed on Linux (and recently windows). This library provides an environment where you can simultaneously run multiple programs that can talk and listen to each other. For me, ROS evokes a place with several routers (programs) inside it that can emit/receive signals to other routers (programs).
2. Why it is good to use ROS?
Industrial-level projects often include several modules and sub-modules that must work together. Using ROS brings you these advantages:
You don’t have to take care about creating separate threads for each module/program. All you have to do is to write each module/program individually and then see how ROS itself runs everything smoothly. That’s why it is called Robot Operating System. Of course, it’s not a full OS but it manages the tasks and switches between them smoothly.
C++ and Python developers can work easily together. ROS supports both languages. So, if a developer prefers C++ and the other prefers Python, they can separately write their codes without being worried about finding or writing wrappers.
There are tons of pre-built ROS libraries that can be easily used and save your development time.
3. Before you start
ROS is an ecosystem with its own words. Having sense about them boosts your learning time.
In ROS dictionary, a program is called a node. As mentioned, industrial-level projects have several programs/nodes. These nodes can talk/listen to each other via messages (any type of message ranging from simple strings to image and point clouds). Each message must have a specific name called topic. A node that talks to others is called publisher, and a node that listens to others, is called subscriber. But this doesn’t mean that a node has to be only publisher or only subscriber. You can write a node that subscribes to a topic, and then based upon the contents of the subscribed message, publishes another message with another topic. This is quite routine when you develop in ROS.
A collection of nodes that perform a specific task, is called a ROS package.
4. Where to start?
ROS has excellent step-by-step tutorials on its website. You have to first install it. There are different distributions and it might be confusing for the first time to select which one. Install the newest LTS distro (currently, the newest is ROS Melodic). After installing, learn to create a catkin package and write a simple publisher/subscriber.
5. ROS for embedded computer vision
I’ve mainly used ROS for developing vision parts of robots. You might think that ROS is heavy for single board computers but I have installed it even on the low-powered Raspberry Pi Zero (single-core armv6 running at 1GHz and 512Mb RAM). There are some tips you should consider when using ROS in such resource-constrained systems:
If you really don’t need graphics, use an OS that has no desktop. This reduces boot time and leaves you more space on your SD card for other installations.
The architecture and OS of some single-board computers doesn’t allow to use pre-built ROS binaries. You have to build it from source. Download the ROS-comm version (the one with no GUI tool). Git clone other required packages for vision applications (image_transport and cv_bridge). Temporarily increase your swap size (to avoid ‘out of memory’ errors) and start building ROS.
After building, make a separate catkin workspace to install your new packages. Otherwise, each time that you want to build your packages, other basic packages are also checked which takes a long time.
If you need third-party libraries in your ROS nodes, build them from source with customized flags that describe your hardware (example). Then link them to your ROS node with Cmake. Using pre-built binaries doesn’t guarantee the full utilization of your resources.
6. What if I need to communicate with a non-ROS device?
Robotic projects often include microcontrollers with no operating system, and thus no ROS. Also, there might be situations where you want to communicate with a Windows computer with no ROS. There are some solutions like rosserial, ros#, and rosbridge but I found them a little bit hard to handle because of poor documentation. I suggest you to use Python Sockets. They are very easy to use and well documented. All you have to do is to create a python ROS node, import socket, and then implement your communication either as a server or client. This post is a good starting point. If you don’t like Python and look for a C++ solution, then check boost.asio or Qt Network module.