Professional Documents
Culture Documents
ODAR
Obstacle Detecting Autonomous Robot
EMILIA HALTORP
JOHANNA BREDHE
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.
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.
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
6 Further work 21
Bibliography 23
Appendices
A Arduino Code
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 could the robot detect obstacles in its lane and what should it do when it
encounters them?
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.
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
(ω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
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.
11
CHAPTER 3. DEMONSTRATOR
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
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.
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.
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
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.
18
Chapter 5
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:
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?
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]
24
Appendix A
Arduino Code
// 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) ,
};
// ∗∗ 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
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 ( ) ;
// 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
Product features:
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:
www.Elecfreaks.com
TRITA -ITM-EX-2020:44
www.kth.se