This is a full report of my project in Level 3 Term 1. The project was basically a self-driven vehicle capable of localizing itself in a grid and planning a path between two nodes. It can avoid particular nodes and plan path between two allowed nodes. Flood Fill Algorithm will be used for finding the path between two allowed nodes. The vehicle is also capable of transferring blocks from one node to another. In fact, this vehicle is a prototype of a self-driven vehicle capable of transporting passengers and it can also be used in industries to transfer different items from one place to another.
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Grid Based Autonomous Navigator
1. BANGLADESH UNIVERSITY OF ENGINEERING & TECHNOLOGY
Course No. : ME 362
Instrumentation and Measurement Sessional
Department of Mechanical Engineering
Grid-Based Navigation for Autonomous, Mobile Robots and Finding the
Conditional Shortest Path in an Unknown Environment
Accomplished by:
Sayeed Mohammed (1110067)
Md. Rakibul Islam (1110075)
Syeda Noor -E- Lamia (1110083)
3. ACKNOWLEDGEMENTS
First we like to thank Almighty for the successful submission of our project within time. We
would like to express our gratitude to our teacher Mr. Kazi Arafat Rahman, K.M Rafidh
Hasan and Anup Saha. From Department of Mechanical Engineering, BUET, for their
valuable suggestion about mechanical design and selection of electrical components. Finally
we want to thank our course teacher, Dr. M. A. Rashid Sarkar (Professor) from Department
of Mechanical Engineering, BUET. We are really grateful to those persons who have
supported us to complete our project.
4. ABSTRACT
A self-driven vehicle capable of localizing itself in a grid and planning a path between two
nodes. It can avoid particular nodes and plan path between two allowed nodes. Flood Fill
Algorithm will be used for finding the path between two allowed nodes. The vehicle is also
capable of transferring blocks from one node to another. In fact, this vehicle is a prototype of
a self-driven vehicle capable of transporting passengers and it can also be used in industries
to transfer different items from one place to another.
KEYWORDS
Flood Fill, Microcontroller, Path Planning, Robust, PID, navigation, gird solving.
5. Index
Topic Page No.
1. Introduction……………………………………………………………………… 1
2. Grid description…………………………………………………………………. 2
3. Solving algorithm
3.1 Flood fill…………………………………………………………………... 3
3.2 Line following algorithm
3.2.1 Basic line following
algorithm…………………………………………………………...
4
3.2.2 PID line following
algorithm…………………………………………………………...
6
4. Components
4.1 Electrical components…………………………………………………….. 9
4.2 Mechanical components…………………………………………………... 12
5. Circuit design
5.1 Motherboard………………………………………………………………. 13
5.2 DC motor drive……………………………………………………………. 14
5.3 Line sensor interfacing……………………………………………………. 14
5.4 Overall electrical system………………………………………………….. 15
6. System prototype………………………………………………………………... 16
7. Future work……………………………………………………………………… 16
8. Conclusion………………………………………………………………………. 16
9. References……………………………………………………………………….. 17
10 Appendix………………………………………………………………………… 19
6. List of Figures
Figure name Page
no.
1. Grid……………………………………………………………………………… 2
2. LFR Principle using IR sensor at the side…………………………………….... 4
3. LFR Principle using IR sensor at the middle …………………………………... 5
4. Robot track before PID tuning………………………………………………….. 6
5. Robot Track after PID tuning …………………………………………………... 7
6. Arduino Mega 2650……………………………………………………………. 9
7. L298N Motor Drive…………………………………………………………….. 9
8. DC Gear motor………………………………………………………………….. 10
9. Buck module……………………………………………………………………. 10
10. Booster module…………………………………………………………………. 10
11. Battery………………………………………………………………………....... 11
12. IR sensor………………………………………………………………………… 11
13. Arduino Line following shield. ………………………………………………… 11
14. Al-Co alloy steel………………………………………………………………… 12
15. Caster ball……………………………………………………………………….. 12
16. Wheels…………………………………………………………………………... 12
17. Motherboard…………………………………………………………………….. 13
18. Schematics Of Motherboard…………………………………………………….. 13
19. Circuit connection of Motors …………………………………………………... 14
20. IR Array…………………………………………………………………………. 15
21. Principle of Sensor Array……………………………………………………….. 15
22. Overall Electrical Systems……………………………………………………… 15
23. Design of Robot………………………………………………………………… 16
7. 1
1. INTRODUCTION
A key ability needed by an autonomous, mobile robot is the possibility to navigate through
the space. The problem can basically be decomposed into positioning and path planning.
Especially if the robot is severely resource-constrained, simple schemes are favorable to
elaborated algorithms. Rather simple sensors and actuators as well as a limited computing
platform also demand simple, robust techniques due to inaccuracy and the lack of resources.
Autonomous navigation of mobile robot has been appeared in literature many times. Our
robot is an autonomous mobile robot capable of exploring 2D world, finding shortest path
between source and destination. It can also transfer objects of different sizes and shapes from
one place to another.
The report is structured in following way: At first the nature of the grid and programming
technique required to solve it is discussed and in the next section the mechanical construction
is detailed.
8. 2
2. GRID DESCRIPTION
The grid used as a reference is a 5×5 square grid having 300mm×300mm inner dimension of
40mm thick white lines on a black surface. The lines are spaced equally. There are nodes at
the intersection of white lines at some places and the nodes are black squares of
40mm×40mm dimension (Fig.1).
Fig 1: Grid
9. 3
3. SOLVING ALGORITHM
The grid is represented in a 2D system. Starting node is assumed as the origin. During the
first scan of the grid, the robot comes across every crossing in the grid and finds out whether
there is a white node in it. All the four directions are marked in which the bot can move so as
to know to where the bot is going to move next. Referring the 2D system in geological
directions NEWS, we will take NORTH or +y axis as 1 and the following directions as 2, 3
and 4. In this way the robot can be guided precisely to the destination node. In the code a
direction counter is kept for this purpose. The value of the counter is changed whenever
needed..
3.1. Flood Fill
The flood fill algorithm takes three parameters: a start node, a target color, and a replacement
color. The algorithm looks for all nodes in the array which are connected to the start node by
a path of the target color, and changes them to the replacement color. There are many ways in
which the flood-fill algorithm can be structured, but they all make use of a queue or stack
data structure, explicitly or implicitly.
One implicitly stack-based (recursive) flood-fill implementation (for a two-dimensional array) goes as
follows:
Flood-fill (node, target-color, replacement-color):
1. If target-color is equal to replacement-color, return.
2. If the color of node is not equal to target-color, return.
3. Set the color of node to replacement-color.
4. Perform Flood-fill (one step to the west of node, target-color,
replacement-color).
Perform Flood-fill (one step to the east of node, target-color,
replacement-color).
Perform Flood-fill (one step to the north of node, target-color,
replacement-color).
Perform Flood-fill (one step to the south of node, target-color,
replacement-color).
5. Return.
10. 4
3.2. Line Following Algorithm
3.2.1. Basic Line Following Algorithm
The algorithm is the one thing that determines the performance of your robot more than
anything else. The most basic algorithm is the one which uses only one sensor. The sensor is
placed in a position that is a little off centered to one of the sides, say right. When the sensor
is detects no line the robot moves to the left and when the sensor detects the line the robot
moves to the right. A robot with this algorithm would follow the line like shown in the
picture below
Fig 3: LFR Principle using IR sensor at the side
The drawback of this method is that the line following is not smooth. The robot keeps
wavering left and right on the track, wasting battery power and time. A modification to this
method is to add sensors on both sides of the robot and place them such that they just sense
11. 5
the line on either side. And the algorithm would be to move forward if both the sensors sense
the line or to move left if only the left sensor senses the line and move right if only the right
sensor senses the line. A robot with this algorithm would follow the line like shown in the
picture below
Fig 4: LFR Principle using IR sensor at the middle
This algorithm is faster than the previous algorithm but the robot will still wobble about the
line and may not be fast enough. A much better algorithm is to use the PID to follow the line.
This will make line following process much smoother, faster and efficient.
12. 6
3.2.2. PID Line Following Algorithm
PID stands for Proportional Integral and Derivative. It is a popular control loop feedback
control extensively used in industrial controls systems. But why would one need a PID
controller for a line following robot, when there are many simpler algorithms already
available for line following.
A conventional robot would follow a line as shown below (red line shows the path taken by
the robot)
Figure 5: Robot track before PID tuning
In the picture the robot oscillates a lot about the line, wasting valuable time and battery
power. Hence there is a maximum speed beyond which you cannot use this algorithm,
otherwise the robot will overshoot the line.
13. 7
A robot with PID control will follow the line as shown below
Figure 6: Robot Track after PID tuning
Target – It is the position you want the line follower to always be (or try to be), that is, the
center of the robot.
Current Position – It is the current position of the robot with respect to the line.
Error - It is the difference between the current position and the target. It can be negative,
positive or zero.
Proportional – It tells us how far the robot is from the line like – to the right, to the extreme
right, to the left or a little to the left. Proportional is the fundamental term used to calculate
the other two.
Integral – It gives the accumulated error over time. It tells us if the robot has been on the line
in the last few moments or not.
Derivative – It is the rate at which the robot oscillates to the left and right about the line.
Kp, Ki and Kd are the constants used to vary the effect of Proportional, Integral and
Derivative terms respectively.
What the controller does is first calculate the current position. Then calculate the error based
on the current position. It will then command the motors to take a hard turn, if the error is
high or a small turn if the error is low. Basically, the magnitude of the turn taken will be
proportional to the error. This is a result of the Proportional control. Even after this, if the
14. 8
error does not decrease or decreases slowly, the controller will then increase the magnitude of
the turn further and further over time till the robot centers over the line. This is a result of the
Integral control. In the process of centering over the line the robot may overshoot the target
position and move to the other side of the line where the above process is followed again.
Thus the robot may keep oscillating about the line in order to center over the line. To reduce
the oscillating effect over time the Derivative control is used. The Pseudo code is given
bellow
//calculate error
Error = target_pos – current_pos
//error times proportional constant gives P
P = Error * Kp
// Integral stores the accumulated error
I = I + Error
//calculates the integral value
I = I * Ki
//stores change in error to derivate
D = Error – Previos_error
Correction = P + I + D
15. 9
4. COMPONENTS
4.1 Electrical Components
1. Arduino mega 2560
Operating voltage: 5 volts
Digital I/O pins: 54
Analog input pins: 16
Clock speed: 16 MHz
EEPROM: 4 KB
SRAM: 8 KB
Flash memory: 256 KB
DC current per I/O pin: 40
mA
Input voltage: 7-12 volt
(Recommended)
2. L298N Motor Drive
Double H bridge drive
chip: L298n
Logical voltage: 5~35 volts
Logical current: 0~36 mA
Maximum power 25 W
Dimensions: 43x43x26
mm
Weight: 26 g
16. 10
3. DC Gear Motor
Rated power: DC 12 volts
Speed: 400 rpm
Shaft diameter: 4 mm
Overall size: 25x67 mm
Weight: 8.7 g
4. Buck Module
Product name: LM2596 step down module
DC-DC buck converter
Power supply: 1.23-30 volts
Input current: 3 A (maximum)
Dimensions: 48x23x14 mm
5. Booster Module
Product name: LM2577 DC-DC
adjustable step up power converter
Output voltage: 4-35 volts
Output current: 2.5 mA (maximum)
Dimensions: 48x23x14 mm
17. 11
6. Battery
Product name: Gens ACE 2200 25C 3S
Li-Po battery
Capacity: 2200 mAh
Discharge rate: 25 C
Dimensions: 106x26x14 mm
Weight: 195 g
Voltage: 11.1 volts
7. IR sensor
Product name: TCRT 5000 Reflective
Optical Sensor
Package type: Leaded
Detector type: Photo transistor
Peak operating system: 2.5 mm
Emitter wavelength: 950 nm
Dimensions: 10.2x5.8x7 mm
8. Arduino Line Following Shield
Power Diode
25 v 100µF capacitor
3 Push switch
1 Buzzer
LED
Serial Rail
18. 12
4.2 Mechanical Components
1. Al-Co Alloy Sheet
2. Caster Ball
Product name: Pololu Ball Caster
Diameter: 1 inch
Height: 1.1-1.4 inch
Ball type: Plastic
3. Wheels
Name : 65 mm wheel
Diameter : 65 mm
Width : 27 mm
Inner six angle
to side : 12mm
Weight : 35g
19. 13
5. CIRCUIT DESIGN
5.1 Motherboard
The motherboard is basically a shield only designed for Arduino MEGA 2560 which can
be easily placed over the arduino. It consists a power diode, one capacitor, three push
switch, one led and serial connections. Its controls all the function of our robot from
controlling the speed of motor to taking raw data from sensor. This shield is the
powerhouse of our robot as it gives power to the whole circuit using a single battery. This
shield made our circuit very concise and saving a lot of space and wires. The shield is
show below in Fig:
Figure 17: Motherboard
Figure 18: Schematics of motherboard
20. 14
5.2 DC Motor Drive
Figure 19: Circuit connection of Motors
For high voltage and high current drive of the DC-motors from ATMEGA16 microcontroller,
L-298 IC has been used which is a dual-bridge controller for motor drive and can be
controlled by sending PWM from the microcontroller into its Enable pin. It supports
bidirectional motor-drive with about 46 volt and 3.5 Ampere. The necessary circuit to drive
DC motor is shown in Fig.8.
5.3 Line Sensor Interfacing
Short range IR transmitter-receiver pair known commercially as TCRT5000 is used as line
sensor. Interfacing pair shown in Fig.12 with the external logic circuitry has been mentioned.
The same circuitry (Fig.11) is used here. In case of white lines, the output is high and for the
black surface (out of the line), the output is low. Using 10 TCRT5000 we made a sensor array
which 20 cm long and distance between each pair of sensor is 2.3 cm apart.
14
21. 15
Figure 20: IR Sensor Array
Figure 21: Principle of Sensor Array
5.4 Overall Electrical System
Figure 22: Overall Electrical Systems
Sensor
Array
Arduino L298N
DC
Motor
22. 16
6. System Prototype
Figure 22: Design of Robot
7. Future Work
In future we will use more robust processing and control using BFS (Breadth First Search),
DFS (Depth First Search) and Dijkustra’s Algorithm for efficient and fast grid solving
8. Conclusion
Our bot is an autonomous mobile robot capable of localizing itself in a 2D world and
planning its path towards destination by means of Flood-Fill Algorithm implemented in
Arduino powered with Atmega2560 microcontroller. It can follow the tracks using feedback
from the line-sensors and also capable of detecting crossings. A large scale prototype
customized for factories will be very promising.
23. 17
9. REFERENCES
[1] J. Borenstein, B. Everett, and L. Feng. Navigating Mobile Robots: Systems and
Techniques. A. K.
Peters, Ltd., Wellesley, MA, 1996.
[2] I.J. Cox and G.T. Wilfong, editors. Autonomous Robot Vehicles. Springer,Verlag, 1990.
[3] Joachim Buhmann, Wolfram Burgard, Armin B. Cremers, Dieter Fox, Thomas Hofmann,
Frank
Schneider, Jiannis Strikos, and Sebastian Thrun. The mobile robot RHINO. AI Magazine,
16(2):31{38, Summer 1995.
[4] Wolfram Burgard, Dieter Fox, and Sebastian Thrun. Active mobile robot localization. In
Proc. of the
Fifteenth International ConferenceonArtificial Intelligence (IJCAI-97), 1997.
[5] Joachim Hertzberg and Frank Kirchner. Landmark-based autonomous navigation in
sewerage pipes.
In Proceedings of the First Euromicro Workshop on Advanced Mobile Robots
(EUROMICRO '96), pages 68{73. IEEE Computer Society Press, 1996.
[6] Hans P. Moravec. Sensor fusion in certainty grids for mobile robots. AI Magazine, pages
61{74,Summer 1988.
[7] Illa Nourbakhsh, Rob Powers, and Stan Birch_eld. DERVISH an office-navigating robot.
AI
Magazine, 16(2):53{60, Summer 1995.
[8] Dijkstra, E. W. (1959). "A note on two problems in connexion with graphs". Numerische
Mathematik
1: 269–271. doi:10.1007/BF01386390. http://wwwm3.
ma.tum.de/twiki/pub/MN0506/WebHome/dijkstra.pdf.
[9] Knuth, Donald E. (1997), The Art Of Computer Programming Vol 1. 3rd ed., Boston:
Addison-
Wesley, ISBN 0-201-89683-4, http://www-cs-faculty.stanford.edu/~knuth/taocp.html
[10] Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L.; Stein, Clifford (2001).
"Section 24.3:
Dijkstra's algorithm". Introduction to Algorithms (Second Ed.). MIT Press and McGraw-Hill.
pp.
595–601. ISBN 0-262-03293-7.
[11] Fredman, Michael Lawrence; Tarjan, Robert E. (1984). "Fibonacci heaps and their uses
in improved network optimization algorithms". 25th Annual Symposium on Foundations of
Computer Science
(IEEE): 338–346.
[12] Fredman, Michael Lawrence; Tarjan, Robert E. (1987). "Fibonacci heaps and their uses
in improved network optimization algorithms". Journal of the Association for Computing
Machinery 34 (3): 596–
615.
[13] Atmel. (2010, Oct. 20). “ATMEGA 16 datasheet.” [On-line]. Pp. 1-356. Available:
www.atmel.com/Images/doc2466.pdf [Sept. 1, 2012].
[14] STMicroelectronics. (2000, January). “L298 Dual full-bridge driver”. [On-line], pp.1-12.
Available:
noel.feld.cvut.cz/hw/st/1918.pdf. [September 2, 2012].
[15] Fairchild Semiconductor. (2009, May). “1N4001-4007 General Purpose Rectifiers”.
[On-line]. pp. 1-
3. Available: www.fairchildsemi.com/ds/1N/1N4001.pdf [September 2, 2012].
24. 18
[16] TowerPro “TowerPro SG-5010 Servo Specifications and Reviews” [On-line] Available:
www.servodatabase.com/servo/towerpro/sg-5010 [October 3, 2012].
[17] TowerPro “TowerPro SG91R Servo Specifications and Reviews” [On-line] Available:
www.servodatabase.com/servo/towerpro/sg91r [October 3, 2012].
[18] National Semiconductor (2000, May 2). “7805 datasheet”. [On-line]. pp. 1-3. Available:
pira.cz/pdf/78xx.pdf. [September 1, 2011].
[19] Aziz, A.; Hossain, M.S.; "Inherent Inter-vehicle Signaling Using Radio Frequency and
Infra-red
Communication," Computer Modelling and Simulation (UKSim), 2012 vol., no., pp.211-215,
28-30
March 2012, doi: 10.1109/UKSim.2012.
25. 19
10. APPENDIX
10.1 Switch
/////////////////////// Switch Selection ////////////////////////////////////
int getSwitch()
{
if (digitalRead(S1)==HIGH) return 1;
else if (digitalRead(S2)==HIGH) return 2;
else if (digitalRead(S3)==HIGH) return 3;
else return 0;
}
/////////////////////// ThresHold ////////////////////////////////////
void threshHold()
{
while (1) {
if (getSwitch() == 1) {
beepBuzzer();
wheel(150, -150);
for (i = 0; i < 1500; i++)
{
// taking the raw analog values of sensors
for(int j=0;j<10;j++) raw[j] = analogRead(Sensors[j]);
// setting up sensors white values
for(int j=0;j<10;j++) if(raw[j] < white[j]) white[j] =
raw[j];
// setting up sensors black values
for(int j=0;j<10;j++) if(raw[j] > black[j]) black[j] =
raw[j];
}
beepBuzzer();
wheel(-200, 200);
delay(20);
wheel(0, 0);
delay(20);
for (int i = 0; i < 10; i++) {
int w = map(white[i], 0, 1023, 0, 255);
int b = map(black[i], 0, 1023, 0, 255);
//writing values in EEPROM
EEPROM.write(i, w);
EEPROM.write(i + 20, b);
}
break;
}
if (getSwitch() == 2) {
beepBuzzer();
delay(50);
26. 20
beepBuzzer();
for (int i = 0; i < 10; i++) {
white[i] = map(EEPROM.read(i), 0, 255, 0, 1023);
black[i] = map(EEPROM.read(i + 20), 0, 255, 0, 1023);
thresHold[i] = (white[i]+black[i])/2;
}
Serial.println("Grid Info Updated: ");
int k = 100;
for(i=0;i<ROW;i++){
for(j=0;j<COL;j++){
Serial.print(EEPROM.read(k++));
Serial.print(" ");
}
Serial.println();
}
Serial.println("nnPATH: ");
k = 80;
for(i=0;i<index;i++)
{
Serial.print(EEPROM.read(k++));
Serial.print(" >>> ");
}
break;
}
}
}
10.2 Wheel Function
void wheel(int motA,int motB)
{
if(motA==0)
{
digitalWrite(MotorLeftp, HIGH);
digitalWrite(MotorLeftn, HIGH);
}
else if (motA>0)
{
digitalWrite(MotorLeftp, HIGH);
digitalWrite(MotorLeftn, LOW);
}
else if (motA<0)
{
digitalWrite(MotorLeftp, LOW);
digitalWrite(MotorLeftn, HIGH);
}
if(motB==0)
{