DesignofanObstacle avoidingRobotCarBasedonArduinoMicrocontroller FINALThesis
DesignofanObstacle avoidingRobotCarBasedonArduinoMicrocontroller FINALThesis
net/publication/329042229
CITATIONS READS
0 8,312
1 author:
Mugahed Ghaleb
North China Electric Power University
1 PUBLICATION 0 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Mugahed Ghaleb on 16 February 2019.
毕 业 设 计(论文)
`
Design of an Obstacle-avoiding Robot Car
题目: Based on Arduino Microcontroller
基于 Arduino 单片机的智能避障小车
设计
院 系 电气与电子工程院
专业班级 电气 1403
学生姓名 穆歌 MUGAHED GHALEB
学 号 1144100034
指导教师 皮伟
2018 年 06 月
ABSTRACT
In today’s world ROBOTICS is a fast growing and interesting field. ROBOT has sufficient
intelligence to cover the maximum area of provided space.
Introduces the design and implementation of an autonomous obstacle -avoiding robot car using
ultrasonic wave sensor in this thesis. By sending pulses, the obstacle avoidance distance can
be measured. At the same time, we can control steering gear to realize the obstacle avoidance
function. The robot car uses front axle steering, rear wheel drive arrangement. Two drive tires
are driven by two DC motors with gear reduction mechanisms. Using Arduino MCU chip as
the control core of the Robot car. Through the design of the hardware and software system, we
build the robot car platform and obtain good experimental effect.
器,人工智能
Table of Contents
I
5.4 Advantages .................................................................................................................. 48
5.5 Limitations ................................................................................................................... 48
5.6 Problems Faced ............................................................................................................ 48
II
Table of Figures
Figure 2.1 Autonomous Urbie developed by NASA, is designed for various urban
operations, including military reconnaissance and rescue operations. .............................. 6
Figure 3.1 Types of Arduino Boards ...................................................................................... 10
Figure 4.1 Block diagram depicting the Hardware Implementation for the project ............... 13
Figure 4.2 Arduino UNO R3 board ........................................................................................ 14
Figure 4.3 Diagram of the basic ultrasonic sensor operation .................................................. 17
Figure 4.4 Ultrasonic Sensor Pins ........................................................................................... 19
Figure 4.5 Block Diagram of Ultrasonic Sensor work............................................................ 20
Figure 4.6 L298D Motor Driver Shield .................................................................................. 21
Figure 4.7 SG-90 Servo Motor ............................................................................................... 22
Figure 4.8 diagram of Servo Closed Loop System ................................................................. 23
Figure 4.9 Position of motor shaft when PWM is generated. ................................................. 24
Figure 4.10 DC Motors ........................................................................................................... 26
Figure 4.11 DC Motor – Gear Motor ...................................................................................... 27
Figure 4.12 Block diagram of Robot working principle ......................................................... 28
Figure 4.13 The final Design of the Robot Chassis ................................................................ 29
Figure 4.14 Chassis Robot Components ................................................................................. 30
Figure 4.15 3D Print chassis plate .......................................................................................... 30
Figure 4.16 Soldering the DC Motors..................................................................................... 31
Figure 4.17 attach the front wheel .......................................................................................... 31
Figure 4.18 attach the rear wheels to the chassis .................................................................... 32
Figure 4.19 schematic circuit diagram of the switch and the power source ........................... 32
Figure 4.20 Soldering the ON/OFF Switch ............................................................................ 33
Figure 4.21 The hardware model depicting my project model ( Obstcle Avoiding Robot) .. 34
Figure 4.22 Schematics Block Diagram of wire up the components ...................................... 34
Figure 4.23 connect ultrasonic sensor Pins to the Motor Shield ............................................. 35
Figure 4.24 Block Diagram of connect ultrasonic sensor Pins to the Motor Shield ............... 35
Figure 4.25 Wire up the Servo Motor to Motor Shield (Servo _ port 2) ................................ 36
Figure 4.26 Wire up the DC motors to Motor Shield ............................................................. 36
Figure 4.27 Arduino integrated development environment (IDE) .......................................... 37
Figure 4.28 The Algorithm/ Flowchart Diagram of The Obstacle-avoiding Robot Car Based
on Arduino Microcontroller ............................................................................................. 38
Figure 4.29 Turning function by servo motor to detect obstacles .......................................... 42
Figure 4.30 Ultrasonic Sensor................................................................................................. 43
Figure 4.31 Robot Driving System ......................................................................................... 44
Figure 5.1 Ultrasonic Sensor Problems Faced ........................................................................ 48
III
华北电力大学本科毕业设计(论文)
1.1 Introduction
Robotics is part of Todays communication. In today’s world ROBOTICS is fast growing
and interesting field. It is simplest way for latest technology modification. Now a day’s
communication is part of advancement of technology, so I decided to work on ROBOTICS
field, and design something which will make human life simpler in today aspect.
An autonomous robot is a robot that is capable of moving on its own in an unknown and
unstructured environment. An autonomous robot is equipped with software intelligence to
sense its environment, detect obstacles in its path and move around an unknown environment
overcoming the obstacles. There are many robotic designs that are employed in designing of
autonomous robots. These designs are usually developed considering the physical
environment in which the robot has to be deployed. There are autonomous robots like snake
robots, walking robots, autonomous drones and autonomous robotic cars or rovers.
This ROBOT has sufficient intelligence to cover the maximum area of provided space. It
has an infrared sensor which are used to sense the obstacles coming in between the path of
ROBOT.
It will move in a particular direction and avoid the obstacle which is coming in its path.
The main motto of designing such type of Robot or the technology is that this technology
can be used in today’s very fast transportation to avoid the accident generally happen in
congested by applying emergency break. If we use this technology in the car or any vehicle,
it will automatically sense the obstacles then it will take a side to the available free space.
An obstacle may be a living things or any object.
Autonomous Intelligent Robots are robots that can perform desired tasks in unstructured
environments without continuous human guidance. Thus, by using this technology in vehicles
we make the drive safe.
1
华北电力大学本科毕业设计(论文)
1.3 Methodology
• simulations of Obstacle-avoiding Robot will be performed before and after
optimization in Proteus Simulink, and others tools if needed.
• The methodology may include research, surveys and other research techniques, and
could include both present and historical information.
• Prepare the required components to do a practical simulation by Arduino
microcontrollers to make the Robot
• Start to design the final project
2
华北电力大学本科毕业设计(论文)
Robots may act according to their own decision-making ability, provided by artificial
intelligence or may be controlled directly by a human, such as remotely-controlled bomb-
disposal robots and robotic arms; or. However, the majority of robots fall in between these
extremes, being controlled by pre-programmed computers [2].
3
华北电力大学本科毕业设计(论文)
Robots are made up of the same components as above. A typical autonomous robot has a
sensor system, a movable physical structure, a power supply and a computer brain that
controls all of these elements. Basically, robots are man-made versions of the animal life.
They are machines that can replicate human and animal behavior.
Robots use actuators to spin wheels and jointed pivot. Some robots use solenoids and electric
motors as actuators; others some use a pneumatic system (a system driven by compressed
gases); yet others use a hydraulic system. A robot may even use all of these actuator types
together.
Robots need a power source to be able to drive the actuators. Most robots have a battery or
they plug into an electricity source. Pneumatic robots need air compressors or compressed air
tanks and hydraulic robots need a pump that pressurizes the hydraulic fluid. The actuators are
wired to an electrical circuit. The circuit powers these electrical motors and solenoids
directly. It also activates the hydraulic system by manipulating electrical valves. The valves
determine the pressurized fluid's path through the machine.
4
华北电力大学本科毕业设计(论文)
A more elaborate version of the same idea is used by more advanced robots. Roboticists
create new sensor systems and algorithms to make robots more perceptive and smarter.
Today, robots are able to effectively navigate a variety of environments. Obstacle avoidance
can be implemented as a reactive control law whereas path planning involves the pre-
computation of an obstacle-free path which a controller will then guide a robot along.
Some mobile robots also use various ultrasound sensors to see obstacles or infrared. These
sensors work in a similar fashion to animal echolocation. The robot sends out a beam of
infrared light or a sound signal. It then detects the reflection of the signal. The robot locates
this distance to the obstacles depending on how long it takes the signal to bounce back.
Some advanced robots also use stereo vision. Two cameras provide robots with depth
perception. Image recognition software then gives them the ability to locate, classify various
objects. Robots also use smell and sound sensors to gain knowledge about its surroundings.
More advanced robots are able to analyze unfamiliar environments and adapt to them. They
even work on areas with rough terrain. This kind of robots can associate particular terrain
patterns with particular actions.
For example, a rover robot constructs a land map with the help of its visual sensors. If the
map depicts a bumpy terrain pattern, the robot decides to travel some other way. Such kinds
of system are very useful for exploratory robots and can be used to operate on other planets.
Figure 2.1 shows the bot developed by NASA called Urbie. It is designed for various military
purposes and is able to move through stairs and other such paths .
5
华北电力大学本科毕业设计(论文)
Figure 2.1 Autonomous Urbie developed by NASA, is designed for various urban operations,
including military reconnaissance and rescue operations.
An ant tries to get over an obstacle, it does not decide when it needs to get over an obstacle. It
simply keeps trying different things until it gets over the obstacle. An alternative robot design
takes a similar less structured approach, which can also be termed as a randomness approach.
When the robot gets stuck, it moves its appendages in every way until something works out.
Force sensors work very closely with the actuators, instead of the computer directing
everything based on a program.
6
华北电力大学本科毕业设计(论文)
7
华北电力大学本科毕业设计(论文)
8
华北电力大学本科毕业设计(论文)
programming through simple languages including PBASIC. An additional reason was that it
was able to store programs on a flash memory chip that enabled the instructions on the board
to be reprogrammed or erased at will with an infinite number of possibilities. It also
supported output devices such as LEDs and motors as well as input sensors. There are other
popular boards for the hobbyists including BASIC Stamp and wiring which are some of the
microcontroller boards that were designed for tangible media explorations and electronic art.
The two boards share the advantages of ease of rapid prototyping and simplicity of
programming.
It was in 2005 when the Arduino team was formed in Italy and it consisted of Barragan
Massimo, David Cuartielles, Gianluca Marino, Dave Mellis and Nicholas Zambetti. The main
goal of this team was to develop an electronic prototyping platform that would simplify the
wiring platform and make it accessible to the non-technical users especially in the creative
fields. The Arduino, therefore, incorporated several characteristics including a programming
environment that is based on the processing language that was conceived by Casey Reas and
Ben Fry and other artists and designers. Arduino also incorporated the ability to program its
board using a standard USB connection with a low price point (Wheat, 2001).
9
华北电力大学本科毕业设计(论文)
Arduino also makes simpler the working process of microcontroller, but it gives some
advantages over other systems for teachers, students and beginners.
Ø Inexpensive
Ø Cross-platform
Ø Simple, clear programming environment
Ø Open source and extensible software
Ø Open source and extensible hardware
10
华北电力大学本科毕业设计(论文)
Arduino System
Processor Memory Digital I/O Analogue I/O
Board Voltage
Arduino Uno
16Mhz 2KB SRAM, 6 inputs, 0
5V 14
ATmega328 32KB flash output
Arduino Due
84MHz
96KB SRAM, 12 inputs, 2
3.3V AT91SAM3X 54
512KB flash outputs
8E
Arduino
Mega 16MHz 8KB SRAM, 16 inputs, 0
5V 54
ATmega2560 256KB flash output
Arduino
Leonardo 2.5KB
16MHz 12 inputs, 0
5V SRAM, 32KB 20
ATmega32u4 output
flash
Arduino
LilyPad
ATmega 168v 1KB SRAM, 6 inputs, 0
2.7-5.5 V 14
or 328v 16KB Flash output
Arduino
Nano
Atmel
2KB SRAM, 8 inputs, 0
5V ATmega328 14
32KB Flash output
11
华北电力大学本科毕业设计(论文)
Arduino FIO
3.3KB
ATmega328P 8 inputs, 0
3.3V SRAM, 32KB 14
output
Flash
Arduino
Mini
2KB SRAM, 8 inputs, 0
5v ATmega328 14
32KB Flash outputs
Arduino Pro
Mini
2KB SRAM, 6 inputs, 0
3.3V or 5V ATmega328 14
16KB Flash output
12
华北电力大学本科毕业设计(论文)
Each component has been explained below along with their circuital representation as used in
the building of the robot. The software implementation is included in the microcontroller
phase
Figure 4.1 Block diagram depicting the Hardware Implementation for the project
13
华北电力大学本科毕业设计(论文)
Pin Function
Gnd 3 pins
IOREF Tied to 5V, tells Arduino shields voltage level from which Arduino board operates
Reset From Reset pin on MCU, tied to VCC through 10K resistor, pull to GND to reset
14
华北电力大学本科毕业设计(论文)
SPI PWM ~ TX / RX
Ø 14 Digital I/O
Ø 5V logic level
Ø Sink/source 20mA per pin
Ø Universal Asynchronous Serial Receiver /
Transmitter (UART)
• Pin 0 – Receive (RX)
• Pin 1 – Transmit (TX)
• MCU INT pins brought out to pins 2, 3
Ø 8-bit PWM
• Pins 3, 5, 6, 9, 10, 11
Ø Serial Peripheral Interface (SPI)
• Pins 10, 11, 12, 13
Analog Pins
15
华北电力大学本科毕业设计(论文)
16
华北电力大学本科毕业设计(论文)
An Ultrasonic sensor is a device that can measure the distance to an object by using sound
waves. It measures distance by sending out a sound wave at a specific frequency and
listening for that sound wave to bounce back. By recording the elapsed time between the
sound wave being generated and the sound wave bouncing back, it is possible to calculate the
distance between the sonar sensor and the object.
The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats do. It
offers excellent non-contact range detection with high accuracy and stable readings in an
easy-to-use package. From 2cm to 400 cm or 1” to 13 feet. Its operation is not affected by
sunlight or black material like sharp rangefinders are (although acoustically soft materials
like cloth can be difficult to detect). It comes complete with ultrasonic transmitter and
receiver module.
Since it is known that sound travels through air at about 344 m/s (1129 ft/s), you can take the
time for the sound wave to return and multiply it by 344 meters (or 1129 feet) to find the total
17
华北电力大学本科毕业设计(论文)
round-trip distance of the sound wave. Round-trip means that the sound wave traveled 2
times the distance to the object before it was detected by the sensor; it includes the 'trip' from
the sonar sensor to the object AND the 'trip' from the object to the Ultrasonic sensor (after the
sound wave bounced off the object). To find the distance to the object, simply divide the
round-trip distance in half.
18
华北电力大学本科毕业设计(论文)
1 VCC The VCC pin powers the sensor, typically with +5V
19
华北电力大学本科毕业设计(论文)
For example, if the object is 10 cm away from the sensor, and the speed of the sound is 340
m/s or 0.034 cm/µs the sound wave will need to travel about 294 u seconds. But what we will
get from the Echo pin will be double that number because the sound wave needs to travel
forward and bounce backward. So, in order to get the distance in cm we need to multiply the
received travel time value from the echo pin by 0.034 and divide it by 2 as shown above.
20
华北电力大学本科毕业设计(论文)
21
华北电力大学本科毕业设计(论文)
Ø 4 H-Bridges: L293D chipset provides 0.6A per bridge (1.2A peak) with thermal
shutdown protection, 4.5V to12V
Ø Pull down resistors keep motors disabled during power-up
Ø Big terminal block connectors to easily hook up wires (10-22AWG) and
power
Ø Arduino reset button brought up top
Ø 2-pin terminal block to connect external power, for separate logic/motor
supplies
Ø T ested compatible with Mega, UNO& Duemilanove
Ø Dimensions: 69mm x 53mm x 14.3mm (2.7in x 2.1in x 0.6in)
22
华北电力大学本科毕业设计(论文)
reason behind using a servo is that it provides angular precision, i.e. it will only rotate as
much we want and then stop and wait for next signal to take further action. This is unlike a
normal electrical motor which starts rotating as and when power is applied to it and the
rotation continues until we switch off the power. We cannot control the rotational progress of
electrical motor; but we can only control the speed of rotation and can turn it ON and OFF.
It is a closed loop system where it uses positive feedback system to control motion and final
position of the shaft. Here the device is controlled by a feedback signal generated by
comparing output signal and reference input signal.
23
华北电力大学本科毕业设计(论文)
signal is given to another input terminal of the error detector amplifier. Now difference
between these two signals, one comes from potentiometer and another comes from other
source, will be processed in feedback mechanism and output will be provided in term of error
signal. This error signal acts as the input for motor and motor starts rotating. Now motor shaft
is connected with potentiometer and as motor rotates so the potentiometer and it will generate
a signal. So as the potentiometer’s angular position changes, its output feedback signal
changes. After sometime the position of potentiometer reaches at a position that the output of
potentiometer is same as external signal provided. At this condition, there will be no output
signal from the amplifier to the motor input as there is no difference between external applied
signal and the signal generated at potentiometer, and in this situation motor stops rotating.
24
华北电力大学本科毕业设计(论文)
connected to the output shaft of the Servo, to calculate the angle and stop the DC motor on
required angle.
To recap, there are two important differences between the control pulse of the servo motor
versus the DC motor. First, on the servo motor, duty cycle (on-time vs. off-time) has no
meaning whatsoever—all that matters are the absolute duration of the positive-going pulse,
which corresponds to a commanded output position of the servo shaft. Second, the servo has
its own power electronics, so very little power flows over the control signal. All power is
draw from its power lead, which must be simply hooked up to a high-current source of 5
volts.
25
华北电力大学本科毕业设计(论文)
4.1.5 DC motor
26
华北电力大学本科毕业设计(论文)
In order to select the most suitable gear motor for our application we must first compute:
Ø Load
Ø Speed
Ø Torque requirements for our application
27
华北电力大学本科毕业设计(论文)
28
华北电力大学本科毕业设计(论文)
29
华北电力大学本科毕业设计(论文)
30
华北电力大学本科毕业设计(论文)
31
华北电力大学本科毕业设计(论文)
we add a switch to the battery holder so that we will be able to turn the robot on or off. The
switch is connected according to the schematics shown below and attached to the case using a
hot glue. The Battery case is attached to the chassis using a double-sided tape to ensure
everything sticks together.
Figure 4.19 schematic circuit diagram of the switch and the power source
32
华北电力大学本科毕业设计(论文)
This step is to mount other parts of the robot before we start connecting their wires. The
motor shield is stacked on the Arduino and it is mounted on the chassis using a double-sided
tape. The current requirements of the motors are often higher than what the Arduino can
provide, that is why it’s important to use the motor shield as it is equipped with additional
circuitry to provide up to 600mA current to each of the motors. This shield provides power to
the motors and the servo motor and ultrasonic sensor and makes it much easier. The
Ultrasonic sensor is also mounted on the top of the servo motor which is then mounted on the
chassis using some screws.
33
华北电力大学本科毕业设计(论文)
Figure 4.21 The hardware model depicting my project model ( Obstcle Avoiding Robot)
To simplify the connections, below is a pin map of how the components connect, one to the
other.
Wire up the components together as shown in the image below.
34
华北电力大学本科毕业设计(论文)
Figure 4.24 Block Diagram of connect ultrasonic sensor Pins to the Motor Shield
35
华北电力大学本科毕业设计(论文)
Figure 4.25 Wire up the Servo Motor to Motor Shield (Servo _ port 2)
36
华北电力大学本科毕业设计(论文)
37
华北电力大学本科毕业设计(论文)
Figure 4.28 The Algorithm/ Flowchart Diagram of The Obstacle-avoiding Robot Car Based
on Arduino Microcontroller
38
华北电力大学本科毕业设计(论文)
The code uses three libraries. Two of them must be downloaded in order for the program to
compile. The first one is the motor shield driver from Adafruit. The second library is the
NewPing library for the supersonic distance sensor.
The first thing we do in the code is to include the libraries that have been downloaded into
the code.
#include <AFMotor.h>
#include <NewPing.h>
#include <Servo.h>
Next, we declare the pins to which or ultrasonic sensor is connected to, and some variables
which will be used to store info as the code runs then we set the speed of the motors. We can
set the motors speed in any value up to 255.
#define TRIG_PIN A4 // Arduino pin tied to trigger pin on the ultrasonic
sensor.
#define ECHO_PIN A5 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_SPEED_OFFSET 20
Next, we Initialize the servo motor by creating an object of the servo library. We Also
initialize the Motors to which the wheels are connected using the AF library.
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(3, MOTOR12_1KHZ);
Servo myservo;
We then move into the void setup () function where we initialize the servo motor and we set
it to “look” straight. In my case, this was at 115 degrees angle.
Next, we read the distance a few times in order to get a valid distance measurement as shown
below
39
华北电力大学本科毕业设计(论文)
void setup() {
myservo.write(115);
delay(2000); // Wait for 2s.
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
}
Now we go to the loop function which executes every 40 Ms. If the distance we measured is
less than or equal to 15 cm, we stop the motors, reverse for 300ms, stop, look right and left
and measure the distance in each direction. If the distance in one direction is greater than the
other we turn the robot to the direction with the farthest/greatest distance and instruct it to
move forward as shown below.
void loop() {
int distanceR = 0;
int distanceL = 0;
delay(40);
if(distance<=15)
{
moveStop();
delay(100);
moveBackward();
delay(300);
moveStop();
delay(200);
distanceR = lookRight();
delay(200);
distanceL = lookLeft();
40
华北电力大学本科毕业设计(论文)
delay(200);
if(distanceR>=distanceL)
{
turnRight();
moveStop();
}else
{
turnLeft();
moveStop();
}
}else
{
moveForward();
}
distance = readPing();
}
this autonomous robot (auto mode) has 5 statuses: move forward, stop, move backward, scan
right and left, and turn right or left. Since only 1 distance sensor used in this project, the
sensor must have the capability to turn around to scan for alternative way to move so it must
attach together with servo. The servo shaft can be turn in 180 degrees to help the sensor scan
the obstacle around and choose the clear path to move along. A homemade bracket used to
attach the sensor to the servo.
41
华北电力大学本科毕业设计(论文)
{
myservo.write(50);
delay(500);
int distance = readPing();
delay(100);
myservo.write(115);
return distance;
}
{
myservo.write(170);
delay(500);
int distance = readPing();
delay(100);
myservo.write(115);
return distance;
delay(100);
}
42
华北电力大学本科毕业设计(论文)
The obstacle sensor is used avoiding the robot from the clash to any external devices or that
is like walls, any obstacle which comes in its way. Here I used the Ultrasonic Sensor as
shown below.
{
delay(70); // Wait 70ms between pings (about 20 pings/sec).
we will be using the following rotation of wheel for steering and straight motion:
43
华北电力大学本科毕业设计(论文)
{
motor1.run(RELEASE);
motor2.run(RELEASE);
}
if(!goesForward)
{
goesForward=true;
motor1.run(FORWARD);
motor2.run(FORWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly
bring the speed up to avoid loading down the batteries too quickly
44
华北电力大学本科毕业设计(论文)
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet+MAX_SPEED_OFFSET);
delay(5);
}
}
}
{
goesForward=false;
motor1.run(BACKWARD);
motor2.run(BACKWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly
bring the speed up to avoid loading down the batteries too quickly
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet+MAX_SPEED_OFFSET);
delay(5);
}
}
{
motor1.run(FORWARD);
motor2.run(BACKWARD);
delay(300);
motor1.run(FORWARD);
motor2.run(FORWARD);
}
{
motor1.run(BACKWARD);
motor2.run(FORWARD);
45
华北电力大学本科毕业设计(论文)
delay(300);
motor1.run(FORWARD);
motor2.run(FORWARD);
}
46
华北电力大学本科毕业设计(论文)
5.1 Conclusion
Today we are in the world of robotics. Knowingly or unknowingly, we have been using
different types of robots in our daily life.
The project is “obstacle detection and the avoidance robot” is practically proved by using the
Ultrasonic sensor for sensing the robot, Motor Shield Driver for the driving the dc motors, dc
motor is used for the movement of the robot with the help of the Arduino Microcontroller.
A lot of factors determined the accuracy of the robot we designed. These factors were the
environmental phenomenon in which the robot was tested, the number of obstacles present
making the test space crowded or relatively less crowded the type and shape of the obstacle
(the robot is designed for a uniform shaped obstacle).
These factors majorly affected the sensors. The accuracy of the robot is dependent on the
sensors used. Thus, the nature of the sensor and its accuracy defined the accuracy of my
robot.
47
华北电力大学本科毕业设计(论文)
The most effective method to increase the accuracy of my robot is the inclusion of better
sensors, although the project cost might increase but the accuracy will definitely increase as
well as the problem space where the robot can be used. Better actuators will result in a faster
and more efficient robot.
5.4 Advantages
Ø Collision control.
Ø It provides Safe Navigation.
Ø This is the basic of all robot and has a wide scope of extensions
5.5 Limitations
The performance of this robot mainly depends on the sensors and number of sensors.
The ultrasonic sensor used here is of commercial application so it may easily undergo
interference.
48
华北电力大学本科毕业设计(论文)
REFERENCES
[1] N. Senthil Kumar,M.Saravanan,S Jeebananthan ,“Microprocessors & Microcontrollers”,
49
华北电力大学本科毕业设计(论文)
APPENDIX:
Robot Coding
#include <AFMotor.h>
#include <NewPing.h>
#include <Servo.h>
#define TRIG_PIN A4
#define ECHO_PIN A5
#define MAX_DISTANCE 200
#define MAX_SPEED 200 // sets speed of DC motors
#define MAX_SPEED_OFFSET 20
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(4, MOTOR12_1KHZ);
Servo myservo;
boolean goesForward=false;
int distance = 100;
int speedSet = 0;
void setup() {
myservo.attach(9);
myservo.write(115);
delay(2000);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
}
50
华北电力大学本科毕业设计(论文)
void loop() {
int distanceR = 0;
int distanceL = 0;
delay(40);
if(distance<=15)
{
moveStop();
delay(100);
moveBackward();
delay(300);
moveStop();
delay(200);
distanceR = lookRight();
delay(200);
distanceL = lookLeft();
delay(200);
if(distanceR>=distanceL)
{
turnRight();
moveStop();
}else
{
turnLeft();
moveStop();
}
}else
{
moveForward();
}
distance = readPing();
}
51
华北电力大学本科毕业设计(论文)
int lookRight()
{
myservo.write(50);
delay(500);
int distance = readPing();
delay(100);
myservo.write(115);
return distance;
}
int lookLeft()
{
myservo.write(170);
delay(500);
int distance = readPing();
delay(100);
myservo.write(115);
return distance;
delay(100);
}
int readPing() {
delay(70);
int cm = sonar.ping_cm();
if(cm==0)
{
cm = 250;
}
return cm;
}
void moveStop() {
motor1.run(RELEASE);
motor2.run(RELEASE);
52
华北电力大学本科毕业设计(论文)
void moveForward() {
if(!goesForward)
{
goesForward=true;
motor1.run(FORWARD);
motor2.run(FORWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly bring the speed up to
avoid loading down the batteries too quickly
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet+MAX_SPEED_OFFSET);
delay(5);
}
}
}
void moveBackward() {
goesForward=false;
motor1.run(BACKWARD);
motor2.run(BACKWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly bring the speed up to
avoid loading down the batteries too quickly
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet+MAX_SPEED_OFFSET);
delay(5);
}
}
void turnRight() {
motor1.run(FORWARD);
motor2.run(BACKWARD);
53
华北电力大学本科毕业设计(论文)
delay(300);
motor1.run(FORWARD);
motor2.run(FORWARD);
}
void turnLeft() {
motor1.run(BACKWARD);
motor2.run(FORWARD);
delay(300);
motor1.run(FORWARD);
motor2.run(FORWARD);
}
54
华北电力大学本科毕业设计(论文)
Acknowledgements
First of all, I would like to thank ALLAH for giving me the strength and wisdom and courage
to complete this thesis.
This thesis is dedicated to my family for their love and support, for believe in me.
I would like to express my most sincere gratitude to my Supervisor Dr. PI WEI for giving me
the opportunity to be involved with such a subject that is interesting and modern and for his
guidance throughout the entire process.
I would also like to thank all of my classmates and for their help, support and friendship
through all the past four years.
and special thanks to my inspiration, my motivation (N) for standing by me.
Last but not the least, I would like to thank Chinese Government and NCEPU for infinite
support.
“I’ll never be able to give you back what you gave me”.
55