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)

Using the light strip for debugging the line follower robot

Now we get to use these for some fun. We have our line follower robot kind of working, and it does have the LEDs underneath on the sensors, but we are now able to modify the line follower code to light up red when it it crosses the line and blue when it goes off the line.

Line follower basic LEDs

First open up the line_following_behavior.py code from the last chapter. After the imports, add the following new code (in bold):

from robot import Robot
from time import sleep

cross_line_color = (255, 0, 0)
off_line_color = (0, 0, 255)
...

We've added a couple of preset colors. Note I've not used the color names here, but names for their purpose. I can then tune the...