Professional Documents
Culture Documents
Faculty of Engineering
Graduation Project
This document goes into 9 chapters, each descriping certain part of the
project.
Chapter 1 Gives an overview about the whole system, the reqiured speci-
fication of the hardware, and the general architecture of the system.
Chapter 9 Gives a short summary about the project. It also shows the
proposed future work ideas.
Contents
1 System Overview 1
1.1 Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Introductoin . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 System Architecture . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Required Computer Specifications . . . . . . . . . . . . . . . . 4
1.5 Robot Hardware . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Robot Components 8
2.1 Hardware Components at a Glance . . . . . . . . . . . . . . . 8
2.2 Basic Stamp Module . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.1 Memory organization . . . . . . . . . . . . . . . . . . . 10
2.3 Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3.1 Infrared Headlights . . . . . . . . . . . . . . . . . . . . 11
2.3.2 Ultrasonic Range Finder . . . . . . . . . . . . . . . . . 13
2.3.3 Digital Compass . . . . . . . . . . . . . . . . . . . . . 14
2.3.4 Digital Encoders . . . . . . . . . . . . . . . . . . . . . 16
2.4 Servo Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.4.1 Continuous Rotation Servo Motors . . . . . . . . . . . 17
2.4.2 Ultrasonic Bracketing Kit . . . . . . . . . . . . . . . . 17
3 Robot Motion 19
3.1 Motion Requirements . . . . . . . . . . . . . . . . . . . . . . . 19
3.2 Motion Calibration . . . . . . . . . . . . . . . . . . . . . . . . 22
3.2.1 Pre-Motion Calibration . . . . . . . . . . . . . . . . . . 22
3.2.2 Coordinating Motion . . . . . . . . . . . . . . . . . . . 24
3.2.3 Ramping . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.2.4 Error Detection and Correction . . . . . . . . . . . . . 25
4 Robot-Computer Communication 27
4.1 Communication Environment . . . . . . . . . . . . . . . . . . 27
CONTENTS b
7 Error Analysis 52
7.1 Robot Motion Errors . . . . . . . . . . . . . . . . . . . . . . . 52
7.2 Sensors Measurements Errors . . . . . . . . . . . . . . . . . . 53
7.2.1 Ultrasonic Range Finder . . . . . . . . . . . . . . . . . 53
7.2.2 Digital Compass . . . . . . . . . . . . . . . . . . . . . 55
7.3 Application Results Errors . . . . . . . . . . . . . . . . . . . . 55
A Bluetooth Overview 69
A.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
A.2 Bluetooth Protocol Stack . . . . . . . . . . . . . . . . . . . . . 70
A.3 Bluetooth Profiles . . . . . . . . . . . . . . . . . . . . . . . . . 73
A.4 Security in Bluetooth . . . . . . . . . . . . . . . . . . . . . . . 73
C Servo Motors 82
C.1 What is a Servo? . . . . . . . . . . . . . . . . . . . . . . . . . 82
C.2 How Servo Works? . . . . . . . . . . . . . . . . . . . . . . . . 82
C.3 Modifying Servo for Continuous Rotation . . . . . . . . . . . . 85
D Perpendicular Regression 86
F Examples on API 91
F.1 Example 1: Motion in a Square . . . . . . . . . . . . . . . . . 91
F.2 Example 2: Motion in an Isosceles Triangle . . . . . . . . . . . 92
Bibliography 93
List of Figures
5.1 The solid points belongs to the line segment but the non-solid
points are far points and doesn’t belong to the line segment. . 37
5.2 An example of Perpendicular fitting . . . . . . . . . . . . . . . 38
LIST OF FIGURES e
3.1 Motors pulse width for motion in straight line with different
speeds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
System Overview
1.1 Abstract
This project addresses the problem of map-building using a mobile robot for
small scale indoor environments. The robot will collect data using a range
finder sensor while an application is running on a remote station, which has
a kind of wireless connection with the mobile robot, and whose task is the
control of the mobile robot and the construction of the map from the received
data using an appropriate method.
1.2 Introductoin
Building maps of indoor environments is a pivotal problem in mobile robotics.
The problem of map building is the problem of determining the location of
entities of interest such as landmarks and obstacles, often relative to a global
frame of reference (sush as a Cartesian coordinate frame). The mapping prob-
lem is often referred to as the concurrent mapping and localization problem.
Because of that the processing unit on the mobile robot does not pro-
vide the enough processing power required for the data processing and map
Chapter 1. System Overview 2
Because of the need to the mobility of robot and the remote control, a
wireless communication is used to exchange data between the mobile robot
and the PC. The PC runs an application responsible for the control of the
behaviour of the mobile robot and the map construction using the data re-
ceived from the mobile robot. Bluetooth is picked to be used in wireless
communication. An API has been developed to be the interface between
the PC application and the mobile robot. This interface is composed of the
commands which control and guide the mobile robot through the execution
of its tasks. The data and commands are sent through bluetooth connection
according to a simple protocol which provide synchronization and data reli-
abilty.
The map is extracted from the received data according to one of two meth-
ods. The first is Points Locality method. It uses the line-based representation
of the map, i.e. the map is represented as a set of line segments which fit
to sets of two-dimensional range scan data that are acquired from multiple
positions. The second method is the Occupancy Grid method. It represents
the environment as a two-dimensional grid whose cells have a probability
of being occupied by objects. Figure1.2 and Figure1.3 show the results of
applying the two methods when exploring the area shown in Figure1.1.
Physically, system consists of three parts: Computer side, robot side, and
communication between the robot and the computer. Computer side con-
tains both application and API. Robot side consists of its physical compo-
Chapter 1. System Overview 4
nents and software modules that control such components. The communi-
cation between the robot and the computer is accomplished over Bluetooth
connection. Bluetooth dongle is connected to the computer, and Bluetooth
module is connected to the robot.
• Memory: 512MB
BOE-BOT robot kit provided by Parallax has been used. Below is a list
of all components fixed on BOE-BOT board. This section will show how to
connect them. Details of each component will come later.
• 2 Continuous rotation servo motors (one for each side to rotate wheels)
Figure 1.6 shows BOE-BOT with all components fixed on it. Schematic
diagram for components connection is shown in Figure 1.7. Pin assignment
for BASIC Stamp is shown in Table 1.1
Chapter 1. System Overview 6
Robot Components
Four types of sensors are fixed on robot board: infrared headlights, ul-
trasonic range finder, digital compass and digital encoder.
Infrared Headlights, Figure 2.2, are used to detect objects but cannot
determine exactly the distance to object. It is important in many appli-
cations such as obstacle avoidance and roaming. Ultrasonic range finder is
used mainly to detect obstacles and measure how far they are. Parallax
P IN G)))T M Ultrasonic Range Finder, Figure 2.3, has been used. The third
type of sensors is digital compass, which is used to determine robot direc-
tion with accuracy of around five degrees. Hitachi HM55B Compass Module,
Figure 2.4, has been used. The last type of sensors is digital encoder, Figure
2.5. Digital encoder is a reflective sensor used to detect objects that are very
closed to the sensor. It’s mainly used to control robot motion.
Scratchpad RAM The BS2pe has some additional RAM called Scratchpad
RAM. The BS2pe has 128 bytes of Scratchpad RAM (0-127). Scratch-
5
pad RAM can only be accessed with the GET and PUT commands
and cannot have variable names assigned to it. The highest location in
Scratchpad RAM, location 127 on the BS2pe, is read-only, and always
contains the number of the currently running program slot. This can
5
see the GET and PUT command descriptions for more information
Chapter 2. Robot Components 11
be handy for programs that need to know which program slot they exist
in.
2.3 Sensors
Infrared light is used to illuminate the robot’s path and determine when the
light reflects off an object.
The infrared object detection system built on the Boe-Bot is like a car’s
headlights in several respects. When the light from a car’s headlights reflects
off obstacles, your eyes detect the obstacles and your brain processes them
and makes your body guide the car accordingly. The Boe-Bot uses infrared
LEDs for headlights as shown in Figure 2.7. They emit infrared, and in some
Chapter 2. Robot Components 12
cases, the infrared reflects off objects and bounces back in the direction of
the Boe-Bot. The eyes of the Boe-Bot are the infrared detectors. The in-
frared detectors send signals indicating whether or not they detect infrared
reflected off an object.
The IR detectors have built-in optical filters that allow very little light
except the 980 nm infrared that we want to detect with its internal photodi-
ode sensor. The infrared detector also has an electronic filter that only allows
signals around 38.5 kHz to pass through. In other words, the detector is only
looking for infrared that’s flashing on and off 38,500 times per second. This
prevents IR interference from common sources such as sunlight and indoor
lighting. Sunlight is DC interference (0 Hz), and indoor lighting tends to
flash on and off at either 100 or 120 Hz, depending on the main power source
in the region. Since 120 Hz is outside the electronic filter’s 38.5 kHz band
pass frequency, it is completely ignored by the IR detectors.
FREQOUT 8, 1, 38500
irDetector = IN9
Chapter 2. Robot Components 13
In this code snippet, FREQOUT sends 38.5 kHz signal to the IR LED connected
to Pin 8, next line stores the IR detector’s output, which is connected to Pin
9, in a bit variable named irDetector. The IR detector’s output state when
it sees no IR signal is high. When the IR detector sees the 38500 Hz har-
monic reflected by an object, its output is low. The IR detector’s output
only stays low for a fraction of a millisecond after the FREQOUT command is
done sending the harmonic, so it’s essential to store the IR detector’s output
in a variable immediately after sending the FREQOUT command.
The Parallax PING ultrasonic range finder provides precise, non-contact dis-
tance measurements from about 3 cm to 3 meters. It is very easy to connect
to BASIC Stamp, requiring only one I/O pin.
Figure 2.8 shows how this operation is done, under control of a host mi-
crocontroller (trigger pulse), the sensor emits a short 40 kHz (ultrasonic)
burst. This burst travels through the air at about 1130 feet per second, hits
an object and then bounces back to the sensor. The PING))) sensor provides
an output pulse to the host that will terminate when the echo is detected;
hence the width of this pulse corresponds to the distance to the target.
Chapter 2. Robot Components 14
In this code snippet, PULSEOUT generates input pulse on Ping pin, PULSEIN
generates output pulse that terminates when detecting echo, the width of this
pulse is stored in rawDist variable, which is divided be 2 to remove return
trip and then converted to microseconds.
As shown in Figure 2.9, The Hitachi HM55B Compass Module has two
axes, x and y. Each axis reports the strength of the magnetic field’s compo-
nent parallel to it. The x-axis reports (f ieldstrength)∗cos(θ), and the y-axis
Chapter 2. Robot Components 15
The Hitachi HM55B chip on the Compass Module reports its x and y
axis measurements in terms of microteslas µT in 11-bit signed values. The
HM55B is designed to return a value of 1 for a north magnetic field of 1 µT
parallel to one of its axes. If the magnetic field is south, the value will be
-1. These are nominal values. According to the HM55B datasheet, the ac-
tual µT value for a measurement of 1 could range anywhere from 1 to 1.6 µT .
The microcontroller connected to the HM55B must control its enable and
clock inputs and use synchronous serial communication to get the axis mea-
surements from its data input and data output pins. For example, a BASIC
Stamp 2 can be programmed to control the Compass Module’s enable lines
with HIGH/LOW and send values that reset the device and start a mea-
surement with SHIFTOUT commands. The SHIFTOUT command controls
the Compass Module’s clock input as it sends data bit values to its data
input. The converse of SHIFTOUT is SHIFTIN, which also controls the de-
vice’s clock input as it collects data bits sent by the device’s data output pin.
SHIFTOUT DinDout,clk,MSBFIRST,[Measure\4]
status = 0 ’ Clear previous status flags
More details aboout digital encoders and using them in motion control
and calibration will be mentioned in chapter 3.
Chapter 2. Robot Components 17
Table 2.1: Standard servo pulse width for different Ping angles
7
For more information about standard servo motors, check Appendix C
Chapter 3
Robot Motion
MOVE
Do
Chapter 3. Robot Motion 20
The previous code uses infinite loop to rotate wheels. It needs some
modification to move robot for a certain distance. To achieve that, it’s
important to find a way to calculate the distance robot has traveled so
far. The simplest solution is to make use of robot velocity and time to
calculate distance, however, this solution it’s not a practical one since
it needs an ideal environment. Therefore, another solution is adopted
that uses digital encoders.
MOVE(Distance)
EP = Convert Distance to Encoder Pulses
While(EP <> 0)
PULSEOUT right_wheel, 650
PULSEOUT left_wheel, 850
if(Right encoder pulse)
EP = EP - 1
Loop
RETURN
servo motor, 1.5 ms in our case, is not the actual one. The following
experiment is done to avoid this problem. Figure 3.2 shows the signal
that has to be sent to the servo to calibrate it. This is called the cen-
ter signal, and after the servo has been properly adjusted, this signal
instructs it to stay still.
After this step, supplying servo with 1.5 ms pulse train will make it
not turning.
After this experiment, each servo has sixteen pulse width values corre-
sponding to sixteen equally spaced velocities.
Speed Level Right Motor Pulse width Left Motor Pulse width (ms)
No Motion(Null) 744 744
Level 1 733 754
Level 2 725 762
Level 3 720 767
Level 4 707 780
Level 5 655 815
Table 3.1: Motors pulse width for motion in straight line with different speeds
While motion
read digital encoders pulses
if left encoder reads two consecutive pulses
stop left wheel for some servo pulses
if right encoder reads two consecutive pulses
1
Pulse width is measured in number of BASIC Stamp clock pulses. To convert it to
milliseconds, multiply by 0.002
Chapter 3. Robot Motion 25
3.2.3 Ramping
Inertia is a fact of life. ”A body at rest will remain at rest, and a body in
motion will remain in motion, unless acted upon by another force.” And this,
of course, applies to robots and robot wheels. Starting or stopping motion
without gradual acceleration and deceleration is not only jarring to the servos
internal mechanisms but wastes precious battery energy. If STOP command
is sent to robot while moving, inertia will keep it moving a little, possibly
for another servo pulse or two, completely messing up the precision we set
out to achieve. On the other hand, if MOVE command is sent to robot, inertia
may make it shake and divert from its proper path.
Fortunately, ramping can solve the problem. Figure 3.3 shows how to
do it. To move robot for a distance D with velocity Vm ax, firstly, ramp
velocity from Vm in to Vm ax, then, move with Vm ax until it almost finishes,
and finally, ramp velocity again from Vm ax to Vm in
Robot-Computer
Communication
The module supports 2 modes. The first mode is Data mode where any
data in sent to the module from the robot is transferred directly over Blue-
tooth connection to the other pair of connection. The second mode is Com-
mand mode where any data sent to the module from the robot is transferred
to the module itself and interpreted as a command. The module supports
some commands for connection establishment and termination. There are
also commands for change the security setting. The full listing of the com-
mands can be found in the manual of the module.
The steps done at the robot side to communicate with the computer are
as follows:
• The connection is established and that can be checked from the status
pin of the eb500
• Both the Stamp microcontroller and the Bluetooth module have US-
ART modules. Those USART modules are used to exchange data be-
tween them.
’Wait for the connection to be established and switch into data mode.
’When switching into data mode, a 300ms timeout is required to give the
’module enough time to make the change.
For the software part, the application running should use the pre-mentioned
serial port. In order to simplify the task of interfacing the serial port, the
.NET2.0 framework is used. It’s the first .NET framework the provide classes
for communicating with the serial ports. The SerialPort class is used. It sup-
ports methods to send/receive bytes to/from the serial port.
The steps required at the computer side to communicate with the com-
puter are as follows:
• Make the connection between the computer and the robot using Blue-
tooth adapter tools.
• From System Settings check the serial port assigned to the Bluetooth
adapter.
• In the SerialPort class, use the method Open to allocate the required
resources by the system for the port.
• Now, you can easily use the methods provided by SerialPort class for
sending and receiving data.
2
SPP stands for Serial Port Profile
3
For more information about Bluetooth profiles, check appendix A
Chapter 4. Robot-Computer Communication 31
Initialize Initializes the status variables of the robot, e.g. the position, the
angle and sensors directions.
Move Forward Makes the robot move till another command of stopping is
invoked.
Move Distance Moves the robot to the forward a certain distance and then
stop it automatically.
Measure Ping Returns the distance in front of the ultra-sonic sensor at its
current position and angle.
Measure Compass Returns the angle of the robot with respect to the mag-
netic north.
Rotate Ping Rotates the Ultra-sonic sensor to one of the five positions.
(90◦ to the left, 45◦ to the left, to the forward, 45◦ to the right, 90◦ to
the right)
Rotate Left 90◦ Rotates the robot 90◦ to the left without using the com-
pass.
Rotate Right 90◦ Rotates the robot 90◦ to the right without using the
compass.
Rotate Left Slow Rotates the robot slowly to the left till stopping com-
mand is invoked.
Rotate Right Slow Rotates the robot slowly to the left till stopping com-
mand is invoked.
Rotate With Compass Rotates the robot to any angle with respect to the
magnetic north using the compass.
Chapter 4. Robot-Computer Communication 33
Figure 4.3: The UML of the API Implementation at the Computer Side
At the robot side, the code is divided into modules. Upon the reception
of a command, the appropriate module is executed. Such modular design
facilitates the pre-explained changeability and extendibility.
At the application side, the API is implemented as certain classes. The UML
shown in Figure 4.3 illustrates them.
The abstract class Robot encapsulates the standard data members and
Chapter 4. Robot-Computer Communication 34
methods that should be available in any robot supporting this API. Those
methods are abstract and have no implementation. Any actual robot class,
BoeBotRobot class in this project, must inherit from Robot class and give
the appropriate implementation for such methods.
The Robot class, or any inherited class from it, needs a class implement-
ing the interface CommunicationPort. This interface provides the meth-
ods required to open connection with the robot, disconnect from the robot,
send data to the robot, and receive data from the robot. In this project,
the serial port profile of the Bluetooth dongle is used, and hence a class
SerialPortCommunication is implementing the interface CommunicationPort.
An instance SerialPortCommunication class is passed to constructor of the
BoeBotRobot class.
Chapter 5
Map Building is one of the fundamental tasks of mobile robots and many re-
searchers have focused on the problem of how to represent the environment
as well as how to acquire models using this representation. Exploration is
the task of guiding a vehicle in such a way that it covers the environment
with its sensors.
Two methods have been used to build the map. The first is Points
Locality, it aims to fit the points returned by sensor readings in line seg-
ments. The second method is a well known method called Occupancy Grid,
it usees a probabilistic approach to build the map. For navigation, Wall
Follower technique has been used.
the points related to one segment. Second, because of the inaccuracy in the
measured points, we need to fit these points to find a candidate line segment
which results in minimum error.
1. The new point is near by the start or the end of the line segment, in
this case either this point belongs to this sigment or belongs to another
segment which is intersected with it as in corners. If the new height of
the new point is small enough and the total error after the insertion of
the new point is still small enough, then the new point would belong
to this segment, otherwise it would belong to an intersected segment.
2. The new point is far from the start and end points of the line segment
but the height of the point is small enough, as in the first case, the new
point may belongs to the line segment or an intersected segment, and
this is decided acording to the current and the new total error as in the
first case.
3. The new point is far from the start and end points of the line segment
and its height is not small enough, in this case the new point doesn’t
Chapter 5. Map Building Application 37
If it’s found that the new point doesn’t belong to any one of the existed line
segment, it will be inserted in a new line segment which will have only one
point untill it receives other neighbour points.
Figure 5.1: The solid points belongs to the line segment but the non-solid
points are far points and doesn’t belong to the line segment.
n
X
ε= hi (5.1)
i=1
n q
X
ε= ∆2X + ∆2Y (5.2)
i=1
and for simplicity, the error will be defined as the sum of the squares of
heights rather than the sum of heights:
n
X
ε= h2i (5.3)
i=1
n
X
ε= (∆2X + ∆2Y ) (5.4)
i=1
n n
∂ε X X
=a P xi − Pyi + nb = 0 (5.6)
∂b i=1 i=1
Chapter 5. Map Building Application 39
the line segment according to the list of its points. Now, each line segment is
determined with the start and end points and the map can ignore the large
number of data points.
There are two problems will appear when using this method. The first one
is the curves which can’t be extarcted by fitting line segments to the data
points. The curves will appear as a number of non-continuous line segments
as shown in Figure 5.4. The second problem is the corner problem which will
lead to undesired results , as shown in Figure 5.3, because of the method of
1
for more information about the mathematical proof, return to appendix D
Chapter 5. Map Building Application 40
For region A, the probability of occupancy of each cell given this sensor
reading is inversely proportional to both the distance and the angle between
it and the sensor. At contrary for every cell in region B the probability of
occupancy of each cell given this sensor reading is directly proportional to
both the distance and the angle between it and the sensor. We used these
Chapter 5. Map Building Application 42
Figure 5.6: Calculating Probability From Distance and Angle Between Sensor
and Cell
factors to estimate the probability of occupancy of each cell given this sensor
reading as follows:
As shown in Figure 5.6, let D be the maximum distance sensor can get,
β be the maximum cone angle, d and α are the distance and angle of the
current cell to be updated, respectively).
In Region A:
c1 D−d c2 β−α
c1 D
+ c2 β
P r(Occ) = (5.9)
2
In Region B:
c1 D−d c2 β−α
c1 D
+ c2 β
P r(Occ) = (5.10)
2
Where P r(Occ) is the probability that the cell is occupied, P r(Occ) is the
probability that the cell is free. c1 and c2 are constants depend on cell size.
The smaller cell size, the larger the constants are. Minimum value of these
constants is 2, just to ensure that probability is greater than 0.5. If not,
sensor reading may cause a negative effect on the total probability.
how to update the cell occupancy probability upon the new sensor reading.
Let the probability of occupancy of each cell given the ST sensor reading is
P r(Occx,y |ST )
The final stored probability after T sensor readings would be
P r(Occx,y |S1 , S2 , ..., ST )
Using Baye’s low and conditional probability rules, the following formula can
be proved2 :
P r(Occx,y |S1 , S2 , ..., ST ) =
−1
T
P r(Occx,y |S1 ) Y P r(Occx,y |Sτ ) P r(Occx,y ) (5.11)
1 − (1 + )
1 − P r(Occx,y |S1 ) τ =2 1 − P r(Occx,y |Sτ ) 1 − P r(Occx,y )
The previous formula is suitable for cells in region A. For Region B, the suit-
able value would be P r(Occx,y |S1 , S2 , ..., ST ) and can be calculated, similarly,
using the formula:
P r(Occx,y |S1 , S2 , ..., ST ) =
−1
T
P r(Occx,y |S1 ) Y P r(Occx,y |Sτ ) P r(Occx,y ) (5.12)
1 − (1 + )
1 − Occx,y |S1 ) τ =2 1 − P r(Occx,y |Sτ ) 1 − P r(Occx,y )
In real implementation, the only needed information for each cell is P r(Occx,y |S1 , S2 , ..., ST ),
which is updated when cell lies in region A, and P r(Occx,y |S1 , S2 , ..., ST ),
which is updated when cell lies in region B. When drawing map, the maxi-
mum of these two values will be chosen.
• Use the recursive formulae, 5.11 and 5.12, to update the two values of
each cell, P r(Occx,y |S1 , S2 , ..., ST ) and P r(Occx,y |S1 , S2 , ..., ST ).
• After finishing navigation, and for each cell, select the maximum value
from P r(Occx,y |S1 , S2 , ..., ST ) and P r(Occx,y |S1 , S2 , ..., ST ).
• Using the selected values, fill the grid points with a grayscale color
corresponding to the probability.
2
See Appendix E for the complete proof
Chapter 5. Map Building Application 44
5.3 Navigation
A common technique for exploration strategies is to extract frontiers between
known and unknown areas and to visit the nearest unexplored place. An-
other simple technique is wall folllower. In this technique, robot is assumed
to begin motion at a point that the wall is right to it. The technique guides
the robot to follow the wall such that the wall always ramains right to the
robot. Robot keeps motion until it reaches its first location again. This
technique may not navigate the whole area if there is some locations far from
the wall, but for simplicity, wall follower has been choosen as a navigation
technique. Frontiers-Based approach is left as a futer work.
WallFollow
For i = 1 to number_of_steps
rotate sensor to forward direction and read it (Forward Read)
rotate sensor to right direction and read it (Right Read)
if Forward Read < forward_threshold then
rotate left 90 degrees
else if Right Read > right_threashold then
rotate right 90 degrees
Chapter 5. Map Building Application 45
end if
move one step
Loop
RETURN
This code snippet checks for two cases, the first is when forward sensor
reading becomes lower than a certain threshold, it means that there is a
wall in front of the robot. The second case is when the right sensor reading
becomes higher than a certain threshold, it means that the wall right to the
robot just ended.
MobotSim free trial simulator has been used to simulate robot motion
and sensors. The following figures shows simulation results.
Figure 5.7 shows result of ocuupancy grid method simulation, Figure 5.8
shows result of points locality method simulation. Note that in occupancy
grid there is no constraint on the shape of the border, it may be either lines
or curves. Points locality method will not give the same result if the border
contains curves. In general, simulation results are encouraging.
Chapter 5. Map Building Application 46
A surface of plates of white foam is used for being a nearly ideal surface.
It ensures little amount of slipping as well as providing a plane surface for
the robot to move on. Blocks of small stones are used to build walls and
objects. C# map-building application is developed using Microsoft Visual
Studio .NET 2oo5 IDE, Express Edition.
6.1 Experiment 1:
• Map Size: 1×1 meter
• Step Length: 15 cm
• Number of Steps: 14
Figure 6.1: Generated Maps for Experiment 1 using Occupancy Grid Method
Figure 6.2: Generated Maps for Experiment 1 using Points Locality Method
The map is this experiment was merely an empty squared room. Figure 6.1
shows the resulted map using occupancy grid method. Figure 6.2 shows the
resulted map using points locality method.
6.2 Experiment 2:
• Map Size: 1×2 meter
• Step Length: 15 cm
• Number of Steps: 28
Figure 6.3 shows the actual map. Figure 6.4 shows the resulted map using
occupancy grid method. Figure 6.5 shows the resulted map using points
Chapter 6. Experiments and Results 50
Figure 6.4: Generated Maps for Experiment 2 using Occupancy Grid Method
locality method.
Some analysis has been performed on the results of these expriments and is
illustrated in Chapter 7.
Chapter 6. Experiments and Results 51
Figure 6.5: Generated Maps for Experiment 2 using Points Locality Method
Chapter 7
Error Analysis
This chapter contains the experiments used to estimate the errors in robot
motion, sensors measurements and the resulted maps. Hardware errors in
robot servo mototrs and sensors measurements are considered pivotal factors
which have a significant effect on the resulted maps. Therefore, a lot of
experiments are performed to estimate the values of these different errors as
illustrated in the following two sections. In order to judge the efficiency of
the system, the errors in the resulted maps are considered as well.
in front of some solid budies and measure the distance, the following results
are obtained
Table 7.2 shows error in ultrasonic sensor readings. The average error is
0.658545455 cm, error standard deviation is 0.702285464 cm.
Table 7.3 and Figure 7.3 show error in walls dimension. The average error
is 11 cm, error standard deviation is 6.542170894 cm.
Table 7.4 and Figure 7.4 show error in angles between walls. The average
error is 7.471428571◦ , error standard deviation is 8.435384655circ .
Some details such as corners and curves may suffer from some distortion.
The parts with dimensions less than the robot motion step may not be fully
detected.
Chapter 7. Error Analysis 56
Several issues arise in implementing the serial port. A lot of this material
is not explained at all in the Stamp manuals, especially the timing issues.
Difficulties with timing on the serial ports can be one of the most frustrating
aspects of developing stamp applications. It usually comes down to quanti-
tative questions of how fast data can be received, recognized, processed and
transmitted.
Now, look at this scenario. The computer issues a move command to the
robot, Figure 8.1. Since the timing of the generated pulse is of big impor-
Chapter 8. Extending Robot Capabilities 58
tance, the robot shouldn’t do something else during the process of moving
the robot. That is because the Basic Stamp doesn’t support timer interrupts
and hence, the timing should be maintained by the running code. If the
computer issues a stop command to the robot, Figure 8.2, the latter cannot
receive the command since the microcontroller is busy moving the robot.
Figure 8.2: Computer issues a stop command but the microcontoller isn’t
listening.
of the robot. All other tasks and communication with the computer are done
by the first microcontroller. This approach is valid provided that the second
microcontroller supports interrupts. The scenario will be modified as follows.
The computer issues a move command to the first microcontroller. The latter
interrupts the second microcontroller and forwards the move command to it,
Figure 8.4. At this state, the first microcontroller is waiting for another
command from the computer and the second microcontroller do nothing but
moving the robot. It at any instance, the computer issues a stop command
to the first microcontroller. The latter interrupts the second microcontroller
and forwards the stop command to it.
Although the first approach was sufficient for this project, this may not
be the case with other situations. The second approach is investigated in
Chapter 8. Extending Robot Capabilities 60
USART module
Timers 3
Data Memory The data memory is partitioned into four banks, which con-
tain the GPRs 1 and the SFRs 2 . There are GPRs implemented as static
RAM in each bank.
As mentioned in Section 8.1, the proposed design of the project uses two
microcontrollers to accomplish the required functionality of the components.
The two microcontrollers are communicating together through a serial proto-
col. Since communication protocols between digital devices, such as I 2 C, are
too complicated to be used in such relatively simple functionality of the com-
munication, a new simpler protocol has been devised. The protocol has used
the external interrupt PIN of PIC microcontroller. As shown in Figure 8.3,
for simplicity, 3 lines are wired between the two microcontrollers. The first is
the interrupt line. The BASIC Stamp uses it to interrupt the PIC. The other
two lines are the Clock and Data wires which are used for synchronous data
transmission between the two microcontrollers. A communication scenario
will fully explain the protocol.
• The Stamp activates the Interrupt line and waits for enough time till
the PIC is ready to receive the data.
• The Stamp begins sending a command to the PIC using Clock and
Data lines.
• The Data are sent in units of 8 bits. Longer data or command param-
eters are sent in separated consecutive bytes.
1
GPR stands for General Purpose Register
2
SFR stands for Special Function Register
Chapter 8. Extending Robot Capabilities 62
• The Stamp waits for an ACK from the PIC to make sure the PIC
successfully received the command.
• The PIC either receives the command correctly and acknowledges pos-
itively or receivers an invalid byte and acknowledges negatively.
Table 8.1 shows the selected code words that provide 4-bit minimum ham-
ming distance for 16 8-bit commands.
In BASIC Stamp side, data is just passed to the computer which will
check the parity and decide the next step. On the other hand, parity bit is
added by computer before sending it to BASIC Stamp.
In PIC side, the problem is more complex. PIC will be responsible for
the whole matter. Parity generation and check must be done using PIC as-
Chapter 8. Extending Robot Capabilities 63
CalculateParity
; 7-bit parity
; This routine will calculate the parity of a 7-bit
; integer "CalulateParityByte" and place the result in the 8-position
parity check uses the same routine, but it stores the original data, and
than compare it to the calculated data.
9.1 Summary
The objective of the project was to use a mobile robot to build a map. The
proposed system is divided into two major entities each of which has its own
characteristics and challenges. Besides a computer, a robot with motors and
sensors attached to it were used to accomplish the objective of the project.
The two entities were to communicate together. The proposed medium of
communication was Bluetooth.
The most important task concerning the robot was how to fully control
it as well as the sensors attached to it. The first stage of achieving such task
has some minor subtasks beginning from calibrating the motion till testing
each robot component separately. Up to this point, no exhaustive design
efforts were exerted. The effort was targeted to getting familiar with the
new companion, the robot. If a name should be give to this stage, it will be
”Collecting Information”. Later on, more time was to be dedicated for the
design. Making all required sensors work together was not a piece of cake
after all. That was the task of this phase.
At this point, the robot is ready to obey its master, the computer. The
missing part was who will convey the orders of the computer to the robot. It
was time to begin testing the Bluetooth communication. Two different mod-
ules of Bluetooth were used, one at the robot and the other at the computer.
Both have been tested for working together seamlessly.
Regarding the communication between the two entities, a robot API was
Chapter 9. Summary and Future Work 67
proposed. All commands that the robot can fulfill were gathered into a
layer between the robot and the computer application. Computer applica-
tion should use this API to control the robot.
Parallel to that process dealing with the robot, another one was investi-
gating different methods of exploration and map-building. It was also nec-
essary to select the applicable methods with respect to time and resources
constraints. Upon the selection, the phase of implementation took place.
The applicable methods of exploration and map-building were implemented
using the proposed API. Those methods have been simulated on the com-
puter before the phase of real testing. Since simulation results were highly
acceptable, the selected map-building methods have been tested and com-
pared according to more than a test case.
During the whole process of the design and implementation of this project,
some other objectives were considered. The most important of those was how
to make the design changeable and extendable. This is objective was success-
fully achieved. To some extent, every module in the system can be replaced
with another one without affecting other modules provided that the new
module supports the same functionality the former supports.
• Using multiple robots to build the map, the robots would communicate
with each other and divide the tasks between them, multiple robots
approach could be used the to build the map faster, and to increase
the accuracy as the error in robot localization is accumulating with
time.
• Improving the accuracy of the resulted maps using error analysis results
and statistical methods.
sonic sensor that could result more accurate maps using points locality
method.
Bluetooth Overview
A.1 Introduction
To put it simply, Bluetooth is a technology standard for electronic devices to
communicate with each other using short-range radio. It is often referred to
as a ”cable replacement” technology, because it is commonly used to connect
things, such as cameras, headsets, and mobile phones that have traditionally
been connected by wires. Bluetooth is much more than simply a way to cut
the cord between todays existing electronic devices. It is an enabling technol-
ogy that will take these devices to new levels of productivity and functionality
and enable a whole new class of devices designed with communications and
connectivity in mind.
The Bluetooth Special Interest Group (SIG) defines Bluetooth a bit more
broadly as the ”worldwide specification for small-form-factor, low-cost radio
solutions that provide links between mobile computers, mobile phones, other
portable devices, and connectivity to the Internet.” In defining Bluetooth,
the SIG has taken a very different approach than the IEEE 802.11 Com-
mittees did. Rather than build Bluetooth as an adjunct to TCP/IP, it was
defined as a standalone protocol stack that includes all layers required by an
application. This means that it encompasses not only wireless communica-
tions but also service advertisement, addressing, routing, and a number of
application-level interfaces referred to as profiles.
• Radio Layer
When looking at the different layers of the Bluetooth protocol stack,
you will always find the raio layer first. Everything in Bluetooth runs
over the Radio Layer, which defines the requirements for a Bluetooth
radio transceiver, which operates in the 2.4GHz band. The radio
layer defines the sensitivity levels of the transceiver, establishes the
requirements for using Spread-spectrum Frequency Hopping and clas-
sifies Bluetooth devices into three different power classes:
• Baseband Layer
The next ”floor” in the Bluetooth protocol stack is the Baseband Layer,
Appendix A. Bluetooth Overview 71
Protocol types are first identified in the L2CAP. Data services are pro-
vided here using protocol multiplexing, segmentation and reassembly
operation, and group abstractions occur. L2CAP allows higher-level
protocols and applications to send and receive data packets up to 64
kilobytes. The L2CAP spends a lot of its time handling segmentation
and reassembly tasks.
These profiles are the primary entry into the stack for an application. Es-
sentially, they define the set of services that are available to that application.
Currently there are more than 25 different profiles defined or in the process
of being defined by the Bluetooth SIG. With so much variety, acquiring an
in-depth understanding of Bluetooth is not a trivial task. However, the ab-
straction by a single profile can provide an application the use of the profile
without such detailed knowledge. There are a number of profiles that are
exposed in very familiar forms. For instance, the SPP profile enables the
device implementing it to appear like a traditional serial port. This virtually
eliminates the need for the user to have specific Bluetooth knowledge, and
allows the radios to be integrated into applications very quickly.
The second and most complex element of Bluetooth security is access con-
trol. This type of security is only relevant when the module is connectable
and is designed to provide protection in this case. The general idea is that
remote devices must become trusted before they will be allowed to connect
and communicate with the device. In order to become trusted, a remote de-
vice must present a passkey that matches the stored local passkey. This only
needs to be done once, as both devices will remember their trusted status
and allow future connections with that specific device without exchanging
passkeys again.
After the Start Bit, the individual bits of the word of data are sent, with
the Least Significant Bit (LSB) being sent first. Each bit in the transmis-
sion is transmitted for exactly the same amount of time as all of the other
bits, and the receiver looks at the wire at approximately halfway through
the period assigned to each bit to determine if the bit is a 1 or a 0. For
example, if it takes two seconds to send each bit, the receiver will examine
the signal to determine if it is a 1 or a 0 after one second has passed, then
it will wait two seconds and then examine the value of the next bit, and so on.
The sender does not know when the receiver has ”looked” at the value of
the bit. The sender only knows when the clock says to begin transmitting
the next bit of the word.
When the entire data word has been sent, the transmitter may add a
Parity Bit that the transmitter generates. The Parity Bit may be used by
the receiver to perform simple error checking. Then at least one Stop Bit is
sent by the transmitter.
When the receiver has received all of the bits in the data word, it may
check for the Parity Bits (both sender and receiver must agree on whether
a Parity Bit is to be used), and then the receiver looks for a Stop Bit. If
the Stop Bit does not appear when it is supposed to, the UART considers
the entire word to be garbled and will report a Framing Error to the host
processor when the data word is read. The usual cause of a Framing Error
is that the sender and receiver clocks were not running at the same speed,
or that the signal was interrupted.
Regardless of whether the data was received correctly or not, the UART
automatically discards the Start, Parity and Stop bits. If the sender and
receiver are configured identically, these bits are not passed to the host.
If another word is ready for transmission, the Start Bit for the new word
can be sent as soon as the Stop Bit for the previous word has been sent.
Traditionally, a Baud Rate represents the number of bits that are actually
being sent over the media, not the amount of data that is actually moved
1
from one DTE device to the other. The Baud count includes the overhead
bits Start, Stop and Parity that are generated by the sending UART and
removed by the receiving UART. This means that seven-bit words of data
actually take 10 bits to be completely transmitted. Therefore, a modem ca-
pable of moving 300 bits per second from one place to another can normally
only move 30 7-bit words if Parity is used and one Start and Stop bit are
present.
If 8-bit data words are used and Parity bits are also used, the data rate
falls to 27.27 words per second, because it now takes 11 bits to send the
eight-bit words, and the modem still only sends 300 bits per second.
The formula for converting bytes per second into a baud rate and vice
versa was simple until error-correcting modems came along. These modems
1
DTE stands for Data Terminal Equipment. A typical Data Terminal Device is a
computer
Appendix B. Serial Communication Interface (USART) 79
receive the serial stream of bits from the UART in the host computer (even
when internal modems are used the data is still frequently serialized) and
converts the bits back into bytes. These bytes are then combined into pack-
ets and sent over the phone line using a Synchronous transmission method.
This means that the Stop, Start, and Parity bits added by the UART in the
DTE (the computer) were removed by the modem before transmission by
the sending modem. When these bytes are received by the remote modem,
the remote modem adds Start, Stop and Parity bits to the words, converts
them to a serial format and then sends them to the receiving UART in the
remote computer, who then strips the Start, Stop and Parity bits.
The reason all these extra conversions are done is so that the two modems
can perform error correction, which means that the receiving modem is able
to ask the sending modem to resend a block of data that was not received
with the correct checksum. This checking is handled by the modems, and
the DTE devices are usually unaware that the process is occurring.
By striping the Start, Stop and Parity bits, the additional bits of data that
the two modems must share between themselves to perform error-correction
are mostly concealed from the effective transmission rate seen by the sending
and receiving DTE equipment. For example, if a modem sends ten 7-bit
words to another modem without including the Start, Stop and Parity bits,
the sending modem will be able to add 30 bits of its own information that
the receiving modem can use to do error-correction without impacting the
transmission speed of the real data.
The use of the term Baud is further confused by modems that perform
compression. A single 8-bit word passed over the telephone line might rep-
resent a dozen words that were transmitted to the sending modem. The
receiving modem will expand the data back to its original content and pass
that data to the receiving DTE.
Modern modems also include buffers that allow the rate that bits move
across the phone line (DCE2 to DCE) to be a different speed than the speed
that the bits move between the DTE and DCE on both ends of the conver-
sation. Normally the speed between the DTE and DCE is higher than the
2
DCE stands for Data Communication Equipment. A typical Data Communications
Device is a Modem.
Appendix B. Serial Communication Interface (USART) 80
Because the number of bits needed to describe a byte varied during the
trip between the two machines plus the differing bits-per-seconds speeds that
are used present on the DTE-DCE and DCE-DCE links, the usage of the
term Baud to describe the overall communication speed causes problems and
can misrepresent the true transmission speed. So Bits Per Second (bps) is
the correct term to use to describe the transmission rate seen at the DCE
to DCE interface and Baud or Bits Per Second are acceptable terms to use
when a connection is made between two systems with a wired connection,
or if a modem is in use that is not performing error-correction or compression.
Modern high speed modems (2400, 9600, 14,400, and 19,200bps) in re-
ality still operate at or below 2400 baud, or more accurately, 2400 Symbols
per second. High speed modem are able to encode more bits of data into
each Symbol using a technique called Constellation Stuffing, which is why
the effective bits per second rate of the modem is higher, but the modem
continues to operate within the limited audio bandwidth that the telephone
system provides. Modems operating at 28,800 and higher speeds have vari-
able Symbol rates, but the technique is the same.
Servo Motors
can be seen on the right side of the circuit board. This pot allows the control
circuitry to monitor the current angle of the servo motor. If the shaft is at
the correct angle, then the motor shuts off. If the circuit finds that the angle
is not correct, it will turn the motor the correct direction until the angle is
correct. The output shaft of the servo is capable of travelling somewhere
around 180 degrees. Usually, its somewhere in the 210 degree range, but it
varies by manufacturer. A normal servo is used to control an angular motion
of between 0 and 180 degrees. A normal servo is mechanically not capable
of turning any farther due to a mechanical stop built on to the main output
gear.
The amount of power applied to the motor is proportional to the distance it
Appendix C. Servo Motors 84
needs to travel. So, if the shaft needs to turn a large distance, the motor will
run at full speed. If it needs to turn only a small amount, the motor will run
at a slower speed. This is called proportional control.
How do you communicate the angle at which the servo should turn? The
control wire is used to communicate the angle. The angle is determined by
the duration of a pulse that is applied to the control wire. This is called
Pulse Coded Modulation. The servo expects to see a pulse every 20 millisec-
onds (.02 seconds). The length of the pulse will determine how far the motor
turns. A 1.5 millisecond pulse, for example, will make the motor turn to the
90 degree position (often called the neutral position). If the pulse is shorter
than 1.5 ms, then the motor will turn the shaft to closer to 0 degress. If the
pulse is longer than 1.5ms, the shaft turns closer to 180 degress.
As you can see in the figure C.3, the duration of the pulse dictates the angle
of the output shaft (shown as the green circle with the arrow). Note that
the times here are illustrative, and the actual timings depend on the motor
manufacturer. The principle, however, is the same.
Perpendicular Regression
The Perpendicular regression is one of the methods used in the linear fitting
of the lines to a given data points. It aims to identify the line segment which
minimizes the total error in the perpendicular distance between each point
and the line segment. It needs to find the coefficeints a and b of the line
equaion y = ax + b that identify the candidate line segment. Here is the
mathematical method used to obtain the coefficeints a and b.
The total error ε is defined as
n
X
ε= hi (D.1)
i=1
n q
X
ε= ∆2X + ∆2Y (D.2)
i=1
and for simplicity, the error will be defined as the sum of the squares of
heights rather than the sum of heights:
n
X
ε= h2i (D.3)
i=1
n
X
ε= (∆2X + ∆2Y ) (D.4)
i=1
where
∆X = Px − Ix ∆Y = Py − Iy (D.5)
the point (Ix , Iy ) is the projection of the point (Px , Py ) on the line y = ax + b
and can be calculated as
Px + aPy − ab
Ix = (D.6)
a2 + 1
aPx + a2 Py + b
Iy = (D.7)
a2 + 1
Appendix D. Perpendicular Regression 87
from D.5
a2 Px − aPy + ab
∆X = (D.8)
a2 + 1
−aPx + Py − b
∆Y = (D.9)
a2 + 1
at the minimum total error, we have
∂ε ∂ε
=0 =0 (D.10)
∂a ∂b
by partially differntiating the the total error defined in equation D.4 with
respect to a and eqauting to zero, we obtain
n
∂ε ∂ X 2
= (∆ + ∆2Yi ) = 0
∂a ∂a i=1 Xi
n
∂ε X ∂∆X ∂∆Y
= (2∆X + 2∆Y )=0
∂a i=1
∂a ∂a
n
X n
X n
X n
X n
X
a Px2i −a Py2i +(a2 −1) Pxi Pyi +(b−a b) 2
Pxi +2ab Pyi −nab2 = 0
i=1 i=1 i=1 i=1 i=1
n
X n
X n
X n
X n
X Xn
2
a (n P xi P y i − P xi Pyi ) + a(n Px2i −n Py2i −( Pxi )2
i=1 i=1 i=1 i=1 i=1 i=1
n
X n
X n
X n
X
+( Pyi )2 ) − n P xi P y i + P xi P yi = 0
i=1 i=1 i=1 i=1
Appendix D. Perpendicular Regression 88
φa2 + ψa − φ = 0 (D.11)
where
n
X Xn n
X Xn Xn Xn Xn
2 2 2
φ=n P xi P y i − P xi Pyi ψ = n( P xi − Pyi )−( Pxi ) +( Pyi )2
i=1 i=1 i=1 i=1 i=1 i=1 i=1
By solving the two equations in D.11 and D.12 simultaneously, we can find
the values of a b as follows
p
ψ 2 + 4φ2
−ψ ±
a= (D.13)
2φ
P r(Occx,y |St )
A map is obtained by integrating these probabilities for all available sen-
sor readings, denoted by S1 , S2 , ..., St . In other words, the desired occupancy
value for each grid cell < x, y > can be written as the probability:
E.2 Proof
The update formula (1) follows directly from Bayes’s rule and the conditional
independence assumption. According to Bayess rule,
P r(Occx,y |S1 , S2 , ..., ST )
P r(Occx,y |S1 , S2 , ..., ST )
(E.2)
P r(ST |Occx,y , S1 , S2 , ..., ST − 1) P r(Occx,y |S1 , S2 , ..., ST − 1)
=
P r(ST |Occx,y , S1 , S2 , ..., ST − 1) P r(Occx,y |S1 , S2 , ..., ST − 1)
The update equation E.1 is nowobtained by solving E.5 for P r(Occx,y |S1 , S2 , ..., ST ),
using the fact that P r(Occx,y |S1 , S2 , ..., ST ) = 1 − P r(Occx,y |S1 , S2 , ..., ST ).
This probabilistic update rule, which is sound given our conditional indepen-
dence assumption, is frequently used for the accumulation of sensor evidence.
It differs from Bayes networks in that albeit the fact that occupancy causally
determines sensor readings {Sτ }τ =1,...,T and not the other way round, the
networks represent the inverse conditional probability: P r(Occx,y |St ). No-
tice that Equation E.1 can be used to update occupancy values incrementally,
i.e., at any point in time τ it suffices to memorize a single value per grid cell:
P r(Occx,y |S1 , S2 , ..., ST ). Technically speaking, this single value is a sufficient
statistic for S1 , S2 , ..., ST .
Appendix F
Examples on API
1. referenceAngle = MeasureCompass
[1] S. Thrun. Learning occupancy grids with forward sensor models Au-
tonomous Robots, 2002.
[3] Robotics with the Boe-Bot, Student Guide, VERSION 2.2, Parallax Inc.