Top programming languages for mobile robots

Find out which of many programming languages are commonly used in robotics.

May 12, 2023

by

Aleksandra Szczepaniak

Leo Rover JavaScript

Programming languages are an inherent part of a computer’s performance as thanks to them, the device can properly and efficiently execute its tasks. There are many programming languages out there but we’re going to focus on the ones that are most commonly used in robotics, especially in mobile robots like the Leo Rover platform.

C

C is a major general-purpose programming language used in the field of robotics. It’s commonly applied to develop operating systems, databases, embedded systems, micro-controllers among many other things. It comes with a broad array of libraries, tools, and features handy in robotics. A lot of programming languages that were developed later, such as Java or JavaScript, rely on syntax or features borrowed directly or indirectly from the C programming language.

Among the key features of C are the following:

  • procedural language – instructions are executed step by step,
  • speed – C operates faster than many other common programming languages including Python or Java,
  • low-level memory access,
  • clean style,
  • simple set of keywords.

C++

C++ was developed as an extension of the C language in order to incorporate object-oriented paradigm. This aids in creating extensible and maintainable programs. C++ is an imperative and compiled programming language, which contributes to the speed and safety of its execution. It’s good for a program’s efficiency and little memory usage. Since it’s derived from C, the syntax and structure code of both is nearly the same.

Other notable features of the C++ programming language include:

  • simplicity – programs can be broken down into logical parts and units, there’s rich library support and various types of data,
  • mid-level language – as a mid-level language, C++ allows for both system-programming and building large-scale user apps,
  • rich library support – the C++ language has a rich library support and third-party libraries for fast development,
  • pointer and Direct Memory Access – C++ offers pointer support to facilitate directly manipulating  storage addresses directly, which helps in low-level programming.

The use of the C++ programming language can be found, for example, in operating systems and systems programming, browsers, cloud/distributed systems, game engines and graphics, database engines and the like.

C++ can be used to interface with ROS through roscpp – the most widely used ROS client library.

Python

Leo Rover's object detection script in Python
The Leo Rover's object detection script in Python

Python is a clear and potent object-oriented programming language. Compared to other leading languages, Python uses fewer lines of code which makes it much easier to write in. In addition, it contains an array of libraries for basic functions. It’s suitable for writing algorithms for high-level features that don’t need to be written efficiently, but readably. The language’s key goal is to ease and speed up programming.

Python occupies a high position among the best programming languages for robotics as in it, each element can be made, altered, or deleted. To complete a command, Python uses new lines, unlike other programming languages that often use parentheses or semicolons.

Other noteworthy features of Python include:

  • elegant syntax which translates to easy readability of the program you write,
  • possibility to be easily expanded by adding new modules applied in compiled languages such as C or C++,
  • running on various platforms including Linux, Windows, Mac, Raspberry Pi, to name a few,
  • code that can be grouped into packages and modules,
  • various basic data types: numbers, strings, lists, and dictionaries,
  • dynamically typed data types. Mixing incompatible types results in raising an exception, so that errors are detected sooner,
  • state-of-the-art programming features including generators and list comprehensions,
  • automatic memory management that saves you from having to manually allocate and free memory in your code,
  • interpreter system thanks to which the code can be executed right after it’s been written. This adds to fast prototyping.

Python is widely used in web development, machine learning, web framework, image processing, and also in technologies applied in the software industry. Python is well tailored for beginners, but is also in common use by experienced programmers.

Alongside C++, Python is the other main programming language used in ROS, having its own ROS client library – rospy

Java

Java is a powerful, general-purpose programming language. It includes all the high-level features required in the robotics industry, particularly those related to AI. It enables to create very efficient algorithms used for machine learning, language processing, and so on.

Some major features of Java are as follows:

  • operation based on the WORA concept – write once, run anywhere – which means that developers can run the compiled Java code on any platform equipped with Java Virtual Machine (JVM) without recompiling,
  • various APIs to meet the robot’s requirements,
  • syntax similar to that of the C and C++ languages but with fewer low-level features, 
  • codes written in the form of objects and classes, 
  • runtime providing runtime code modification and reflection and other dynamic capabilities, which is not typical of standard compiled languages.

Compared to Python and C++, it can be said that Java lies somewhere in between. Java programs tend to run faster than their equivalent Python programs but slower than the C++ ones. Similarly to C++, Java performs static type checking while Python doesn’t.

Java is used for developing desktop and mobile applications, embedded systems, big data processing, games, web servers, database connection and so on.

C#

C# is a modern, general-purpose, and object-oriented programming language. It’s one of the languages in the Common Language Infrastructure. C# runs on the .NET framework and is highly flexible. 

C# comes with an array of exceptional features including: 

  • faster development time – some of the language features like versatile, bug-free data types and ability to reuse components speed up development. C# also provides a variety of components and a vast library of high-level features for quickening any project,
  • high scalability – thanks to static coding, programs of C# are reliable and can be easily changed and tweaked. This allows engineers to quickly make adjustments and create on top of any C# program to extend its functionality,
  • gentle learning curve – C# is easy to learn and understand. Plus, it shares many similarities with Java in terms of syntax and is also easy for users familiar with C and/or C++ as it derives from the C family of the programming languages,
  • large community – as one of the most popular programming languages, C# gathers developers from around the world willing to help out other users. Also, it offers the support of Microsoft.

The C# programming language is mostly used for web and game development and Windows apps among other things.

Rust

Rust is a general-purpose, multi-paradigm, statically-typed programming language. It was designed for performance and safety, in particular, safe concurrency and memory management. Originally, Rust was developed as an open-source project at Mozilla Research. 

The language’s syntax is similar to that of C++. A key advantage of Rust is that it addresses the issues that C/C++ developers have been struggling with for a long time, such as concurrent programming and memory errors. 

There can be pointed out 3 main strong assets of Rust:

  • performance – the language is fast and memory efficient. It enables users to power performance-critical services that run on embedded devices, and integrate easily with other languages without garbage collector or runtime,
  • reliability – Rust ensures memory and thread safety allowing to get rid of multiple classes of errors at compile-time,
  • productivity – it provides very good documentation, excellent tools including smart multi-editor support, integrated package manager and build tool among many others.

Recently, Rust has gained notoriety and is getting more and more popular with the robotics developers, slowly becoming a substitute for C++.

JavaScript

Leo Rover's UI script in JavaScript
The Leo Rover's UI script in JavaScript

JavaScript belongs to one of the key web technologies, right next to CSS and HTML. It’s a versatile, dynamic, lightweight programming language with object-oriented capabilities. It’s also considered an interpreted programming language as the compilation is performed at run-time. 

JavaScript is used both on the server and client sides. When it comes to the server side, node.js is used. On the client side, the code is executed and displayed by the browser. 

Some of the JavaScripts key features include the following:

  • event-based programming – JavaScript enables users to write codes that are performed differently for different events,
  • less interaction with the server – the input can be verified before sending the page to the server, which saves server traffic,
  • platform independence – the codes of JavaScript are run in browsers. Thus, regardless of the device, the code can be run on any browser provided that it supports JavaScript,
  • instant feedback for visitors – there’s no need to wait for a page to reload to see if everything was entered.

JavaScript is mostly used for creating dynamic webpages and network-centric applications. All leading web browsers run on a dedicated JavaScript engine to execute the code on user’s devices. 

What programming languages do we use in the Leo Rover?

Given that the languages listed above are widely popular in robots, you won’t be surprised that some of them found their use in the Leo Rover robotic platform. Let’s see which ones :).

The Leo Rover’s user interface, about which you can read here, is written in JavaScript along with CSS and HTML. 

The firmware, i.e. the code that is running on the motor controllers LeoCore or Husarion CORE2 (depending on the Rover iteration you have), is written in C and C++.

Various other components developed by us that run on the Raspberry Pi are written primarily in Python. In instances where speed is critical, the components are written in C++.

Also, a lot of software used in Leo Rover is provided by open-source packages available in the ROS ecosystem that we contribute to when needed.

Develop your skills and your robot

Knowing your way around programming is a must in robot development. And the more programming languages you know, the more doors to a career in the robotics industry you can open for yourself. Even if you're programming just for personal needs, it’s always good to brush up your skills so that your machine can perform even better. And if you’ve just started your adventure with robotics, check out our article on challenges with robot development :).

Want to see more posts like that?

Subscribe to stay informed.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

See more blog posts:

<- get back to the Blog