Making Robots With The Arduino part 6.pdf
(
1168 KB
)
Pobierz
Servo 2011-04.pdf
Making Robots
With The
ARDUINO
By Gordon McComb
Part 6 -Follow That Line!
You want simple. You want cheap. You want effective. And, of course, you want fun. That
pretty much sums up line following — probably the simplest of all navigation systems for
mobile robots. The basic idea goes back centuries, and is well known to anyone who’s taken a
train ride. Only in robotics, instead of a mechanical track the vehicle stays on course by shining
a light onto a piece of tape that’s stuck to the floor. Pretty advanced stuff.
factories use line following,
where a predefined path is
marked on the ground. The
path can be a painted black or white
line, a wire buried beneath a carpet, or
any of several other methods. The path
to follow can be changed simply by
peeling off the tape and laying down a
new stripe.
You can easily and
inexpensively incorporate a
tape-track navigation
system in your robot. The
line following feature can
be your bot’s only means
of intelligence, or it can be
just one part of a more
sophisticated machine. You
could, for example, use the
tape to help guide your
robot back to its battery
charger nest. (Beats
clicking your heels three
times and saying, “There’s
no place like home ...”)
So with that in mind, let’s talk
about line following in this installment.
ArdBot Update
Like all expandable robots, the
ArdBot is designed as a permanent work
in progress. It's never truly finished. In
last month's article, I demonstrated a
method of depowering the ArdBot's
Sharp infrared proximity detector, as a
way to conserve power when it's not
needed. As I've refined the Ardbot's
software, I have determined the method
is not necessary. Turns out that in
practice, it slows things down
considerably and introduces as much
signal noise as it eliminates.
If you've been following in the
construction of the ArdBot, just skip the
extra control electronics to the Sharp
sensor and wire it directly. For more
information on this and other
enhancements for the ArdBot, see the
ArdBot Construction Notes at
www.robotoid.com/servomag
.
FIGURE 1.
The ArdBot complete with
all hardware detailed in this and
previous installments.
About This Project
compatible) microcontroller as its brain.
The ArdBot is shown in its fully
“decked out” form in
Figure 1
. The
pictured version incorporates all of the
features we’ve talked about individually
in previous installments, plus the line
following functionality of this month’s
article. The ArdBot can be constructed
out of plywood, plastic, even picture
frame mat board. It’s designed to
As with the previous parts in this
series, this article builds on earlier
issues of
SERVO
, starting with
November ‘10. From there, you’ll find
useful information about building and
programming the ArdBot which is a
low-cost expandable desktop robot
that uses an Arduino Uno (or
34
SERVO 04.2011
N
o, really! Many high-tech
www.servomagazine.com/index.php?/magazine/article/april2011_McComb
allow easy prototyping — it’s a robot
made for your own freedom of
expression.
In last month’s issue, I mentioned
this article would conclude the series.
Well, turns out there was too much to
cover in one last installment. So, this
time around we’ll tackle just the line
following component, and then
conclude with putting all the pieces
together. Next time, we’ll combine
what you’ve learned to create a fully-
capable dual-function robot that
follows predescribed paths, and
explores rooms and seeks out
information about its environment.
detector. Mount them close
to one another, and point
them in the same direction.
All you need to finish the
circuit is a couple of
resistors, as shown in
Figure 3
.
Let’s take a closer look
at the components used in
making a line following
circuit.
Emitter LED and
Current Limiting
Resistor
The electronics for line
following are technically
two separate circuits
connected to the same power source.
The first part is the emitter LED and its
resistor. The purpose of the resistor is
to limit current flowing through the
LED. You select the value of the
resistor based on how much current
you want to pass through the LED. The
more current, the brighter the LED will
glow.
Ideally, the LEDs you use come
with specifications, so you know
things like forward voltage drop and
maximum forward current. With this
info, you can use some simple math
to calculate the value of the resistor
you need. Here’s the formula:
The Basics of
Line Following
FIGURE 2.
Black PVC electrical tape on
white poster board makes an excellent
line following course.
With a line following robot, you
place white, black, or reflective tape on
the floor — the color of the tape is
selected to contrast with the floor.
Using simple optics, the robot then
follows that line.
Black PVC electrical tape absorbs
infrared light, and it’s cheap and easy
to use. So, the most popular method
of making a track is to lay down a path
of electrical tape onto white paper, like
that in
Figure 2
. I prefer using a stiff
poster board that’s coated with a
smooth finish on at least one side. The
coating reflects more light, and helps
prevent the paper from being
transparent to the infrared light. Try
the nearby dollar store for inexpensive
poster board. I get mine for 50 cents a
sheet. Each sheet measures 22 x 28
inches. It comes in colors, but you
want to start out with white.
For the best results, the floor
should be hard, like wood, concrete, or
linoleum, and not carpeted. You can
also use a large table. To sense the
line, optical sensors are placed in front
of or under the robot. These sensors
incorporate an infrared LED (
EMITTER
)
and an infrared phototransistor
(
DETECTOR
). The output of the
phototransistor indicates whether or
not it sees light reflected off the floor.
Assuming a black line on a white floor,
the absence of reflected light means
the robot is over the line.
You can use most any infrared LED
and phototransistor for the emitter and
If you like to buy from surplus
(like I do), you may not have any
specs for the infrared LEDs you use.
Instead, you can apply some educated
guesswork to select a resistor value
that’s close to what you need. I
usually start with a 470
W
resistor, as
this provides enough drive current to
allow the LED to glow, but not so
much that it will burn it out.
Depending on the LED, you may need
to reduce the value of the resistor,
knowing that if you get too low (say,
R = V
in
- V
drop
/ I
f
V
in
is five volts. Assuming V
drop
is
1.7 volts (kinda typical for infrared
LEDs), and a desired 30 mA current,
the formula becomes:
110 = 5 - 1.7 / 0.030
If the result isn’t a standard
resistor value, always choose the next
highest. In this case, 120
W
.
(Notice I
f
is given as a decimal
fraction. The formula expects amps,
but these LEDs are rated in milliamps.
You need to move the decimal point
over to convert amps to milliamps; a
value of 0.030 is 30 milliamps.)
FIGURE 3.
The basic line following
circuitry has two parts: emitter and
detector. Light from the emitter reflects
off a surface and into the detector.
SERVO 04.2011
35
FIGURE 5.
Two “store bought”
reflective sensors mounted on the
leading edge of the ArdBot. They’re
used to follow a 3/4” line made of
black electrical tape.
intensity.
The easiest way to
determine the value of the
resistor is through
empirical testing. Wire the
phototransistor as shown
in
Figure 3
, starting with
a 10 k
W
resistor. Connect
a voltmeter between the
output and ground
connections. Use an
incandescent (not
fluorescent or LED) desk lamp to
alternately shine or block light to the
phototransistor. You should see the
voltage fluctuate on your meter. It
may not be much.
Now try incrementally larger
resistance values until you observe a
good voltage swing — the difference
in voltage between darkest and
lightest conditions. It won’t be the full
zero to five volts of the power supply,
but the larger the difference, the
better. You don’t need (or want) to
select ever-higher resistance values
when a lower one works just as well.
For the phototransistors I used for my
prototype ArdBot, I found good
sensitivity and voltage swing with
100 k
W
resistors.
What if the phototransistor still
doesn’t respond well to light, even
when using very high values? The
phototransistor may be bad, or it may
be connected in reverse. Try flipping it
around in the circuit or select another
one. (See
Figure 4
for how to
determine the leads of the typical LED
and phototransistor. Note that in a
phototransistor, the flatted side/short
lead is usually the collector.)
Like LEDs, phototransistors come
in a variety of package styles. Look for
the same package type you use for
the LED. A phototransistor in a T-1
package has its own built-in lens, and
it’s easy to mount through a hole in
the bottom of your robot.
FIGURE 4.
Detail of a typical LED and
phototransistor T-style package. Use the
short lead and/or flatted side to
determine the pinout.
forward current, so you have a bit of
wiggle room. While the average
visible-light LED might have a
maximum forward current of 30 mA,
the typical IR LED is often rated
higher, some 50 mA or more. (Of
course, there are always exceptions.
For the sake of science, you should be
prepared to blow out an LED now
and then.)
Should you always choose to drive
the LED “hard” with lots of current?
Not necessarily. For one thing, doing
so ends up consuming more battery
power. It can also cause unnecessary
light spoilage — why use a searchlight
when a candle works just as well? To
start, always go with a lower current,
and then decrease the value of the
resistor if your circuit isn’t responsive
enough.
If you have a choice, pick an LED
with a narrow viewing angle. It shines
more light into one spot. The generic
T-1 size (3 mm diameter) water-clear
LED is a good choice. These have a
built-in lens, and are both plentiful
and cheap. They’re also easy to
mount by drilling a 1/8” diameter hole
into the bottom of the robot.
under 150
W
or so), the chances of
burning out the component
dramatically increase.
Fortunately, many IR LEDs are
engineered for fairly high maximum
Is That Infrared LED
On or Off?
H
ow do you know if an infrared LED
is actually emitting infrared light? Your
best bet is to use the camera in your
mobile phone. Most of these cameras
are at least partially sensitive to the
infrared light wavelengths produced by
IR LEDs (typically about 800 to 950
nanometers).
Activate the LED and point the
camera at it. Look at the scene from the
digital viewfinder of the camera. If the IR
LED is working, you’ll see its light as
white or pale blue.
FIGURE A
shows the
infrared emitters mounted on the
underside of the ArdBot. The picture
was taken using an Apple iPhone.
If the camera isn’t picking up
anything, do one last test to ensure it
can see IR light. Point any infrared
remote control at the camera and press
some buttons. You should see a series
of bright flashes.
Phototransistor and
Divider Resistor
FIGURE A.
The second half of the line
follower circuit is composed of a
phototransistor, along with a resistor
that forms a voltage divider. The value
of this resistor depends on the
characteristics of the phototransistor
and the circuit you’re connecting to;
the higher the value of the resistor,
the more sensitive the transistor
becomes to variations in light
Arranging the
Infrared LED &
Phototransistor
The LED emitter and
phototransistor detector should be
mounted side by side, and pointing in
the same direction. To avoid light
“crosstalk” — light that shines from
the side of the LED and directly into
36
SERVO 04.2011
the phototransistor — add
some black heat shrink
tubing around the LED, the
phototransistor, or both. Or,
place a small piece of metal
or opaque plastic between
the two to act as a baffle.
While using separate
LEDs and phototransistors is
the least expensive method
of creating a line following
sensor, an easier approach is
to use an all-in-one reflective
sensor. These come in
various shapes and sizes,
and are fairly common on the surplus
market.
Figure 5
shows a pair of
reflective sensors mounted on the
outside edge of the ArdBot. These
sensors — which I bought surplus who
knows when — provide their own
mounting flange (many do; you just
have to be patient and look around).
They’re easy to use, but because this
style of reflector is bulky, they can’t be
mounted under a low profile robot
such as the ArdBot. Instead, they have
to be placed on the outside edge.
That’s okay, as it demonstrates one of
many ways to perform line following.
Since I’m on the subject of
mounting, reflective sensors like to be
as close to the ground as possible,
while not making actual contact. As
noted in
Figure 6
, the ideal distance
from the sensor to the ground is 1/8”
to 3/8”, depending on the design of
the sensor. I mounted the two sensors
to the underside of the ArdBot using
plastic spacers, in order to decrease
the distance from sensor surface and
floor.
Several online sources offer
unitized emitter/detector modules, like
the QTI sensor from Parallax shown in
Figure 7
. The resistors and all
components are mounted on a small
circuit board. Simply attach wires to
the module: power, ground, and
signal. A single hole allows you to
mount the module almost anywhere
on the robot.
Another variation is the
emitter/detector array which
combines two or more pairs of
infrared LEDs and phototransistors on
a single circuit board. All components
are already on the board, and the
LED/phototransistor pairs are spaced
FIGURE6.
Placement of
the reflective sensors on
the robot. For best results, the
face of the sensors should be
1/8” to 3/8” from the ground.
3/8” to 1/2” from one another —
ideal for line following. In a bit, you’ll
see how to use one of these arrays
with the ArdBot.
Whether you use homebrew line
following sensors or rely on ready-
made modules, the emitter and
detector can be aligned either in
column or row orientation, whatever
fits best. By their nature, line
following requires at least two pairs of
emitters/detectors. These are placed a
specific distance from one another, in
order to determine the location of the
line under the robot.
(In a pinch, you can even share
one LED and several phototransistors.
In this scheme, the light of the LED
FIGURE7.
Parallax QTI reflective sensor,
useful for line following (and other
things). Note that the output of this
sensor is a pulse, not an analog voltage.
provides a large enough spot for two
phototransistors — one on each side.
This method is not recommended
though, unless space is extremely
limited.) The spacing of the
emitter/detector pairs depends on the
width of the tracking tape. To be
effective, at least one sensor should
detect the line at any one time. With
too much space, a thin line can get
“lost” between sensors. You can fix
this either by grouping the
emitter/detector pairs closer together,
or using a wider tape.
Figure 8
shows
some variations. As most, PVC
FIGURE8.
The spacing
between
reflective
sensors is
dependent on
the width of
the line. The
line must be
visible to at
least one
sensor at
any time.
FIGURE9.
Circuit for
connecting two
LEDs and
phototransistors
to the Arduino.
See the text for
the values of
the four
resistors.
SERVO 04.2011
37
electrical tape is 3/4” wide; a spacing of 3/8” to 1/2” is
most common.
By the way, when we talk of spacing, it means the
distance between the optical centers of each
emitter/detector pair, regardless of the physical dimensions
of the sensor. Given sensors that are physically 1/4” wide
and 3/8” between optical centers, the actual spacing
between each component is only 1/8”.
Constructing a Two-Sensor
Line Follower
The most basic line follower uses two emitter/detector
pairs. To work properly, the pairs must be close enough
together to both see the line when the robot is directly
over it. If the left sensor doesn’t detect the line, it means
the robot has veered too far to the right. To compensate,
the robot steers back over to the left. Conversely, if the
right sensor doesn’t detect the line, the robot corrects its
path by briefly steering back toward the right.
Figure 9
shows the schematic view of connecting
two IR LEDs and two phototransistors to the Arduino.
Since the output of the phototransistors is a variable
voltage, we use two of the Arduino’s analog-to-digital
converter inputs; specifically, pins A3 and A4.
Figure 10
shows the same circuit but in breadboard view. (The
bottom of the breadboard is dedicated to the servo
wiring. See Part 2 of this series for more information.)
Resistor values to start (see the previous discussion for
selecting the values based on the LEDs and
phototransistors you use) are:
Listing 1
/*
ArdBot line following demo using
2 reflective sensors
Requires Arduino IDE version 0017
or later (0019 or later preferred)
*/
#include <Servo.h>
Servo servoLeft; // Define left servo
Servo servoRight; // Define right servo
const int lineLSense = A3;
const int lineRSense = A4;
int irReflectR = 0;
int irReflectL = 0;
int thresh = 400;
void setup() {
servoLeft.attach(10); // Left servo pin D10
servoRight.attach(9); // Right server pin D9
void loop() {
R1, R2: 470
W
R3, R4: 100 k
W
// Read reflective sensors
irReflectL = analogRead(lineLSense);
irReflectR = analogRead(lineRSense);
Listing 1
shows a simple line following sketch. After
setting up the two servos, the analog values of the two
sensors are read. These values are then applied to one of
several actions:
if (irReflectL >= thresh && irReflectR >= thresh) {
line_forward(); // on line
if (irReflectL >= thresh && irReflectR <= thresh) {
line_spinLeft(); // veering off right
delay(4);
• Line is detected by both sensors; keeps going forward.
• Line is detected only by the left sensor; steer briefly to
the left.
• Line is detected only by the right sensor; steer briefly
to the right.
• Line is not detected by either sensor; steer in a circle,
if (irReflectL <= thresh && irReflectR >= thresh) {
line_spinRight(); // veering off left
delay(4);
// If line is lost try to reacquire
if (irReflectL < thresh && irReflectR < thresh) {
line_spinRight();
delay(20);
FIGURE 10.
Breadboard view of the circuit in Figure 9.
}
}
// Motion routines for line following
void line_forward() {
servoLeft.write(0);
servoRight.write(180);
void line_slipRight() {
servoLeft.write(90);
servoRight.write(180);
}
void line_slipLeft() {
servoLeft.write(0);
servoRight.write(90);
}
void line_spinRight() {
servoLeft.write(180);
servoRight.write(180);
}
void line_spinLeft() {
servoLeft.write(0);
servoRight.write(0);
}
38
SERVO 04.2011
}
}
}
}
}
Plik z chomika:
phill2k
Inne pliki z tego folderu:
Making Robots With The Arduino part 6.pdf
(1168 KB)
Making Robots With The Arduino part 5.pdf
(901 KB)
Making Robots With The Arduino part 4.pdf
(1018 KB)
Making Robots With The Arduino part 3.pdf
(505 KB)
Making Robots With The Arduino part 2.pdf
(647 KB)
Inne foldery tego chomika:
Architektura mikrokontrolerów PIC 16F8x
ARM7TDMI
ATAPI
Autorouter Specctra
AVR Assembler
Zgłoś jeśli
naruszono regulamin