Practical Line Following Robot Documentation

This practical has been established to provide the microcontroller course at the
Vienna University of Technology with an autonomous robot. The robot should be
programmed by students participating in this course. The goal of this practical is
to develop a working prototype suitable for teaching purposes.
Line following is the ability of an autonomous robot to follow a line marked along
the floor. This primary objective should be accomplished in the least amount of
time.

1 INTRODUCTION
Figure 1: ﬁrst working prototype - July 7th, 2004
1 Introduction
1.1 Preface
This practical has been established to provide the microcontroller course at the
Vienna University of Technology with an autonomous robot. The robot should be
programmed by students participating in this course. The goal of this practical is
to develop a working prototype suitable for teaching purposes.
Line following is the ability of an autonomous robot to follow a line marked along
the ﬂoor. This primary objective should be accomplished in the least amount of
time.
Line Following Robot Documentation 3

1.2 Requirements
1.2 Requirements
These features are mandatory for the robot:
• high extensibility
• low complexity
• low costs
1.3 Goals / Aims
The following points should be heeded to guarantee the best possible acceptance:
• easy to program
• high speed and maneuverability
• cool exterior
1.4 Existing Systems
Line following is a popular topic many robot engineers already dealt with. There-
fore several competitions are held worldwide among line following enthusiasts
each year. Many successful projects are well documented available through the
www.
An extensive research effort has been undertaken to evaluate different solutions
and to avoid design mistakes. Here is a list of ideas gathered during the web
research phase:
From http://www.robotroom.com/Sweet.html:
• Lego compatible shaft for different types of wheels
• eventually place a bargraph on the front (debugging, fun)
• visible light sensors better than IR (tape lines cause trouble)
Line Following Robot Documentation 4

1.5 Application Boundaries
From http://www.robotroom.com/Sandwich.html:
• fancy headlights, nice exterior (chassis)
• white leds as light source improve different color tracking
From http://elm-chan.org/works/ltc/report.html:
• smooth steering algorithm
From http://www.barello.net/Papers/LineFollowing/:
• algorithms
From http://www.seattlerobotics.org/encoder/200106/
linerigel.html:
• sensor tips, sample time, noise reduction, data processing algorithms, fast
robot!
From http://www.wa4dsy.net/robot/line/:
• schematics and source codes
From http://www.kmitl.ac.th/~kswichit/LFrobot/LFrobot.htm:
• award winning robot, very slow though
1.5 Application Boundaries
There are many tradeoffs one has to face while designing a robot. For example
there is conﬂict between speed and durability, because heavy batteries improve
range while reducing the robots maneuverability. High speed turns are always
limited by the grip of tires, because, most important, the laws of physics can never
be broken.
Line Following Robot Documentation 5

2.2 Microcontroller
2.2 Microcontroller
It seems practical to use the ATmega16 controller which is currently used in the
lab. This controller is mounted on a multi-purpose Controller Board.
ATmega16 Features:
• Advanced RISC Architecture, 16 MIPS
Throughput at 16 MHz
• 16K Flash, 512 Bytes EEPROM and 1K SRAM
• two 8-bit Timers, one 16-bit Timer
• 4 PWM Channels
• 8-channel, 10-bit ADC
Totally it has 32 IO pins, which are protected by se- Figure 3: controller board
rial resistors on the Controller Board against short
circuits.
2.3 Sensors
David Cook states on his homepage that photoresistors are not the best choice for
line following due to their long reaction time. Phototransistors are fast and a 100
to 700 times more sensitive than photoresistors. Therefore an array of six BPY
62/III phototransistors is used. They "see" light between 420nm and 1130nm and
have an half angle of 8 degrees.
Furthermore David Cook writes that visible-light emitters and detectors are supe-
rior to infrared for line detection. What looks like a line to a human eye may be
almost transparent (masking tape) or completely opaque (certain clear plastics) to
infrared. Since humans are building the courses, the robot should see using the
same spectrum! Thus six SLH 36 WS white leds illuminate the path of our robot
(visible light has a wavelength of 370nm - 750nm). They have an half angle of 25
degrees and a brightness of 300mcd.
Line Following Robot Documentation 7

2.3 Sensors
Figure 4: sensor sideview
Figure 4 shows the front view of our sensor-led arrangement. The sensors and
leds are mounted on a 100x27mm printed circuit board. This board is 20 mm
longer in reality than on this picture to hold the connectors.
Figure 5 demonstrates the alignment of the sensors. The surface with the 5mm
line is located 40mm away from the PCB. Figure 6 shows that the real exposure
corresponds with the model.
When creating the schematics for the sensor circuit this description of phototran-
sistor circuits becomes handy. An interesting property of phototransistors is that
their sensitivity is determined by the circuit in which the phototransistor is involved.
With a high circuit resistance, the phototransistor has an increased sensitivity to
light than with a low circuit resistance.
The actual resistor values are difﬁcult to calculate, because the impact of ambient
light is not known a priori. Therefore several experiments (see Figure 7, 8)are
conducted to ﬁnd the appropriate values. To sense the current ﬂowing through
the phototransistor a 100kOhm resistor is used. The difference between "line"
and "no line" equals now 190bit with our ADC. Higher resistor values increase this
difference but also increase the noise level on the lines.
In order to save energy the six leds don’t shine all the time, they are switched by a
2N2218 transistor which draws only 4mA from the Microcontroller. With the con-
straints of our components in mind it is now possible to determine the maximum
sampling rate of our robot, which could limit its speed. The rise/fall time of the
BPY 62/III phototransistor is 7 us and our ADC has a Conversion Time of 65 - 260
Line Following Robot Documentation 8

2.3 Sensors
Figure 5: 3D Illumination Simulation
Figure 6: Illumniation Test
us, thus limiting the Sampling Rate of one sensor to 3.8 kHz (worst case, still not
bad). Sampling all 6 sensors and ﬁnding the position of the line can therefore (the-
oretically) be done in 1.56ms at a rate of 641 Hz. Referring to a (hypothetically)
20 km/h moving robot that would be one sample every 8.6 mm. This example
indicates that the real speed limiting factors are motors and traction rather that the
sampling rate.
The next step was to test this sensor concept. Therefore the test circuit shown in
ﬁgure 9 was used in connection with a HCS12 microcontroller for data acquisition.
Line Following Robot Documentation 9

2.3 Sensors
The measured data was transferred to the pc via the RS232 interface and visual-
ized using Excel. As ﬁgure 10 indicates, ﬁrst tests look really promising. A white
paper with a 12mm black line was pulled from right to left approximately 40mm
over the sensor.
sensor data of a right to left transistion
1000
980
960
940
left
920
center
900
right
880
860 right
1
12
23
34
center
45
56
67
78
89
left
100
111
122
133
144
155
166
30
20
10
0
1 9 17 25 33 41 49 57 65 73 81 89 97 105 113 121 129 137 145 153 161 offset
-10
-20
-30
-40
Figure 10: sensor data acquisition
Figure 11 shows the ﬁnished Line Sensor circuit soldered on a prototyping PCB.
On the right there is a connector leading to the ADC inputs of the microcontroller.
The silver cylinder on the bottom left is the 2N2218 transistor.
Line Following Robot Documentation 11

2.4 Motors
Figure 11: the sensor PCB
2.4 Motors
Our motors should produce much torque at low rpm and consume as little energy
as possible. The following calculations were made to give us a raw idea of how
much torque we would need to accelerate our robot (thanks to Markus Foltin).
F = m∗v t
(F... force needed to accelerate, m... mass, v... velocity, t... time)
F = 0.5∗5
3
(assuming 500grams and an acceleration from 0 to 5 m/sec in 3 sec)
T =F ∗r
(T... Torque, r... radius)
T = 0.8333 ∗ 0.02 = 0.016N m = 16mN m
(our wheels should have a diameter of 4 cm, friction is neglected)
4cm wheels would turn at 2387 rpm when driving 5m/sec. With this approximated
data in mind it is possible to select appropriate motors for this special applica-
tion. The IGARASHI 2430-65 motor (2.95 euro @ conrad.at) seems suitable. It
produces 2.0 mNm at 7200 rpm, running at optimal efﬁciency. With a 1:3 trans-
˜
mission it should handle its job quite well (2 motors 12 mNm).
The motordriver L293D (equipped with internal clamping diodes) will be used,
because our motor draws only a maximum of 1A current. First experiments with
Lego showed that the robot would be way to fast with a 1:3 transmission, therefore
a 1:25 transmission is used. However, our other assumptions were not too bad:
the real robot weights 580 grams and the IGARASHI 2430-65 motors perform their
job very well in accelerating the robot.
Line Following Robot Documentation 12

2.4 Motors
As power supply serves a NiCd 1100 mAh / 6 Volt battery pack from an old cam-
corder. It was chosen because it can be fast charged very easily with the existing
battery charger of the camcorder. These 6 Volts go directly into the L293D dual
H-bridge motordriver IC. A LP2950 low dropout voltage controller is used to feed
the microcontroller and the sensor with 5 volt. The robot draws about 850 mA
while driving, thus an operating time of 1.5 hours can be achieved theoretically.
Although both motors draw together only 650 mA and the L293D should handle up
to 1.2A peak per channel it gets extremely hot. As soon as the L293D becomes
too hot the robot slows down or stops completely, so cooling becomes an issue.
Figure 12: improvised cooler
Figure 12 shows a workaround for this problem. A custom made cooler was built
out of the cooling ﬁns of an old CPU cooler and attached to the L293D with wires.
This solution renders it possible to drive around with 60 percent of the total speed
without getting slowed down due to overheating. For faster speeds a ventilator
would be needed.
Line Following Robot Documentation 13

2.5 RF transceiver
2.5 RF transceiver
Equipping this robot with an RF transceiver and making it remote controllable is
part of another practical. It should be possible to program the robot over the
internet and watch its movements via a webcam. Once this is done, a link will be
placed here.
2.6 Mechanical Assembly
Lego was used to build the robot because it is widely available and it is very easy to
build transmissions. It is also quite stable if glue is used to hold the parts together.
The microcontroller itself is mounted together with an IO board on a wooden panel,
which was originally created for the microcontroller course. It is used unmodiﬁed
for the robot, held in place by double sided adhesive tape. Although the IO board
is not necessary for operation it is good to have it for debugging. Below the micro-
controller is the H-bridge motordriver circuit (the brown PCB).
Figure 13: ﬁnished prototype
Two Lego parts where modiﬁed with the Dremel tool to hold the motors in position,
which are attached with 2 component epoxy glue. Figure 15 shows the motors
and the transmission. The gears directly after the motors are from a gear set,
obtainable at conrad.at. The Line Sensor is attached to the Lego frame with hot-
melt adhesive.
Line Following Robot Documentation 14

2.7 Application Software, Algorithms
2.7 Application Software, Algorithms
As development environment WinAVR is used.
The ﬁrst steering algorithm used is very simple, but effective. The maximum of the
6 sensor values is determined and interpreted as the position of the line. The two
motors are driven by a PWM signal with a period time of 1msec. A simple switch
statement does the steering:
/*
* max_pos: position of the line (maximum of sensor values, 0 to 5)
* drive_speed_m1: left motor speed (-100 to 100)
* drive_speed_m1: left motor speed (-100 to 100)
*/
switch (max_pos)
{
case 0:
drive_speed_m1 = 60;
drive_speed_m2 = -20;
break;
case 1:
drive_speed_m1 = 40;
drive_speed_m2 = -5;
break;
case 2:
drive_speed_m1 = 30;
drive_speed_m2 = 20;
break;
case 3:
drive_speed_m1 = 20;
drive_speed_m2 = 30;
break;
case 4:
drive_speed_m1 = -5;
drive_speed_m2 = 40;
break;
case 5:
drive_speed_m1 = -20;
drive_speed_m2 = 60;
break;
}
Note: In this example only a small percentage of the maximum engine power is
used.
Line Following Robot Documentation 16

3 PCB DESIGN
3 PCB Design
3.1 Introduction
After the concept has been proved by the prototype, an application speciﬁc printed
circuit board (PCB) was created for small series production. It should comprise
all the useful features of the prototype while expunging its deﬁciencies (e.g. the
weak motor driver). Ultimately, a few extra features where added to challenge the
students programming the robot.
3.2 Features
• Atmel ATmega128 microcontroller
• 2x L298 4Amp dual H-bridge motor driver
• 2x temperature sensor for motor driver
• Line Sensor (6 white leds, 6 phototransistors), removable
• JTAG and ICSP interface
• ER400TRS RF transceiver
• RS232 driver
• high side current monitor
• low drop voltage regulator
• 2 buttons
• 2 potentiometers
• 8 leds
• high extensibility
• supply voltage 7.5V - 16V
The goal of the design process is to create a versatile, multi-purpose PCB for
various robotic applications. Virtually all IO pins of the ATMega128 are accessible
through female connectors. Theoretically it is possible to create an extension
board and stack it on top of the robot board. Many parameters of the board’s state
are accessible by software, e.g. current consumption, battery voltage and the
Line Following Robot Documentation 17

3.3 Schematics
motor driver’s temperature. On board IOs include 2 potentiometers for parameter
tuning, 2 buttons and 8 leds, therefore facilitating debugging. As communication
interface serves a RS232 plug to connect the board directly to a PC, as well as
the ER400TRS RF module for wireless access.
The line sensing section is apart of the other sections, rendering it possible to
detach it. E.g. it is possible to mount the line senor elsewhere than the robot
board and connect it by a ribbon cable.
3.3 Schematics
The light edition of the Eagle Layout editor by CadSoft is used for drawing the
schematics and creating the board’s layout. This freeware program is considered
as one of the best schematic editors, providing also a great deal of free part li-
braries. To improve readability most signals are named after their function.
See Figure 16.
Line Following Robot Documentation 18