Intro to Robotics Programming: Part 1
Posted: March 19, 2016
Introduction to the Series
Robots are awesome. But robotics as a discipline is both broad and deep, and without guidance it's almost impossible to know where to get started. I'm often asked how best to get started with robotics, so throughout this series of articles, I will introduce you to the world of robotics programming. We will use Python for simplicity, and work in pure simulation to learn the concepts and techniques that give robots the ability to do all the amazing things that they do. Many of the topics will be difficult, but I'll try to keep the explanations clear and intuitive, and the examples interesting.
Components of a Robotics Software System
A robotic system is composed of many layers, all coordinated to enable the robot to accomplish some task in the physical world. We will look at these layers one by one to build up a simple but functional robotic system. But first, let's look at an overview.
Robots, walls, bottles, and and other objects all have physical properties that make them what they are. Roboticists usually employ Rigid Body Dynamics to model objects and their interactions. What this means is objects are considered inflexible (no bending or soft objects), and we can describe their behavior as an exact and straightforward function of time. In these articles, we will mostly be concerned with the kinematics of objects, rather than their dynamics. In other words, shape rather than mass and mass distribution.
You have to represent your robot and other physical objects in software. You'll need to plan movements, and may want to "try out" a movement in simulation before committing your expensive robot to a potentially dangerous action. We call this representation the world or environment. The most important function of the world is to maintain a mapping of all objects and their locations in some frame of reference.
The simulation could be as simple as a list of objects and properties along with some simple functions, up to a full blown physics simulator. We shall see many ways to represent and use the simulated environment.
The main use of the simulation environment is collision detection. You don't want to break your expensive robot, so you need a way of predicting that you may hit something. The great the number and more complex the objects involved the more difficult this becomes. In real robotic simulations and planning, collision detection often accounts for over 90% of the computation time. We will look at some simple collision detection techniques for 2D objects, and rely on libraries for more complex tasks.
Once we have a way to simulate actions, we can make plans for how to accomplish our goal.
Finding a path to drive from
goal is like solving a maze, generally involving clever graph search algorithms.
This becomes even more complicated when we try to grasp objects or position our hand, requiring solving some very
difficult equations or optimization problems, as well as searching through very high dimensional configuration spaces
that include the position of every object and every joint in the world.
Humans take for granted that we can identify objects in the world, but we've had millions of years of biological evolution to get it right. How can a robot identify whether it is looking at a a fork or a spoon? Or a picture of a spoon? How does a robot know where it is in the world? We could tell it explicitly, but at some point you probably want your robot to figure this out on its own. We will look at how robotic perception systems work, and what kinds of sensors they use. We will briefly review the field of computer vision, and use libraries to process image data for useful information.
Simulation is all well and good, but eventually you probably want to see your robot move. We will look at the field of control theory, and implement the simplest and most common kind of controller in simulation! Wait, what? Trust me, we'll get there.
Finally, because our weak human brains have trouble with all the crazy math required to represent the mechanics of movement, we will want to visualize our environment and many of our planners. We'll use a simple graphics library to let us see exactly what is going on as we simulate our robot.
Once we've mastered the basic techniques, we'll have uncovered the enormous complexity of robotics. At that point, we probably won't want to keep writing our own glue code and wrappers for every single thing we want to accomplish, and we'd like the help of high quality libraries wherever we can. So I'll introduce ROS (Robot Operating System), a framework for robotics platforms with many many libraries targeting it, and recommend some more powerful libraries and frameworks for you to continue your journey.
What We Won't Cover
Despite the long list of topics above, we're still only going to scratch the surface of robotics technology. But perhaps most notably, I won't be talking about any hardware programming. Embedded systems are very interesting to program, but there are now many resources dedicated to embedded programming thanks to the popularity of platforms such as Raspberry Pi, Arduino, and BeagleBone.
There are some prerequisites for this course. First, robotics happens on Linux. We're starting small with Python and some popular open source libraries, so although I cannot guarantee the instructions or code provided here will work on anything but the latest Ubuntu LTS (14.04 Trusty Tahr at the time of this writing), it is possible that the code may run on OSX or Windows. However, if you don't have Linux, I recommend you setup an Ubuntu virtual machine using VirtualBox or another VM of your choice.
We will primarily be using Python, so while you may pick it up from these articles, I'm not concerned with teaching it. I will assume good working knowledge of the language, and focus on the robotics. Later, we will introduce some C++ where it may be beneficial to future learning.
Finally, all the code for these articles is available at https://github.com/clintliddick/robotics_intro. Each article will mention if there is something you should attempt yourself before looking into the source for answers.
Hopefully this has piqued your interest, and you're excited to see some code and play with a robot. In the next article, we'll jump right in with an overview of the software and general application structure we'll be using, and we'll build our first robot.
Next article: Part 2