You are on page 1of 48

DEGREE PROJECT IN TECHNOLOGY,

FIRST CYCLE, 15 CREDITS


STOCKHOLM, SWEDEN 2020

ODAR
Obstacle Detecting Autonomous Robot

EMILIA HALTORP

JOHANNA BREDHE

KTH ROYAL INSTITUTE OF TECHNOLOGY


SCHOOL OF INDUSTRIAL ENGINEERING AND MANAGEMENT
ODAR

Obstacle Detecting Autonomous Robot

JOHANNA BREDHE, EMILIA HALTORP

Bachelor’s Thesis at ITM


Supervisor: Nihad Subasic
Examiner: Nihad Subasic

TRITA-ITM-EX 2020:44
Abstract
The industry for autonomous vehicles is growing. Accord-
ing to studies nine out of ten traffic accidents are due to
the human factor, if the safety can get good enough in au-
tonomous cars they have the potential to save thousands of
lives every year. But obstacle detecting autonomous robots
can be used in other situations as well, for example where
the terrain is inaccessible for humans because of different
reasons.
In this project, a self navigating obstacle detecting robot
was made. The robot uses ultrasonic sensors to detect ob-
stacles and avoid them. An algorithm of the navigation
of the robot was created and implemented to the Arduino.
For driving the wheels, two servo motors were used. The
robot consisted of three wheels, two in the back to which
the servo motors were attached and one caster wheel in the
front. This made it possible to implement differential drive
which enabled quick and tight turns.
Tests were performed which showed that the robot could
successfully navigate in a room with various obstacles placed
out. The placement of the sensors worked good considering
the amount of sensors that was used. Improvements in de-
tection of obstacles could have been made if more sensors
had been used. The tests also confirmed that ultrasonic
sensors works good for this kind of task.

Keywords: Mechatronics, Autonomous Robot, Ultrasonic


Sensors, Servo Motors, Arduino
Referat
Autonom hinderupptäckande robot
Industrin för självkörande fordon växer. Enligt studier be-
ror nio av tio trafikolyckor på den mänskliga faktorn, om
säkerheten kan bli tillräckligt bra i självkörande bilar har
de potential att rädda tusentals liv varje år. Men hinder-
upptäckande självkörande robotar kan användas i andra
situationer också, till exempel i terräng som är otillgänglig
för människor av olika anledningar.
I det här projektet har en självnavigerande hinderupp-
täckande robot byggts. Roboten använder ultraljudssenso-
rer för att upptäcka hinder och unvika dem. En algoritm
för navigationen av roboten skapades och implementerades
i Arduinon. För drivningen av hjulen användes två servo-
motorer. Roboten hade tre hjul, två i den bakre änden till
vilka servomotorerna var fästa och ett länkhjul fram. Det
möjliggjorde differentialstyrning vilket också tillät snabba
och snäva svängar.
Tester genomfördes som visade att roboten kunde na-
vigera i ett rum med olika hinder utplacerade utan större
problem. Placeringen av sensorerna fungerade bra med tan-
ke på det antal sensorer som användes. Förbättringar av
hinderupptäckningen hade kunnat göras om fler sensorer
hade använts. Testerna bekräftade också att ultraljudssen-
sorer fungerar bra för denna typ av uppgift.

Nyckelord: Mekatronik, Autonom Robot,


Ultraljudssensorer, Servomotorer, Arduino
Acknowledgements

We would like to thank Nihad Subasic for his valuable lectures, and for his always
so quick and supportive responses. A special gratitude goes to Seshagopalan Tho-
rapalli Muralidharan for all the help and support he provided during this project.
It would not have been possible to accomplish this without the enormous help
with manufacturing and shipping things to us that we got from the department of
mechatronics at KTH, we are very grateful for that.

Johanna Bredhe & Emilia Haltorp


Stockholm, May 2020
Contents

1 Introduction 3
1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2 Theory 5
2.1 Ultrasonic sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Servo motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Differential drive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.4 Microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.4.1 Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3 Demonstrator 9
3.1 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1.1 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2.1 Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2.2 Ultrasonic Sensor . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2.3 Servo Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.3 Electronics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

4 Tests and results 15


4.1 Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.2 Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.3 Sensor tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.4 Obstacle tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

5 Discussion and conclusions 19


5.1 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.2 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

6 Further work 21
Bibliography 23

Appendices

A Arduino Code

B Ultrasonic Sensor Data Sheet


List of Figures

3.1 A flowchart over the algorithm, made with draw.io. . . . . . . . . . . . . 10


3.2 The construction made in Autodesk Fusion. . . . . . . . . . . . . . . . . 11
3.3 Ultrasonic Sensor [16] . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.4 A picture of the servo motors that were used [19] . . . . . . . . . . . . . 12
3.5 An illustration over the electric circuit, made on Tinkercad.com. . . . . 14

4.1 A picture showing the final construction. . . . . . . . . . . . . . . . . . . 15


4.2 A picture of how the test was conducted. . . . . . . . . . . . . . . . . . 17
4.3 A picture of the front sensor during the test. . . . . . . . . . . . . . . . 18
List of Tables

4.1 Results from test with sensor. . . . . . . . . . . . . . . . . . . . . . . . . 17


List of Abbreviations

IDE Integrated Development Environment

PWM Pulse Widht Modulation

CPU Central Processing Unit

ALU Arithmetic Logic Unit

RAM Random Access Memory

ROM Read Only Memory

USB Universal Serial Bus

GPS Global Positioning System

USB Universal Serial Bus

1
Chapter 1

Introduction

Autonomous vehicles can be used for a lot of different purposes and the industry
is growing. With autonomous vehicles follows new challenges and safety is one
that is very important. If the safety is good enough autonomous vehicles have the
potential to save thousands of lives every year. Studies show that nine out of ten
traffic accidents are due to the human factor [1]. Other benefits of autonomous
vehicles could be improved energy efficiency and reduced driving costs [2]. This
report presents how an obstacle detecting autonomous robot was developed.

1.1 Background
Autonomous robots are freely moving and can operate without direct human super-
vision. They are capable of making their own decisions based on what it perceives
and has been programmed to recognize.
An obstacle detecting autonomous robot has many applications. The technique
can be implemented in cars for example. If the control system is fast enough it can
decrease the speed quick and avoid accidents with obstacles that occurs rapidly.
With the traffic becoming more complex with new situations the requirements on
the control system and algorithms increases [3].
Autonomous robots can also be used in situations where it is dangerous or in
any other way inappropriate for humans to be.

1.2 Purpose
The purpose of this Bachelor’s thesis project was to build a robot that could detect
obstacles in its path and avoid them by turning in another direction. Following
research questions will be investigated in this thesis:

3
CHAPTER 1. INTRODUCTION

• How should the robot navigate?

• How could the robot detect obstacles in its lane and what should it do when it
encounters them?

– What kind of sensors are needed?


– Where should the sensors be placed?

1.3 Scope
Due to limited time and a limited budget of 1000 SEK this project had some con-
straints. The budget limited the size of the prototype and its components had to
be relatively inexpensive.
Tests were done in ideal conditions, i.e. the robot was driven in an inside
environment and on a flat surface.
During the time this thesis was written the world suffered a great pandemic.
The pandemic struck in the middle of the project and no one was prepared. This
led to a number of challenges as we were no longer allowed to be on campus and
therefore not in the lab where all of the equipment and tools we needed were. To
partially solve this, things we required was shipped to us and we are very grateful
for that as it was crucial for our work. However, this led to everything taking a
longer amount of time and as we did not have access to all the equipment we needed
some provisional solutions were made.

1.4 Method
The first step of this project was to formulate the research questions. The next
step was to gather information about autonomous robots and obstacle detection.
This was done by reading articles and investigating projects from previous years
related to the subject. From the literature study, components that were needed
for the prototype could be determined. A prototype was then made. The program
Autodesk Fusion was used to create a design. Axles and brackets for the sensors
were 3D-printed. The bottom plate was designed in Adobe Illustrator and cut out
with a laser cutter. When the construction was completed, the Arduino software
Integrated Development Environment (IDE) was used to program the algorithm.
To avoid collisions, the robot must be able to identify all obstacles in its path. In
order to achieve this, the robot was equipped with sensors to detect objects. Tests
were made where obstacles were placed in front of the robot while it was driving
forward to investigate what the best placement of the sensors were.

4
Chapter 2

Theory

This chapter presents the theory necessary to answer the research questions and
build an autonomous obstacle avoiding robot.

2.1 Ultrasonic sensors


When wanting to measure distance between a moving object and obstacles that
may appear around it, ultrasonic sensors are a good alternative. They are cheap
but not the most precise. Ultrasonic sensors measures distance by transmitting
pulses of ultrasonic sound-waves which propagates through the air and is reflected
and received by the sensor when there is an object in front of them. If there is an
object in front of the sensor, the sound-waves reflects and returns to the receiver
[7]. One problem with them is that if the object in front of the sensor is tilted
relative to the sensors transceiver, only such a small amount of the sound-wave will
be reflected back to the sensor that the object won’t be detected. This can also
cause problems with the measured distance, if the area where the sound-waves hits
the object is a little bit tilted the distance may be detected as longer or shorter
than it actually is [18].
To calculate the distance between the object on which the sensor is placed and
the obstacle, equation 2.1 can be used [8].

tc
l= (2.1)
2
Where l is the distance, t is the time and c is the speed of sound. It is divided
by two because the time is measured from when the signal is transmitted from the
sensor to when it is received and in that time the sound-waves have traveled the
distance twice, back and forth.
What makes the calculations less accurate is the value of the speed of sound.
Since the speed of sound depends on temperature it is not ideal to use the same
value all the time. What could be made to improve this is using a temperature
sensor and constantly update the value [7].

5
CHAPTER 2. THEORY

2.2 Servo motors


Servo motors are simple electric motors that offers closed-loop position control [9].
They are controlled by a signal, also known as Pulse Width Modulation (PWM).
PWM is a technique where digital control is used to create a square wave, which
is a signal that switches between full on and full off. From PWM you get analog
results with digital means. It simulates different voltages between full on and full
off depending on the portion of time that the signal spends on versus off. If the
on-off pattern is repeated fast enough, it will appear as if the signal is a steady
voltage [10].
The servo motor provides control of linear or angular position, velocity and
acceleration. They differ from each other in how many degrees they can rotate and
how much they can torque. Servo motors have many different applications, such as
robotics, printers and automatic door openers.

2.3 Differential drive


Differential drive is a method in which two wheels are driven with one motor each.
This enables the robot to move in all directions easily. If both wheels are rotating
with the same speed in the same direction the robot will either go straight forward
or backwards depending on the direction in which the wheels rotates. To make the
robot turn, one wheel will have to have a faster speed while still going in the same
direction as the other one, the robot will then turn away from the faster rotating
wheel. The robot can also spin around the midpoint in between the wheels. To make
that happen, both wheels needs to go at the same speed but in different directions.
The linear velocity of the robot can be calculated as shown by equation 2.2 and
the angular velocity as shown by 2.3,

(ωR + ωL )r
v= (2.2)
2
(ωR − ωL )r
ω= (2.3)
L
where r is the wheel radius, L the distance between the wheels and ωR , ωL the
angular velocity of the right and left wheels [13].

2.4 Microcontroller
A microcontroller is a small computer with most of the required support chips
available. They are often embedded inside other devices and can therefore control
features and actions of the product. The microcontroller controls the device by
taking its input and sending signals to different components in the device [11].
The microcontroller consists of a microprocessor and the primary memory con-
nected to a system bus. The microprocessor contains the Central Processing Unit

6
2.4. MICROCONTROLLER

(CPU) with the Arithmetic Logic Unit (ALU), it is the CPU that executes pro-
grams. The cache memory can also be found in the microprocessor, this is where
the next operation is stored. The system bus is the primary pathway between CPU
and memory, this is where addresses, data and control signals are transmitted. The
primary memory is called Random Access Memory (RAM). RAM means that ac-
cess to a memory cell is not sequential, which means that it takes just as long to
retrieve the information no matter what memory location it is on. It is a very fast
component that temporarily stores information that is needed in the moment and
near future. Among the primary memories are also various types of Read Only
Memory (ROM), these types of memories keep its content regardless of whether or
not it has power. The microcontroller also consists of the external bus, that enables
connection to external devices and components [12].

2.4.1 Arduino
The microcontroller used in this project is an Arduino Uno. Arduino is an open-
source platform. The Arduino boards are easily programmed on the Arduino Soft-
ware (IDE) [14]. Arduino Uno is based on the microcontroller ATmega328P which
has a flash memory of 32 kB. It has 14 digital input/output pins and six of these
can be used as PWM outputs. The board can be connected to a computer with a
Universal Serial Bus (USB) cable to power it or to an external power supply, the
recommended voltage input is 7-12 V. If it is powered with less than 7 V it may
become unstable and more than 12 V may cause the voltage regulator to overheat
and damage the board [15].

7
Chapter 3

Demonstrator

This chapter will present the hardware and software that was needed in order to
build the autonomous obstacle detecting robot. It will also include the electrical
circuit that shows how the different components have been connected to the Ar-
duino.

3.1 Software

The code for the microcontroller was created in Arduino IDE and can be found in
Appendix A.

3.1.1 Algorithm

A flowchart was created to describe the algorithm that the robot uses. The flowchart
can be seen in figure 3.1. The robot started with driving forward. If it encountered
an obstacle in front of its path it checked if there was an obstacle to the right, if not
it turned 90° to the right and then continued to drive forward. In the occasion it
was an obstacle to the right as well the robot checked to its left and if there was no
obstacle there it would turn 90° left and continue forward. In the case where there
were obstacles both in front and to both sides the robot would check behind and if
the way was free there it would reverse and then again check its right and left sides.
If a situation occurred where there were obstacles all around the robot the motors
would stop and the robot would have to be moved manually.

9
CHAPTER 3. DEMONSTRATOR

Figure 3.1. A flowchart over the algorithm, made with draw.io.

10
3.2. HARDWARE

3.2 Hardware
The final construction is shown in figure 4.1. Everything was created and designed
in Autodesk Fusion 360. The bottom plate was made out of 6 mm thick acrylic and
laser cut with Epilog Laser Fusion M2. Wheel axles and sensor mounts were 3D
printed using Ultimaker2 . In the figure, no jumper wires are added.

Figure 3.2. The construction made in Autodesk Fusion.

3.2.1 Arduino Uno


The Arduino Uno controls the two servo motors and also the four ultrasonic sen-
sors. Both the sensors and servo motors were connected to the digital input pins.
Connecting the two servo motors to separate pins enables control of the motors
separately which is needed for differential drive.

3.2.2 Ultrasonic Sensor


Four ultrasonic sensors of type HC-SR04 were used in this project, see figure 3.3.
These sensors can identify a distance from 2-400 cm. They require a current con-
sumption of 2 mA and a 5 V power supply [16]. One sensor was placed in each
direction of the robot; in the front, to the left, to the right and in the back. The
robot is programmed to stop when an obstacle occurs within 15 cm ahead of it, this

11
CHAPTER 3. DEMONSTRATOR

is due to the problem brought up in chapter 2.1 about measurement problems. To


minimise the risk of the robot hitting an obstacle due to miscalculations it is good
to make it stop when there is still some distance left to the obstacle [18]. The sensor
to the right then controls if there is an obstacle to the right, if there is no obstacle
there, the robot turns right. If there is an obstacle to the right, the sensor to the
left controls if there is an obstacle in its way, the robot turns left if no obstacle has
been detected there. In the case it occurs to be obstacles both in front of the robot
and to the left and right the sensor in the back will check if there is an obstacle
behind. If there is, the robot stops and if it is not it reverses.

Figure 3.3. Ultrasonic Sensor [16]

3.2.3 Servo Motor


Two servo motors of model Tower Pro SG-5010 were used for the two wheels that
were driven with differential drive, they can be seen in figure 3.4. This servo motor
is continuous and can turn 360°. Its dimensions are 40.8 x 20.1 x 38 mm and its
weight 40 g. It requires a 4.8-6 V power supply [17].

Figure 3.4. A picture of the servo motors that were used [19]

12
3.3. ELECTRONICS

3.3 Electronics
The electrical components that the robot consisted of were an Arduino Uno, two
servo motors and four ultrasonic sensors. A 9 V battery was used to power the
robot but as some components required 5 V, a voltage regulator and two capacitors
were also needed. The circuit is shown in figure 3.5.

13
CHAPTER 3. DEMONSTRATOR

14

Figure 3.5. An illustration over the electric circuit, made on Tinkercad.com.


Chapter 4

Tests and results

This chapter presents the results of the demonstrator that was built in this project
and the tests which was performed. The final construction can be seen in figure 4.1.

Figure 4.1. A picture showing the final construction.

15
CHAPTER 4. TESTS AND RESULTS

4.1 Movement

The movement of the robot was controlled by the sensors as different values were
sent to the servos due to the distance to obstacles around the robot. Therefore,
tests to check the movement of the robot were made where obstacles were placed in
front of it to make sure it could turn as desired.

4.2 Navigation

The robot was tested in an inside environment where obstacles were placed around
it. While driving, it was observed to confirm that it worked as intended. First, an
object was placed in front of the robot to make sure it turned right when it discovered
the object. Then, an object was also placed to the right to ensure it turned left that
time. When the code had been adjusted so that these things worked an obstacle
was placed to the left as well to see if the robot then reversed. Lastly, obstacles
were placed all around the robot to make sure it would stop completely. After all of
the testing an obstacle course was built. Minor adjustments in the code were made
until the robot drove through the obstacle course without difficulties.

4.3 Sensor tests

In order to decide what distance from the obstacles the robot should stop, tests
were made with the ultrasonic sensors. Tests were done to find out how accurate
the sensors were. An obstacle was placed at a certain distance from the sensor, the
distance was measured with a ruler and then compared with the distance specified
by the sensor. This is shown in figure 4.2. The result showed that the sensors
are precise except in the case where the object is placed very close to the sensor.
According to the manufacturer’s specifications (which can be seen in Appendix B),
the sensors can identify a distance from 2-400 cm. The result is presented in table
4.3.

16
4.4. OBSTACLE TESTS

Figure 4.2. A picture of how the test was conducted.

Table 4.1. Results from test with sensor.


Measured Distance
distance from sensor
0 cm 0 cm
1 cm 2 cm
5 cm 5 cm
15 cm 15 cm
30 cm 30 cm

4.4 Obstacle tests


Obstacles of various shapes and sizes were placed in front of the robot to investigate
which objects the sensors were able to detect. The sensors were attached on top of
the bottom plate which generated a height difference of 5 cm between the ground
and the center of the sensors. This made it interesting to investigate the sensors’
ability to detect low obstacles in its path. The test was initiated by placing an
object with a length of 15 cm and a height of 16 cm in front of the robot. This
obstacle was easily detected by the robot. Another object with the dimensions
4,5 cm x 5,5 cm was placed in front of the construction and was once again easily

17
CHAPTER 4. TESTS AND RESULTS

discovered, this is shown in figure 4.3. When an object with the a height of 2,5
cm was tested, the robot could not detect it. In order to find the lowest detectable
height, objects with a height of 3,5 cm, 4 cm and lastly 5 cm were tested. The
result showed that the object with height 5 cm was the lowest obstacle that could
be identified by the sensors. This test provided useful information about which
obstacles that were suitable to include in the obstacle course that was later built
and what improvements that could have been done to the robot.

Figure 4.3. A picture of the front sensor during the test.

18
Chapter 5

Discussion and conclusions

This chapter aims to discuss the performance and results of the demonstrator. Final
conclusions will be drawn and examples of further work will also be brought up.

5.1 Discussion
The goal of this project was to answer the research questions and to build an
autonomous obstacle avoiding robot. Even though some improvements could have
been made if we have had more time we are happy with the results.
The bottom plate could have been designed in a way that better fits the servo
motors. A chassis that fits the bottom plate could have been created to hide the
jumper wires and some of the components. This would also give a better overall
impression of the construction.
If the sensors had been attached closer to the ground, at the same height as
the bottom plate or below it, it would have been possible for the robot to identify
objects with a height less than 5 cm. This would extend the robot’s applications.
To change the height of the sensors, it would be necessary to change the design of
the brackets where the sensors are attached.
We experienced some trouble with a sensor returning only zero as the distance
to an obstacle even though an obstacle was not in front of it. This led to that
our algorithm did not work as expected. After some testing with different codes
sent to the Arduino and changing the pins on the Arduino to which the sensor was
connected to we discovered that the problem probably was the pins. Some pins
worked perfectly and some pins did not work at all, while it was also some pins that
sometimes returned the distance to zero and sometimes a very large number like 800
cm but sometimes also the correct number. It is not clear if this is a normal problem
or if something was wrong with our Arduino. Since we had to use almost all of the
digital pins we could not only choose to use the ones which worked perfectly fine.
Our solution to this was to put the worst functioning sensor in the back as this one
was used least. This though, is not a good solution and if we had discovered this
problem a little bit earlier we could probably have made a better solution. Another

19
CHAPTER 5. DISCUSSION AND CONCLUSIONS

solution to this could have been to change the code slightly so that it would receive
multiple values from this sensor and calculate a mean value from those. It is unclear
if this would solve the problem though as the false values most of the time were
completely wrong.
As mentioned earlier, this project started at the time when Covid-19 began
spreading. In the middle of the project it escalated to a pandemic which caused
the universities in Sweden to close and our remaining work had to be done from
home. Since the closing of KTH was declared almost halfway in to the project
we were then in the early constructing phase. At the time we had to leave KTH
our construction was not assembled and the parts that we were supposed to 3D-
print and laser cut was not done yet. Thanks to the assistants who still had access
to the lab at KTH we could send files to them and get the parts manufactured
anyway and shipped to our homes. This though led to that we did not have the
opportunity to adjust and remake the parts to do several prototypes and in this
way develop the robot. With not being able to make a new part we had to come up
with some special solutions which led to that everything was not optimal but still
worked. Even though things did not turn out exactly the way we wanted and that
we had to face bigger challenges than we thought in the beginning, we think that
this has developed our problem solving skills more than it should have without the
pandemic. The situation really had us thinking outside the box.

5.2 Conclusion
Following are the research questions that were investigated in this project and the
answers to them:

• How should the robot navigate?

The robot can successfully navigate with the algorithm described in chapter
3.1.1.

• How could the robot detect obstacles in its lane and what should it do when it
encounters them?

– What kind of sensors are needed?


– Where should the sensors be placed?

Ultrasonic sensors was the type of sensors that was chosen. This due to that they
are good at detecting obstacles relative to the price of them. They are placed one
in each direction; front, right, left and back. This placement is the most profitable
for the amount of sensors we have got but as it is now, the robot can not detect
all obstacles. The sensors has got a measuring angle of 15 degrees according to the
data sheet which can be found in Appendix B. This makes it impossible for only
four sensors to detect all obstacles that can occur around the robot.

20
Chapter 6

Further work

A lot of things could be done to improve the performance of this robot. It would also
be possible to add different functions to develop the robot even more. To improve
the obstacle detection, more ultrasonic sensors could be added. This could make
sure that the robot does not have any angles where it can not detect obstacles.
Servo motors could also be added to make the sensors turn and detect a bigger
angle than if they are fixed, then probably four sensors would be enough. An idea
is also to add other types of sensors to detect obstacles that the ultrasonic sensors
may miss.
To solve the problem with the sensors not detecting obstacles below five cm, the
placement of the sensors could be improved. For example they could be placed on
the bottom plate or even below it. If that would cause a problem with detecting
obstacles higher up, a sensor could also be placed above the bottom plate a little
bit higher than the current placement.
To improve the navigation a Global Positioning System (GPS) could be added.
This could help with keeping track of the positioning of the robot and also make it
possible for it to return to it’s starting point when the battery is about to run out.
With a GPS it would also be possible to set an end point for the robot to travel to.
Maybe, both the microcontroller and algorithm would have to be updated then.
Another improvement would be to develop the algorithm so that the robot can
drive towards a predetermined goal. Currently, the robot changes direction when
an obstacle arises instead of going around it. If this were to be implemented, the
robot could be used in more areas.
Solar panels could be added to help recharge the battery to make the robot more
self sufficient.

21
Bibliography

[1] A. Pernestål, ‘Varning för självkörande bilar’, 2019. [Online]. Available: https:
//fof.se/tidning/2019/3/artikel/varning-for-sjalvkorande-bilar/
[Accessed: 23- Jan- 2020].
[2] W. Zhang, ‘Planning and evaluation of autonomous vehicles in freight and pub-
lic transport services’, PhD dissertation, KTH Royal Institute of Technology,
Stockholm, 2019. [Online]. Available: http://www.diva-portal.org/smash/
get/diva2:1316459/FULLTEXT01.pdf [Accessed: 23- Jan- 2020].
[3] D. Madås et al., ‘On Path Planning Methods for Automotive Collision Avoid-
ance’, in 2013 IEEE Intelligent Vehicles Symposium: IV 2013: Gold Coast City,
Australia, 23-26 June 2013, 2013, pp. 931–937. [Online]. Available: https://
doi-org.focus.lib.kth.se/10.1109/IVS.2013.6629586 [Accessed: 23- Jan-
2020].
[4] C. Bondesson and E. Stigenius, ‘Autonom bil med enkapseldator och ul-
traljudssensorer: tillämpning av en Arduino mikrokontrollerplattform och HC-
SR04 sensorer’, Dissertation, 2015. [Online]. Available: http://urn.kb.se/
resolve?urn=urn:nbn:se:uu:diva-255762 [Accessed: 28- Jan- 2020].
[5] O. Nordström and A. Axelsson, ‘Pathfinder: Autonomous Guided Vehicle us-
ing Infrared Light’, Dissertation, 2018. [Online]. Available: http://urn.kb.se/
resolve?urn=urn:nbn:se:kth:diva-230241 [Accessed: 28- Jan- 2020].
[6] N. Lorentzon, L. Strömberg, I. Wikander, and M. Bengtson, ‘Konstruktion
och programmering av Arduino-baserad robot för kartläggning av rum genom
ultraljud’, Dissertation, 2019. [Online]. Available: http://www.diva-portal.
org/smash/get/diva2:1333043/FULLTEXT01.pdf [Accessed: 28- Jan- 2020].
[7] D. Webster, ‘A pulsed ultrasonic distance measurement system based upon
phase digitizing,’ in IEEE Transactions on Instrumentation and Measurement,
vol. 43, no. 4, pp. 578-582, Aug. 1994. [Online]. Available: https://doi.org/
10.1109/19.310171 [Accessed: 12- Feb- 2020]
[8] Ultrasonic Sensor HC-SR04 and Arduino Tutorial [Online]. Avail-
able: https://howtomechatronics.com/tutorials/arduino/
ultrasonic-sensor-hc-sr04/ [Accessed: 12- Feb -2020]

23
BIBLIOGRAPHY

[9] M. Akar, I. Temiz, ’Motion controller design for the speed control of DC servo
motor’, in International journal of applied mathematics and informatics, issue
4, vol.1, 2007. [Online]. Available: http://citeseerx.ist.psu.edu/viewdoc/
download?doi=10.1.1.548.1319&rep=rep1&type=pdf [Accessed: 14- Feb -
2020]

[10] Arduino, ’PWM’ April 2020. [Online]. Available: https://www.arduino.cc/


en/tutorial/PWM [Accessed: 28- Apr -2020]

[11] D. Calcutt, F. Cowan, H. Parchizadeh, ”Introduction to Microcontrollers”, in


8051 Microcontroller: An Applications Based Introduction. Burlington, MA,
USA: Elsevier, 2004. [Online]. Available: https://doi-org.focus.lib.kth.
se/10.1016/B978-0-7506-5759-4.X5000-X [Accessed: 14- Feb -2020]

[12] H.Johansson, ’Elektroteknik’, 2013. KTH Institutionen för Maskinkonstruk-


tion, Mekatronik.

[13] E. Maulana, M. A. Muslim and A. Zainuri, ”Inverse kinematics of a two-wheeled


differential drive an autonomous mobile robot,” 2014 Electrical Power, Elec-
tronics, Communicatons, Control and Informatics Seminar (EECCIS), Malang,
2014, pp. 93-98. [Online]. Available: https://doi.org/10.1109/EECCIS.2014.
7003726 [Accessed: 14- Feb- 2020]

[14] Arduino, ’Arduino Introduction’, February 2020. [Online]. Available: https:


//www.arduino.cc/en/Guide/Introduction [Accessed: 15- Feb- 2020]

[15] Arduino, ’Arduino Uno’, February 2020. [Online]. Available: https://store.


arduino.cc/arduino-uno-rev3 [Accessed: 15- Feb- 2020]

[16] Elektrokit, ’Distance sensor ultrasound’. [Online].


Available: https://www.electrokit.com/en/product/
distance-sensor-ultrasound-hc-sr04-2-400cm/ [Accessed: 23- Mar-
2020]

[17] Elektrokit, ’Servo large 360°’. [Online]. Available: https://www.electrokit.


com/en/product/servo-large-360/ [Accessed: 23- Mar- 2020]

[18] J. Borenstein and Y. Koren, ”Obstacle avoidance with ultrasonic sensors,” in


IEEE Journal on Robotics and Automation, vol. 4, no. 2, pp. 213-218, April
1988. [Online]. Available: https://doi-org.focus.lib.kth.se/10.1109/56.
2085 [Accessed: 28- Mar -2020]

[19] Electrokit, ’Servo stort 360°’. [Online]. Available: https://www.electrokit.


com/produkt/servo-stort-360/ [Accessed: 29- Apr -2020]

24
Appendix A

Arduino Code

/∗ Johanna Bredhe and E m i l i a H a l t o r p


ODAR − O b s t a c l e D e t e c t i n g Autonomous Robot
MF133X − B a c h e l o r ’ s t h e s i s i n M e c h a t r o n i c s
TRITA−ITM−EX 2 0 2 0 : 4 4
KTH, 04−05−2020 ∗/

#include <NewPing . h>


#include <Servo . h>

#define SONAR NUM 4 // Number o f s e n s o r s

#define MAX DISTANCE 300

// 0 : f r o n t , 1 : r i g h t , 2 : l e f t , 3 : b a c k
NewPing s o n a r [SONAR NUM] = { // Sensor o b j e c t a r r a y .
NewPing ( 5 , 1 3 , MAX DISTANCE) , // Each s e n s o r ’ s t r i g g e r pin , echo pin ,
NewPing ( 6 , 4 , MAX DISTANCE) , // and max d i s t a n c e t o p i n g .
NewPing ( 1 2 , 1 1 , MAX DISTANCE) ,
NewPing ( 8 , 7 , MAX DISTANCE) ,
};

Servo l e f t s e r v o ; // Servo o b j e c t f o r each s e r v o


Servo r i g h t s e r v o ;

int distance front = 0; // I n i t i a l i s i n g v a r i a b l e s


int distance right = 0;
int distance left = 0;
int distance back = 0;
int moving ;
int pos ;
void s e t u p ( ) {
S e r i a l . begin (9600);
l e f t s e r v o . attach ( 1 0 ) ; // A t t a c h s e r v o s t o p i n 10 and 3
rightservo . attach ( 3 ) ;
}

// ∗∗ Robot movement f u n c t i o n s ∗∗
// The f u n c t i o n s r e c e i v e i n f o r m a t i o n a b o u t how many m i c r o s e c o n d s
// t h e r o b o t s h o u l d d r i v e i n t h a t d i r e c t i o n
// pwm s i g n a l s a r e s e n t t o t h e s e r v o s

int f o r w a r d ( int moving ) {


l e f t s e r v o . writeMicroseconds (1300);
rightservo . writeMicroseconds (1700);
d e l a y ( moving ) ;
return moving ;
}

int l e f t ( int moving ) {


l e f t s e r v o . writeMicroseconds (1700);
rightservo . writeMicroseconds (1700);
d e l a y ( moving ) ;
return moving ;
}

int r i g h t ( int moving ) {


l e f t s e r v o . writeMicroseconds (1300);
rightservo . writeMicroseconds (1300);
d e l a y ( moving ) ;
return moving ;
}

int r e v e r s e ( int moving ) {


l e f t s e r v o . writeMicroseconds (1700);
rightservo . writeMicroseconds (1300);
d e l a y ( moving ) ;
return moving ;
}

int s t o p s ( int moving ) {


l e f t s e r v o . writeMicroseconds (1500);
rightservo . writeMicroseconds (1500);
d e l a y ( moving ) ;
return moving ;
}

void l o o p ( ) {
// C a l c u l a t i n g and p r i n t i n g o u t t h e
// d i s t a n c e t o any o b s t a c l e i n f r o n t o f t h e r o b o t
S e r i a l . print ( ” Distance front : ” ) ;
S e r i a l . p r i n t ( s o n a r [ 0 ] . ping cm ( ) ) ;
S e r i a l . p r i n t l n ( ”cm” ) ;
d i s t a n c e f r o n t = s o n a r [ 0 ] . ping cm ( ) ;

// As l o n g as no o b s t a c l e has been d e t e c t e d i n f r o n t
// o f t h e r o b o t i t s h o u l d k e e p moving f o r w a r d
while ( d i s t a n c e f r o n t > 1 5 ) {
pos = f o r w a r d ( 5 0 0 ) ;
d i s t a n c e f r o n t = s o n a r [ 0 ] . ping cm ( ) ;
}
// I f an o b s t a c l e i s d e t e c t e d , t h e o t h e r s e n s o r s a r e c h e c k e d
// The r o b o t s t o p s f o r 300 ms
i f ( d i s t a n c e f r o n t < 15) {
pos = s t o p s ( 3 0 0 ) ;
d i s t a n c e r i g h t = s o n a r [ 1 ] . ping cm ( ) ;
d i s t a n c e l e f t = s o n a r [ 2 ] . ping cm ( ) ;
d i s t a n c e b a c k = s o n a r [ 3 ] . ping cm ( ) ;

Serial . print ( ” Distance right : ” );


Serial . p r i n t l n ( s o n a r [ 1 ] . ping cm ( ) ) ;
Serial . print ( ” Distance l e f t : ” );
Serial . p r i n t l n ( s o n a r [ 2 ] . ping cm ( ) ) ;

// I f t h e r e i s no o b s t a c l e t o t h e r i g h t
// The r o b o t t u r n s r i g h t
i f ( d i s t a n c e r i g h t > 15 && d i s t a n c e r i g h t != 0 ) {
pos = r i g h t ( 1 6 0 0 ) ;
d i s t a n c e f r o n t = s o n a r [ 0 ] . ping cm ( ) ;
// I f t h e r e i s no o b s t a c l e i n f r o n t o f i t now , i t
// d r i v e s f o r w a r d u n t i l an o b s t a c l e i s d e t e c t e d
while ( d i s t a n c e f r o n t > 1 5 ) {
pos = f o r w a r d ( 5 0 0 ) ;
d i s t a n c e f r o n t = s o n a r [ 0 ] . ping cm ( ) ;
}
}

// Same t h i n g happes i f t h e r e i s an
// o b s t a c l e t o t h e r i g h t , i t j u s t t u r n s l e f t i n s t e a d
e l s e i f ( d i s t a n c e l e f t > 15 && d i s t a n c e l e f t != 0 ) {
pos = l e f t ( 1 6 0 0 ) ;
d i s t a n c e f r o n t = s o n a r [ 0 ] . ping cm ( ) ;
while ( d i s t a n c e f r o n t > 1 5 ) {
pos = f o r w a r d ( 5 0 0 ) ;
d i s t a n c e f r o n t = s o n a r [ 0 ] . ping cm ( ) ;
}
}

// I f t h e o n l y f r e e way i s b e h i n d t h e r o b o t , i t w i l l r e v e r s e
else i f ( distance back > 15) {
pos = r e v e r s e ( 2 0 0 0 ) ; // i t r e v e r s e s f o r 2 s e c o n d s
d i s t a n c e r i g h t = s o n a r [ 1 ] . ping cm ( ) ;
d i s t a n c e l e f t = s o n a r [ 2 ] . ping cm ( ) ;
// t h e n t u r n r i g h t i f i t ’ s f r e e t h e r e
i f ( d i s t a n c e r i g h t > 15) {
pos = r i g h t ( 1 6 0 0 ) ;
d i s t a n c e f r o n t = s o n a r [ 0 ] . ping cm ( ) ;
while ( d i s t a n c e f r o n t > 1 5 ) {
pos = f o r w a r d ( 5 0 0 ) ;
d i s t a n c e f r o n t = s o n a r [ 0 ] . ping cm ( ) ;
}
}
// o t h e r w i s e i t t u r n s l e f t
else i f ( d i s t a n c e l e f t > 15) {
pos = l e f t ( 1 6 0 0 ) ;
d i s t a n c e f r o n t = s o n a r [ 0 ] . ping cm ( ) ;
while ( d i s t a n c e f r o n t > 1 5 ) {
pos = f o r w a r d ( 5 0 0 ) ;
d i s t a n c e f r o n t = s o n a r [ 0 ] . ping cm ( ) ;
}
}
else { // I f i t ’ s o b s t a c l e s e v e r y w h e r e i t has t o s t o p
pos = s t o p s ( 3 0 0 0 ) ;
}
}

else { // I f o b s t a c l e s a r e d e t e c t e d i n e v e r y d i r e c t i o n
pos = s t o p s ( 3 0 0 0 ) ; // around t h e r o b o t , i t s t o p s
}
}
}
Appendix B

Ultrasonic Sensor Data Sheet


Tech Support: services@elecfreaks.com

Ultrasonic Ranging Module HC - SR04

 Product features:

Ultrasonic ranging module HC - SR04 provides 2cm - 400cm non-contact


measurement function, the ranging accuracy can reach to 3mm. The modules
includes ultrasonic transmitters, receiver and control circuit. The basic principle
of work:
(1) Using IO trigger for at least 10us high level signal,
(2) The Module automatically sends eight 40 kHz and detect whether there is a
pulse signal back.
(3) IF the signal back, through high level , time of high output IO duration is
the time from sending ultrasonic to returning.
Test distance = (high level time×velocity of sound (340M/S) / 2,

 Wire connecting direct as following:

 5V Supply
 Trigger Pulse Input
 Echo Pulse Output
 0V Ground

Electric Parameter

Working Voltage DC 5 V
Working Current 15mA
Working Frequency 40Hz
Max Range 4m
Min Range 2cm
MeasuringAngle 15 degree
Trigger Input Signal 10uS TTL pulse
Echo Output Signal Input TTL lever signal and the range in
proportion
Dimension 45*20*15mm
Vcc Trig Echo GND

Timing diagram

The Timing diagram is shown below. You only need to supply a short 10uS
pulse to the trigger input to start the ranging, and then the module will send out
an 8 cycle burst of ultrasound at 40 kHz and raise its echo. The Echo is a
distance object that is pulse width and the range in proportion .You can
calculate the range through the time interval between sending trigger signal and
receiving echo signal. Formula: uS / 58 = centimeters or uS / 148 =inch; or: the
range = high level time * velocity (340M/S) / 2; we suggest to use over 60ms
measurement cycle, in order to prevent trigger signal to the echo signal.
 Attention:

  The module is not suggested to connect directly to electric, if connected


electric, the GND terminal should be connected the module first, otherwise,
it will affect the normal work of the module.
  When tested objects, the range of area is not less than 0.5 square meters
and the plane requests as smooth as possible, otherwise ,it will affect the
results of measuring.

www.Elecfreaks.com
TRITA -ITM-EX-2020:44

www.kth.se

You might also like