Kshitij Tiwari Ph.D.

Learn programming for robotics

8 min read

In a previous post, I already shared plenty of FREE and Paid resources to help you learn robotics on a budget from the comfort of your homes. And I have already discussed that robotics is an interdisciplinary field so, in this post, we are going to take a deep dive into learning programming for robotics with a special focus on mobile robots as that is my area of expertise. However, the framework can easily be extended and adapted to other robot platforms too. So, let’s look into the various programming languages to learn for robotics.

What does programming for robotics entail?

When it comes to robotics, software and hardware have to work in tandem for the robot to be able to perform desired actions. But, when it comes to software, i.e. programming the robot, there are numerous components that can actually be programmed. For instance, one could program micro-controllers, micro-processers, artificial intelligence, Internet of Things (IoT) and a whole lot more. Each of these components belong a specific level in the hierarchy that makes up a robot. Here is a breakdown from the bottom-up:

  • Low level components: As the lowest level in the hierarchy, these components perhaps have the most important role in commanding and controlling the robot. This includes components like micro-controllers and micro-processors.

  • Mid level components: This could include computing architecture that helps develop a closed-loop ecosystem for the various robotic components to communicate with each other. As a beginner in robotics, you should know that when it comes to computations (typically for perceiving the environment via sensors), not all of the heavy lifting is done onboard a robot. Some heavy duty computations can be shipped off to a nearby base station (a high performance computer) and some basic computations can be done onboard. 

  • High level components: This involves managing and operating the various sensors onboard and programmatically controlling their operational modes. This could be necessary for cases like energy conservation wherein some sensors could be made to sleep or operate on a lower frequency depending on operational conditions and so on.

How to learn programming for robotics?

In keeping with the three levels of components we mapped, let us look closer into the programming languages to learn for robotics, respectively.

    • Low level programming: When it comes to learning programming for low level robotics components, we are typically referring to micro-controllers and micro-processors. One of the most prominent micro-controller is an Arduino board whereas a popular micro-processor would be the Raspberry Pi.

      One needs to understand that there is a difference in functionality of a micro-processor vs micro-controller and hence, there is a difference in learning to program them as well. A micro-control is used to manage the electronics whereas a micro-controller is like a mini computer and it’s processing power can be used for automations, data logging, build lightweight AI models and so on.

      Micro-controllers like Arduino are typically programmed in C and the programming tasks are typically using various communication protocols and operating electronics like servo motors, LEDs etc. There is a great community for programming with an Arduino board and a lot of the open source code can be used to save up deployment time. As for the micro-processors like Raspberry Pi, typically C++/ Python can be used and their tasks are commonly, managing multiple micro-controllers, data logging, executing state machines, if any and so on.

    • Mid level programming: Now that you are able to send control commands to your robot via micro-controller and generate basic behaviors via micro-processors, it’s time to scale things up. One very powerful tool utilized in robotics is the Robot Operating System (ROS) which is a framework to implement various behaviors of a robot in a distributed fashion. Prominent programming languages used in ROS are C++ and Python and sometimes external libraries are also written in C#.

      The agile and distributed framework of ROS means that you do not have to do all things in one place. You could do partial analysis onboard, partially on a base station, or even distribute the work load among various robots on a team. ROS helps plan, manage and deploy all such distributed computations and has a lot of open source code one could utilize that already solve some of the most common robotics challenges.

      While ROS is quite prevalent in academia, not everyone in the industrial setting would use ROS and some might even rely on proprietary software stacks. Though, knowing ROS might come in handy even in such settings as you would have experience with an entire ecosystem and you could always adapt.

    • High level programming: High level programming in robotics includes tasks such as cloud-based applications and web-apps to control the robots. This is especially useful when you plan to ship off your robot to an end user who isn’t really programming-savvy but needs to be able to deploy the robot platform with little to no training.

      So, you could develop intuitive graphic user interfaces, mobile apps, web apps and the likes for them to drag-and-drop or click on buttons to get the robot to do the desired tasks while the robotic software executes under the hood. As this might involve interfacing with the web, assuming you are building your ecosystem via ROS, you would then need to rely on ROS bridge to connect to the internet and then some Java scripts for the web app.

As a quick recap, depending on whether you want to specialize in low, mid or high level programming in robotics, you would have to learn one or more of the following programming languages: C#, C++, Python, Java. And, you could also start learning ROS as the underlying ecosystem.

Program your 1st hobby robot

One of the most effective ways to learning programming for mobile robots is to program an actual robot.

You might be wondering that this is something that would require $$$ for you to be able to purchase your robot.

Turns out, this isn’t always the only option and you can always learn robotics on a budget. Purchase one of the budget-friendly hobby kits to build your 1st DIY robot platform. If you are unsure which type of robot platform to opt for, I would recommend starting your robotics journey with a simple line follower robot.

Then you should incrementally increase the complexity of the build by adding more sensors, better hardware and even employing Robot Operating System (ROS) to plan and manage your entire software stack.

Key takeaways

The aim of this article was to show you how you can learn robotics programming and to explain the various programming languages for robotics. As you can see, there are numerous components of a robot that can be programmatically controlled and each might require a different programming language. So, you need to hone in on the components that you would like to master. Also, without programmatic control over such components, a robot would essentially be a piece of metal that can’t really do anything so programming is a crucial building block of the interdisciplinary field of robotics.

Aside from the programming languages for robotics mentioned above, there are also Pascal, Scratch, Industrial Robot Language, Hardware Description Language (HDL), LISP and Prolog. However, these might be needed only in specific use cases and the programming languages mentioned earlier would suffice for most academic use cases. Additionally, there is also growing trend for block-based coding wherein there are preset behaviors which you can drag and drop to form a behavior chain. However, such methods are typically limited in what a robot can achieve and hence, are mostly beneficial for young learners to gain exposure to STEM learning and robotics programming.

Related resources