A beginner’s guide to robot programming with Python


Let’s face it, robots are cool. They’re also going to run the world some day, and hopefully, at that time they will take pity on their poor soft fleshy creators (a.k.a. robotics developers) and help us build a space utopia filled with plenty. I’m joking of course, but only sort of.

In my ambition to have some small influence over the matter, I took a course in autonomous robot control theory last year, which culminated in my building a Python-based robotic simulator that allowed me to practice control theory on a simple, mobile, programmable robot.

In this article, I’m going to show how to use a Python robot framework to develop control software, describe the control scheme I developed for my simulated robot, illustrate how it interacts with its environment and achieves its goals, and discuss some of the fundamental challenges of robotics programming that I encountered along the way.

In order to follow this tutorial on robotics programming for beginners, you should have a basic knowledge of two things:

  • Mathematics—we will use some trigonometric functions and vectors
  • Python—since Python is among the more popular basic robot programming languages—we will make use of basic Python libraries and functions

The snippets of code shown here are just a part of the entire simulator, which relies on classes and interfaces, so in order to read the code directly, you may need some experience in Python and object oriented programming.

Finally, optional topics that will help you to better follow this tutorial are knowing what a state machine is and how range sensors and encoders work.

The challenge of the programmable robot: perception versus reality, and the fragility of control

The fundamental challenge of all robotics is this: It is impossible to ever know the true state of the environment. Robot control software can only guess the state of the real world based on measurements returned by its sensors. It can only attempt to change the state of the real world through the generation of control signals.

This graphic demonstrates the interaction between a physical robot and computer controls when practicing Python robot programming.