The word robotics can mean a lot of things. For some people, it is anything that moves by itself; kinetic art is robotics. To other people, robotics means something that is mobile or something that can move itself from place to place. There is actually a field called mobile robotics ; automatic vacuum cleaners, such as a Roomba or a Neato, fall into this category. To me robotics falls somewhere in between kinetic art and mobile robotics.
A robot is technology that applies logic to perform a task in an automated manner. This is a fairly broad definition, but robotics is a fairly broad field. It can cover everything from a childs toy to the automatic parallel parking capabilities in some automobiles. We build a small mobile robot in this book.
Many of the principals that you are exposed to in this book are easily transferable to other areas. In fact, we will go through the entire process of building a robot from beginning to end. A little later in this chapter, I go over the project that we will build. At that time, I will provide a list of the parts used in in this book. These parts include sensors, drivers, motors, and so forth. You are welcome to use whatever you have on hand because, for the most part, everything we go through in this book can be applied to other projects.
Robotics Basics
I like to tell people who are new to robotics, or are just robotics curious, is that a robot consists of three elements .
The ability to gather data
The ability to process, or do something with the gathered data
The ability to interact with the environment
In the following chapters, we apply this principal to build a small mobile robot. We will use ultrasonic rangefinders and infrared sensors to gather data about the environment. Specifically, we will identify when there is an object to be avoided, when we are about to drive off the edge of a table, and the contrast between the table and the line that we will follow. Once we have this data, we will apply logic to determine the appropriate response.
We will use Python in a Linux environment to process the information and send commands to our motors. I chose Python as the programming language because it is easy to learn, and you dont have to have a complex development environment to build some pretty complex applications.
Our interaction with the environment will be simply to control the speed and direction of motors. This will allow our robot to move about freely on the table or floor. There really isnt much to driving a motor. We will look at two ways of doing it: with a motor driver made for the Raspberry Pi and with a common motor controller.
This book is intended to be challenging. I cover some pretty complex material and I do it quickly. There is no way that I can provide detailed coverage on any of these topics, but I hope to get you to a functional robot by the end of the book. In each chapter, I try to provide you with more resources to follow up on the topics discussed. You will struggle at times; I did and I frequently still do.
Not everyone will be interested in all the subjects. The expectation is that you will expand on the areas that interest you the most outside of this book. Persistence pays off.
At the end of the book, I add a little more challenge. In Chapter .
Linux and Robotics
Linux is a Unix-based operating system. It is very popular with programmers and computer scientists because its simple and straightforward. They seem to enjoy the text-based interface of the terminal. Yet, for many others, including me, Linux can be very challenging. So, why in the world would I choose this environment for an introduction-to-robotics book? The answer to that question is threefold.
First, when you work with robotics, you eventually have to confront Linux. Thats just a fact. You can do a lot without ever typing a single sudo command, but you will have limited capabilities. The sudo command stands for super user do in Linux. This tells the operating system that you are about to perform a protected function that requires more than general user access. You will learn more about this when we begin working with the Raspberry Pi.
Second, Linux is challenging. As I stated before, this book will challenge you. If you have worked in Linux before, then this reason doesnt apply to you. However, if you are new to Linux, the Raspberry Pi, or working in a command line, then some of the things that we do will be challenging. And thats good. Youre learning something new and it should be a challenge.
Third, and this is by far the most important, the Raspberry Pi uses Linux . Yes, you can install other operating systems on the Pi, but it was designed and intended to use Linux. In fact, the Raspberry Pi has its own flavor of Linux called Raspbian . This is the recommended operating system, so it is what well use. One of the nice things about using a prebuilt operating system, besides its ease of use, is many of the tools are already installed and ready to go.
Since we are using Linux, we will use command-line instructions extensively. This is where most new users have problems. Command-line code is entered via a terminal. Raspbian has a Windows-style interface that we will use, but much of it uses the terminal. A terminal window is available in the graphical user interface (GUI) , so we will use that. However, when we set up the Pi, we will set it up to boot into terminal mode by default. Getting to the GUI is only a simple startx command. All of this is covered in Chapter .
Sensors and GPIO
GPIO stands for general-purpose input/output . It represents all the various connections to devices. The Raspberry Pi has a lot of GPIO options: HDMI, USB, audio, and so forth. However, when I talk about GPIO in this book, Im generally referring to the 40-pin GPIO header. This header provides direct access to most of the boards functionality. I discuss this in Chapter .
Arduino also has GPIO. In fact, one could argue that Arduino is all GPIO and nothing else. This isnt far from the truth given that all the other connections are there to allow you to communicate with and power the AVR chip at the heart of the Arduino.
All of these headers and GPIO connections are there so we can access sensors outside the boards themselves. A sensor is a device that gathers data. There are many different types of sensors, and all serve a purpose. Sensors can be used for detecting light levels, the range to an object, temperature, speed, and so forth. In particular, we will use GPIO headers with an ultrasonic rangefinder and an IR detector.
Motion and Control
One thing that most definitions of a robot have in common is that it needs to be able to move. Sure, you can have a robot that doesnt actually move, but this type of device generally falls under the moniker of IoT , the Internet of Things.
There are many ways to add motion to your project. The most common is the use of motors. But you can also use solenoids, air, or water pressure. I discuss motors more in Chapter .
Although it is possible to drive a motor directly off a Raspberry Pi or an Arduino board, it is strongly discouraged. Motors tend to draw more current than the processors on the boards can handle. Instead, it is recommended that you use a motor controller. Like motors, motor controllers come in many forms. The motor control board that we will use is accessed through the Raspberry Pis header. I also discuss how to drive motors with an L298N dual motor controller.