Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Raspberry Pi Embedded Projects Hotshot

You're reading from  Raspberry Pi Embedded Projects Hotshot

Product type Book
Published in Feb 2015
Publisher
ISBN-13 9781849696227
Pages 250 pages
Edition 1st Edition
Languages
Concepts

Table of Contents (20) Chapters

Raspberry Pi Mechatronics Projects HOTSHOT
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Hello World A Raspberry WebIDE Example The Arduino Raspberry Pi Interface Christmas Light Sequencer Internet of Things Example – An E-mail Alert Water Fountain Raspberry Pi as a Personal Assistant Raspberry Pi-based Line Following Robot Connect Four Desktop Game using Raspberry Pi The Raspberry Pi-enabled Pet/Wildlife Monitor Raspberry Pi Personal Health Monitor Home Automation using Raspberry Pi Using a Raspberry Pi for Science and Education Tips and Tricks Index

Chapter 7. Raspberry Pi-based Line Following Robot

In this project, we will build a line following robot that is controlled by your Raspberry Pi.

Note

It is absolutely not necessary to make use of the Raspberry Pi to build a line following robot unless you are using a camera to follow the line. We are building this robot to demonstrate an example of building a mechatronic system using the Raspberry Pi.

Mission briefing


In this project, we will build a line following robot that will follow a black line against a white background. The robot will make use of a pair of infrared sensors to track the orientation of the robot and drive the robot accordingly.

A line following robot

Why is it awesome?

The Pi, as you have seen in the last few projects, offers you immense functionality and many advantages over microcontrollers. You can bring this power and smaller footprints to robotics. So, we are getting you started off with the line following robot. Once you get this under control, the possibilities are endless, making this an awesome segue into robotics and beyond.

Your Hotshot objectives

In this project, we will build the line following robot in the following steps:

  • Assembly of the Pi Plate for the line following robot

  • Sensor selection, interfacing sensors, and data interpretation

  • Implementation of line following logic based on sensor data

  • Testing the motor driver circuit

  • Preparation of the line following...

Assembly of the Pi Plate for the line following robot


Note

The Pi Plate is necessary only if you are going to build your own circuitry (instead of an off-the-shelf robot kit) that drives the robot.

We will make use of the Pi Plate from Adafruit Industries. The Pi Plate is stackable and an add-on hardware for the Raspberry Pi. The Pi Plate is like a breadboard/perforated prototyping board and enables prototyping using the Raspberry Pi platform. We will assemble the headers on the board.

Prepare for lift off

The Pi Plate is available from Adafruit Industries (www.adafruit.com). It costs 15.95 USD. This stackable add-on hardware is useful because the sensors and actuators can be connected using the screw-in terminals. This will avoid any loose connections to your Raspberry Pi while the robot is in motion.

Engage thrusters

  1. The contents of the Pi Plate package are as follows:

    Contents of a Pi Plate package

    Note

    Adult supervision is required for soldering and putting the Pi Plate together.

  2. The Pi Plate...

Sensor selection, interface, and data interpretation


In this task, we will discuss the different sensors available to build a line following robot and pick a sensor for this project.

Engage thrusters

We will discuss three sensors in this task, including light detecting resistors, IR emitters/detectors, and a camera. We will discuss their operations, features, and their distinct edge over other sensing techniques as well as their disadvantages.

Light Dependent Resistors

As the name suggests, Light Dependent Resistors are those that change their resistance when light is incident on the surface of the resistor.

Light Dependent Resistors are used in combination with a bright LED. We can make use of the difference in reflectivity between different coloured surfaces to follow a black line on a dark surface.

When Light Dependent Resistor is inserted into a potential divider configuration, as shown in the following diagram, the drop in voltage causes a potential imbalance leading to a change in voltage...

Implementation of line following logic based on sensor data


In this task, we will implement a simple line following technique using the infrared sensor. We will make use of a pair of infrared sensors to track a black line on a white surface. The robot will move forward if both the sensors are on a white surface. The robot turns left if the left sensor is on the black line and vice versa.

Prepare for lift off

The sensor needs to be soldered and connected to the Raspberry Pi (something like the one shown in the preceding schematic). Alternatively, you may use a sensor of your choice.

Engage thrusters

  1. As always, we will get started by importing the required modules, especially Rpi.GPIO:

    import RPi.GPIO as GPIO
    from time import sleep
  2. We will set the pin configuration that we will use in this program:

    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(18,GPIO.IN)
    GPIO.setup(25,GPIO.IN)
  3. The control logic explained earlier is implemented as follows:

    state = 1
    prev_state = 0
    while True:
      #both sensors...

Testing the motor driver circuit


In this project, we will use a pair of DC motors to drive the robot. We will use a dual H-bridge (SN754410) driver to control the DC motors. We will use a software PWM library written for the Raspberry Pi. We chose DC motors for the following reasons:

  1. DC motors are easy to operate and control using an H-bridge interfaced to the Raspberry Pi.

  2. There is a software PWM library that makes it easier to control the DC motors.

In this task, we will implement the DC motor control circuit and also write a program to control the DC motors.

Prepare for lift off

We will use the software PWM function available with RPi.GPIO. The software PWM function is available on versions greater than 0.5.3. We need to determine the RPi.GPIO version installed on the Raspberry Pi using a command-line terminal:

python
import RPi.GPIO
RPi.GPIO.VERSION

If the returned value is earlier than 0.53, the package can be updated as follows:

sudo apt-get update
sudo apt-get upgrade

We will be making...

Preparation of the line following course


In this task, we will prepare the line following track for the robot.

Prepare for lift off

There are two approaches to building a line following track. They include the following:

  1. Print a track available from Parallax and set it on top of a posterboard.

  2. Use electrical tape and build a track using a tutorial from Pololu.

The following items are required to complete this task:

  1. A posterboard

  2. A permanent marker

  3. A pencil

  4. A ruler

  5. A4 sheets

Engage thrusters

  1. We will use a readily available line for the following track (http://www.parallax.com/sites/default/files/downloads/28136-S2-PrintableTracks.pdf) designed for the Scribbler line following robot from Parallax. The line following track from Parallax consists of 10 individual pieces of track that can be arranged and customized according to our needs.

  2. We will get started with printing two sets of the track available along with this project's downloads and arrange them according to our needs and determine the complicity...

Designing the chassis for the line following robot


In this task, we will design the chassis for the line following robot. There are several options available in terms of design tools for the design of the chassis. We chose Autodesk Inventor, but there are a lot of tools such as Autodesk 123D and so on.

Prepare for lift off

The chassis for the robot is fabricated using the laser cutting technique. You are welcome to fabricate your own chassis. We have chosen to use laser cutting because it is the easiest to complete. The technique involves designing the chassis followed by preparing the design for fabrication and laser cutting.

You may download the design file available along with this project and use it for laser cutting. There is a trial version of Autodesk Inventor available for download and it can be installed and used for designing a custom chassis.

As a maker/hacker, it is important that you learn how to use these tools and how to design a chassis.

Note

The use of tools such as a laser cutter...

A step-by-step assembly of the robot


In this task, we will assemble the robot in simple steps that are accompanied by a photographical representation.

Prepare for lift off

We need to have the following parts ready to assemble the robot:

  1. Top and bottom chassis plates for the line following robot

  2. Infrared sensors

  3. A pair of #2 screws and nuts (washers optional)

  4. A ball caster assembly with screws from Pololu

  5. 2*M2.5 screws for mounting the Raspberry Pi (washers optional)

  6. 4*#6 1-inch screws with spacers (washers optional)

  7. A Raspberry Pi

  8. Velcro

  9. Battery

  10. 2 DC motors

  11. Double-sided tape

  12. A Pi Plate

  13. A motor driver

Engage thrusters

  1. We will get started by mounting the castor wheel.

    Mounting the castor wheel

  2. We will mount the Raspberry Pi using M2.5 screws.

    Raspberry Pi mounted using M2.5 screws

  3. This is followed by the DC motors coupled with wheels using the double-sided tape. The DC motors with a plastic gearbox from Pololu do not come with a mounting hole, and hence, we will use double-sided tape to mount the motors. Similarly...

Mission accomplished


In this project, we built a line following robot step by step. We got started with the sensors followed by motor control, chassis design, arena design, and integration. Now, we have a line following robot.

A line following robot on the arena

Hotshot challenge


In this project, we did not make use of any motor control algorithm (like PID) to steer the robot. How do we implement one?

References

The Pololu tutorial on Building Line Following and Line Maze Courses can be found at http://www.pololu.com/docs/0J22

The Advanced Line Following with 3pi: PID Control tutorial can be found at http://www.pololu.com/docs/0J21/7.c

The Parallax line following track: http://www.parallax.com/Portals/0/Downloads/docs/prod/robo/scribbler2/Tracks.pdf

lock icon The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi Embedded Projects Hotshot
Published in: Feb 2015 Publisher: ISBN-13: 9781849696227
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}