Many different programming languages are used in robotics. The choice depends on the individual experience of the programmer but also on the problem to be solved. This article describes the most important programming languages and shows in which areas of robotics they are commonly used. At the end of this article we will discuss which programming language you should learn as a beginner.
Note: This is a simplified overview that tries to give some orientation. Keep in mind that nothing of this is set in stone as you can achieve the same task with multiple different languages.
1. C/C++
C/C++ can be used in almost any area of robotics but the closer you are to the hardware the more inevitable it becomes. This already starts with the embedded software that usually runs on a microcontroller and directly controls the motors inside the robot joints.
Then there is usually some form of communication that connects the robot hardware to higher level software like the (higher level) controllers. These controllers as well as the motion planning part are also often implemented in C/C++. One reason is that C/C++ is very efficient which is important for implementing algorithms that are often running on machines with limited computing power. It is also important that the execution time is fast as these algorithms have to meet timing criteria (so called real time constraints).
Algorithms that require efficient implementations are also common in the field of Computer Vision. Finally, C++, besides many other languages, is used to do Machine Learning and Deep Learning.
Commonly used in: Hardware-related software, Control, Motion Planning, Computer Vision, Machine/Deep Learning
2. Python
Python is often regarded as a simple to learn but versatile programming language. With an abundance of libraries available for different applications you can can get immediate result .
One example of such libraries is OpenCV for Computer Vision. It is easy to use and you can set up applications for face recognition, object detection, object tracking etc. in no time. Python also has become a popular choice for implementing Machine Learning and Deep Learning applications. Again, there are lots of libraries that have all the common Machine Learning methods implemented. Other ones help you to easily set up a neural network for your Deep Learning approach. There is also libraries for Reinforcement learning if you want to go down that path.
Apart from Computer Vision and AI, Python is a very useful scripting language if you want to automate processes on your computer. All in all it’s always good to have some Python in your toolbox.
Commonly used in: Application, Computer Vision, Machine/Deep Learning, Scripting
3. Matlab
Some people will argue if Matlab is really its own programming language but the fact is that it is widely used in robotics. Probably the most popular use is in developing the robot controllers. It provides a graphical programming environment called Simulink that comes in handy to simulate and analyze complex dynamical systems.
In Matlab you can simulate the controllers you developed and also model the joints of your robot. That way you will see how the joint reacts to the signals coming from the controllers before testing them on the actual hardware. This can prevent hardware damage in the process as even a small error can make your controllers go crazy.
Matlab developers lately also put more emphasis on Computer Vision and Machine/ Deep Learning applications. They provide toolboxes that often contain out-of-the-box solutions that are useful to get something running with close to no effort.
Also, with Matlab you can create oh so beautiful plots:
Matlab is a commercial tool but if you are a student you can get access to free versions. If not, you need to pay quite some money for it.
Commonly used in: Control, Simulation, Computer Vision, Machine/ Deep Learning
4. Java
Java is a high level programming language that is widely used in Artificial Intelligence. Also it is often the go-to language for Computer Scientists that start in robotics.
One of the big advantages of Java is the write once, run anywhere approach. That means when you compile Java code once on your machine you can run it on every other machine that runs a Java Virtual Machine. That way you don’t have to worry about the underlying computer architecture. These attributes make it popular when is comes to higher level applications with a greater level of abstraction.
Commonly used in: Machine/Deep Learning, Higher level applications
Others
Vendor specific languages: Most robot vendors provide their own language for program their robots which is especially important for robot integrators. Some companys offer a graphical way to create robot programs for example by programming movements on a mobile teach pendant. They also have text based languages that are similar to common languages like Pascal or Python. Some robot vendors also offer a C-API to access the robot functionality.
Scratch: A programming language with a visual interface that was developed specifically for children up to the age of 16 to learn computational thinking and problem solving. It is fun and children can start robot programming e.g. with the LEGO Mindstorm series.
Which programming language should you learn?
If you are a beginner in robotics and are wondering which programming language you should learn to start, here is a few thoughts:
I already mentioned that what you will end up using depends on the specific area of robotics you want to work in. Also, you can achieve the same task with a lot of different programming languages so if you already know a language, just start with that one and you will get immediate results.
If you don’t know where to start and seek for suggestions I will give you my personal opinion. Keep in mind however that this is very subjective and other people might have different opinions on this.
The most widely used languages in robotics are C/C++ and Python. These are also the two languages that ROS uses natively. C++ is a powerful language but it is also complex and it might take more time to get into and get something running. If you already have some programming experience however, mastering it is definitely worthwhile (If you want to get started with C++ in robotics check out our tutorials).
Python is very easy to start with and has a great community. You will be able to see results very quickly and there is a ton of tutorials out there. If you are a beginner, use Python.
Also, if you are just starting you should read my article on how to start learning robotics. It shows you the best learning approach and points you to specific resources you can begin with.
Thank you guys for reading and let me know your thoughts on this topic in the comments. Until then, happy coding!