OS & Tools/ROS

[ROS] Learn ROS with C++ or Python?

전두선 2020. 12. 17. 10:04

“Do you recommend me to learn ROS with C++  or Python?”

As you may know, you can create ROS programs mainly in two programming languages: Python and C++. There are other languages available like Swift, Lisp or others, but those are not fully supported. So for the rest of the article, we will consider that only Python and C++ are the available ones for a newcomer. Mostly, whatever you can do in ROS with C++, you can do it also with Python. Furthermore, you can have C++ ROS programs (ROS programs are called nodes) talking to other Python ROS nodes in the same robot. Since the nodes communicate using standard ROS messages, the actual language implementation of the nodes is not affecting their communication. That is the beauty of ROS.

If that is the way of working of ROS, then, why not to let everybody program in the language they want? Well, because programming in one language or another has its consequences, especially when you are learning ROS. Let’s have a look at them.


Programming ROS with Python

Pros of programming ROS in Python

  • Is faster to build a prototype. You can create a working demo of your node very fast if you use Python, because the language takes care of a lot of things by itself so the programmer doesn’t have to bother.
  • You don’t need to compile, and spend endless hours trying to catch a hidden bug. Even if you can have bugs in Python, the nature of them are a lot easier and faster to catch.
  • You can learn Python very fast.
  • You can make really short programs for complex things
  • The final code of your node is quite easy to read and understand what it does.
  • You can do anything with Python. Python is a very powerful language with libraries for anything you want.
  • It is easier to integrate it with web services based on Django. Since Django is based on Python, you can integrate ROS functions easily in the server calls.
  • It is easier to understand some ROS concepts if you use the Python API, because some complex concepts are hidden for the developer in the ROS Python API. For example, things like the Callback Queue are handled directly by the ROS Python API.

Cons of programming ROS in Python

  • It runs slower. Python is an interpreted language, which means that it is compiled in run time, while the program is being executed. That makes the code slower.
  • Higher chances of crashing in run time, that is, while the program is running on the robot. You can have a very silly mistake in the code that won’t be cached until the program runs that part of the code (in run time).
  • Unless you define very clear procedures, you can end with a messy code in a short time if the project grows. I mean, you need to impose some rules for developing, like indicating every class you import from which library is, force strong types on any definition of a variable, etc.


Programming ROS with C++

Pros of programming ROS in C++:

  • The code runs really fast. Maybe in your project, you need some fast code.
  • By having to compile, you can catch a lot of errors during compilation time, instead of having them in run time.
  • C++ has an infinite number of libraries that allow you to do whatever you want with C++.
  • It is the language used in the robotics industry, so you need to master it if you want to work there.

Cons of programming ROS in C++:

  • C++ is a lot more complex to learn and master. A LOT
  • Just creating a small demo of something requires to create a lot of code.
  • To understand what a C++ program does can take you a long time.
  • Debugging errors in C++ is complex and takes time.


ref : www.theconstructsim.com/learn-ros-python-or-cpp/

'OS & Tools > ROS' 카테고리의 다른 글

ROS 환경에서 CMake Upgrade 방법  (0) 2021.04.04
[ROS] Linux tmux Install & Command  (1) 2020.12.20
[ROS] Learn ROS with C++ or Python?  (0) 2020.12.17
[ROS] Hector SLAM  (0) 2020.03.09