Book Image

Learn Robotics Programming

By : Danny Staple
Book Image

Learn Robotics Programming

By: Danny Staple

Overview of this book

We live in an age where the most difficult human tasks are now automated. Smart and intelligent robots, which will perform different tasks precisely and efficiently, are the requirement of the hour. A combination of Raspberry Pi and Python works perfectly when making these kinds of robots. Learn Robotics Programming starts by introducing you to the basic structure of a robot, along with how to plan, build, and program it. As you make your way through the book, you will gradually progress to adding different outputs and sensors, learning new building skills, and writing code for interesting behaviors with sensors. You’ll also be able to update your robot, and set up web, phone, and Wi-Fi connectivity in order to control it. By the end of the book, you will have built a clever robot that can perform basic artificial intelligence (AI) operations.
Table of Contents (21 chapters)

Writing the line-following behavior

Now we are ready to build a more interesting behavior. However, for the same reasons covered in Chapter 7, Drive and Turn - Moving Motors with Python, we now want to add our sensors into the robot object. This means that, on a different robot with sensor on different pins, or regardless of the pull up configuration, the behavior written on top of the robot layer will still work. We will add the sensors to this, then create the line-following behavior.

Adding the sensors to the Robot object

Open up robot.py from the last chapter. In the imports section, we will want the LineSensor object from GPIO Zero:

from gpiozero import LineSensor

In the constructor, the __init__ method for the robot...