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.
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.
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...
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.
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.
In this task, we will discuss the different sensors available to build a line following robot and pick a sensor for this project.
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.
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...
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.
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.
As always, we will get started by importing the required modules, especially Rpi.GPIO
:
import RPi.GPIO as GPIO from time import sleep
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)
The control logic explained earlier is implemented as follows:
state = 1 prev_state = 0 while True: #both sensors...
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:
DC motors are easy to operate and control using an H-bridge interfaced to the Raspberry Pi.
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.
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...
In this task, we will prepare the line following track for the robot.
There are two approaches to building a line following track. They include the following:
The following items are required to complete this task:
A posterboard
A permanent marker
A pencil
A ruler
A4 sheets
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.
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...
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.
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.
In this task, we will assemble the robot in simple steps that are accompanied by a photographical representation.
We need to have the following parts ready to assemble the robot:
Top and bottom chassis plates for the line following robot
Infrared sensors
A pair of #2 screws and nuts (washers optional)
A ball caster assembly with screws from Pololu
2*M2.5 screws for mounting the Raspberry Pi (washers optional)
4*#6 1-inch screws with spacers (washers optional)
A Raspberry Pi
Velcro
Battery
2 DC motors
Double-sided tape
A Pi Plate
A motor driver
We will get started by mounting the castor wheel.
We will mount the Raspberry Pi using M2.5 screws.
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...
In this project, we did not make use of any motor control algorithm (like PID) to steer the robot. How do we implement one?
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