├── MazeSolverRobot ├── DetailedDescription.pdf ├── ArduinoCode_PreOrderTraversal.ino └── ArduinoCode_final.ino └── README.md /MazeSolverRobot/DetailedDescription.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sahilkhoslaa/MazeSolverRobot/HEAD/MazeSolverRobot/DetailedDescription.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Maze Solving Line Following Robot

2 |

An Arduino micro controller based robot which first analyzes the maze in the dry run by following lines through IR sensors and then calculates the shortest path from the source to the destination.In this paper we have discussed a unique general algorithm for exploring and solving any kind of line maze with another simple one for simple mazes without loops or with loops having highest two branches none of which are inward. For the general algorithm, we need a method to map the whole maze, which is required if the maze is complex. The proposed maze mapping system is based on coordinate system and after mapping the 3 | . In order to find the coordinates of the turning points and junctions, linear distances between the points are needed, for which wheel encoder was used. However, due to non-linear movement of robot, the directly measured distance from the encoder has some error and to remove this error an idea is built up which ended by deriving equations that give us almost exact linear distance between two points from the reading of wheel encoder of the robot moving in a non-linear path

4 |

5 | 6 |

7 |

Table of Contents

8 |
1. Problem Statement
9 |
2. Installation/Integeration
10 |

Problem Statement

11 | Teams have to build an autonomous robot which can follow a white line and keep track of directions while going through the maze. The bot has to analyze the path in the dry run and has togo through the mesh from the starting point to the ending point in minimum possible time. 12 |
ARENA
13 |

The game field consists of an arena having dimensions 2310 mm X 1980 mm (lxb).It consists of the following: 14 | 1.The arena is composed of random paths made up of white strips. 15 | 2.Angle between two adjacent white lines in the path is either 90 deg or 135 deg. 16 | 3.The width of all white stripes will be 30mm. 17 | 4.The actual arena at the competitionwill consist of slight alterations in the path. 18 |

Installation/Integeration

19 |
Requirements
20 |

Arduino Board, Ready-made Chasis, Male to Male , Male to female wires, Breadboard, 8 IR sensor array board, Lithium-ion polymer battery, Arduino software, Wheels, L293D Motor Driver, 7805

21 |
Integeration
22 |

23 | Follow up this pin diagram: 24 | 25 | 26 |

27 |
Installation
28 |

Just Copy and paste the above given code in MazeSolverRobot Directory -> ArduinoCode_Final.ino in the new project of Arduino Software. Save and Upload the Code in the Arduino Board and Design a map with Black lines on White Background. 29 |

Note : This Code is valid for black lines on white background. Just apply "!" NOT operater in all the if conditions to reverse the color combination

30 |
You are All set to go :)
31 |
Visit : MazeSolverRobot for more info regarding this project. 32 |
Author : Sahil Khosla
33 | -------------------------------------------------------------------------------- /MazeSolverRobot/ArduinoCode_PreOrderTraversal.ino: -------------------------------------------------------------------------------- 1 | float PWM; 2 | float PWM2; 3 | int P; // (Preportional) 4 | float I; // (Integral) 5 | float D; // (Derivative) 6 | int pI; // The sum of the preportional value and the integral value 7 | int PID; 8 | int val; 9 | int Aval; // All values (see the integral equation) 10 | int Pval1; // The previous value (see the derivative term) 11 | int Pval2; 12 | int Dval; // The subtraction of the current value from the previous value 13 | void setup() { 14 | Serial.begin(9600); 15 | Aval=0; 16 | Pval1=0; 17 | Pval2=0; 18 | val=0; 19 | pinMode(5,OUTPUT); 20 | pinMode(9,OUTPUT); 21 | pinMode(10,OUTPUT); 22 | pinMode(11,OUTPUT); 23 | 24 | pinMode(2,INPUT); 25 | pinMode(3,INPUT); 26 | pinMode(4,INPUT); 27 | pinMode(6,INPUT); 28 | pinMode(7,INPUT); 29 | 30 | pinMode(13,OUTPUT);//for led 31 | } 32 | int flag=0;//for checking only 1 end possible 33 | //FUNCTIONS: 34 | void HardRight(){ 35 | digitalWrite(5,LOW); 36 | analogWrite(9,110); 37 | analogWrite(10,110);//RIGHT 38 | digitalWrite(11,LOW); 39 | } 40 | void HardLeft(){ 41 | digitalWrite(9,LOW); 42 | analogWrite(5,110); 43 | analogWrite(11,110);//RIGHT 44 | digitalWrite(10,LOW); 45 | } 46 | void SoftRight(){ 47 | digitalWrite(5,LOW); 48 | digitalWrite(9,LOW); 49 | analogWrite(10,110); 50 | digitalWrite(11,LOW); 51 | 52 | } 53 | void SoftLeft(){ 54 | analogWrite(5,110);//NH LEFT 55 | digitalWrite(9,LOW); 56 | digitalWrite(10,LOW); 57 | digitalWrite(11,LOW); 58 | } 59 | void Move(float x, float y){ 60 | analogWrite(5,x); 61 | digitalWrite(9,LOW); 62 | analogWrite(10,y); 63 | digitalWrite(11,LOW); 64 | } 65 | void Reverse(){ 66 | analogWrite(9,110); 67 | digitalWrite(5,LOW); 68 | analogWrite(11,110); 69 | digitalWrite(10,LOW); 70 | } 71 | void Stop(){ 72 | digitalWrite(5,LOW); 73 | digitalWrite(9,LOW); 74 | digitalWrite(10,LOW); 75 | digitalWrite(11,LOW); 76 | } 77 | 78 | /*void thisIsTheEnd(){ 79 | //Stylish Reverse 80 | digitalWrite(13,HIGH); //LED ON 81 | digitalWrite(5,LOW); //HAULT FOR 10 SECONDS 82 | digitalWrite(9,LOW); 83 | digitalWrite(10,LOW); 84 | digitalWrite(11,LOW); 85 | delay(5000); 86 | flag++; 87 | digitalWrite(13,LOW); //LED OFF 88 | analogWrite(9,110); //Reverse for 0.5s 89 | digitalWrite(5,LOW); 90 | analogWrite(11,100); 91 | digitalWrite(10,LOW); 92 | delay(500); 93 | digitalWrite(5,LOW); //Hard Right for 0.2s 94 | analogWrite(9,110); 95 | analogWrite(10,100); //RIGHT 96 | digitalWrite(11,LOW); 97 | delay(200); 98 | } 99 | void thisIsTheEnd2(){ 100 | analogWrite(5,110); //Move forward to check T or end 101 | digitalWrite(9,LOW); 102 | analogWrite(10,100); 103 | digitalWrite(11,LOW); 104 | delay(200); 105 | if(!!digitalRead(7)&&!!digitalRead(6)&&!!digitalRead(A0)&&!!digitalRead(4)&&!!digitalRead(3))//if end 106 | { 107 | analogWrite(5,110); //Move on the box 108 | digitalWrite(9,LOW); 109 | analogWrite(10,100); 110 | digitalWrite(11,LOW); 111 | delay(400); 112 | 113 | digitalWrite(13,HIGH); //LED ON 114 | 115 | digitalWrite(5,LOW); //HAULT FOR 10 SECONDS 116 | digitalWrite(9,LOW); 117 | digitalWrite(10,LOW); 118 | digitalWrite(11,LOW); 119 | delay(5000); 120 | 121 | digitalWrite(13,LOW); //LED OFF 122 | /* //commenting bcs no full scanning 123 | analogWrite(5,110); //Move little forward 124 | digitalWrite(9,LOW); 125 | analogWrite(10,100); 126 | digitalWrite(11,LOW); 127 | delay(200); 128 | 129 | digitalWrite(5,LOW); //HAULT FOR 3 SECONDS 130 | digitalWrite(9,LOW); 131 | digitalWrite(10,LOW); 132 | digitalWrite(11,LOW); 133 | delay(3000); 134 | 135 | HardRight(); //U Turn 136 | delay(770); 137 | 138 | analogWrite(5,110); //Move forward 139 | digitalWrite(9,LOW); 140 | analogWrite(10,100); 141 | digitalWrite(11,LOW); 142 | delay(750); 143 | //Program Back to normal 144 | } 145 | else//NOT AN END 146 | { 147 | HardRight(); 148 | delay(450); 149 | } 150 | }*/ 151 | 152 | 153 | void loop() 154 | { 155 | Pval2 = Pval1; 156 | val = analogRead(A0);//!digitalRead(A0) 157 | //Serial.println(!digitalRead(A0)); 158 | //Serial.println(analogRead(A0)); 159 | 160 | 161 | val = constrain (val, 700, 900); 162 | map (val, 700, 900, -300, 300); 163 | Pval1=val; 164 | P=val*3; // Expirement with this value 165 | 166 | Aval=Aval+val; // Because we need the values from the start of the program to the instantanious time 167 | 168 | I=Aval*0.3; // See the Integral Discription + Expirement with this value 169 | 170 | Dval=Pval2-val; 171 | D=Dval*0.3; // See the Integral Discription + Expirement with this value 172 | pI=I+P; 173 | PID=pI+D; // Finally, the PID value 174 | 175 | PWM = 110+PID; // Expirement with the "150" value 176 | PWM2 = 110-PID; 177 | if(!digitalRead(7)&&!digitalRead(6)&&!digitalRead(A0)&&!digitalRead(4)&&!digitalRead(3)){//0 178 | HardLeft();//no giggling effect in left turns 179 | //HardRight();//no giggling effects in right turn 180 | } 181 | 182 | if(!digitalRead(7)&&!digitalRead(6)&&!digitalRead(A0)&&!digitalRead(4)&&!!digitalRead(3)){//1 183 | /* while(!digitalRead(A0))// Error handling when there is giggling between s4 and s5//Right preference case//HardLeft case//now no giggling effect in right turns 184 | {//HardRight 185 | digitalWrite(5,LOW); 186 | analogWrite(9,110); 187 | analogWrite(10,100);//RIGHT 188 | digitalWrite(11,LOW); 189 | }*/ 190 | SoftRight();//required if no exception 191 | } 192 | 193 | if(!digitalRead(7)&&!digitalRead(6)&&!digitalRead(A0)&&!!digitalRead(4)&&!digitalRead(3)){//2 194 | /*while(!digitalRead(A0))// Error handling when there is giggling between s3 and s4//Right preference case//HardLeft case//now no giggling effect in right turns 195 | {//HardRight 196 | digitalWrite(5,LOW); 197 | analogWrite(9,110); 198 | analogWrite(10,100);//RIGHT 199 | digitalWrite(11,LOW); 200 | }*/ 201 | SoftRight();//required if no exception 202 | } 203 | 204 | if(!digitalRead(7)&&!digitalRead(6)&&!digitalRead(A0)&&!!digitalRead(4)&&!!digitalRead(3)){//3 205 | HardRight(); 206 | } 207 | 208 | if(!digitalRead(7)&&!digitalRead(6)&&!!digitalRead(A0)&&!digitalRead(4)&&!digitalRead(3)){//4 209 | Move(PWM,PWM2); 210 | } 211 | 212 | if(!digitalRead(7)&&!digitalRead(6)&&!!digitalRead(A0)&&!digitalRead(4)&&!!digitalRead(3)){//5 213 | Reverse(); 214 | } 215 | 216 | if(!digitalRead(7)&&!digitalRead(6)&&!!digitalRead(A0)&&!!digitalRead(4)&&!digitalRead(3)){//6 217 | // Reverse(); 218 | Move(PWM,PWM2); 219 | } 220 | 221 | if(!digitalRead(7)&&!digitalRead(6)&&!!digitalRead(A0)&&!!digitalRead(4)&&!!digitalRead(3)){//7 222 | SoftRight(); 223 | } 224 | 225 | if(!digitalRead(7)&&!!digitalRead(6)&&!digitalRead(A0)&&!digitalRead(4)&&!digitalRead(3)){//8 226 | SoftLeft(); 227 | } 228 | 229 | if(!digitalRead(7)&&!!digitalRead(6)&&!digitalRead(A0)&&!digitalRead(4)&&!!digitalRead(3)){//9 230 | SoftLeft(); 231 | } 232 | 233 | if(!digitalRead(7)&&!!digitalRead(6)&&!digitalRead(A0)&&!!digitalRead(4)&&!digitalRead(3)){//10 234 | SoftLeft(); 235 | } 236 | 237 | if(!digitalRead(7)&&!!digitalRead(6)&&!digitalRead(A0)&&!!digitalRead(4)&&!!digitalRead(3)){//11 238 | SoftLeft(); 239 | } 240 | 241 | if(!digitalRead(7)&&!!digitalRead(6)&&!!digitalRead(A0)&&!digitalRead(4)&&!digitalRead(3)){//12 242 | //Reverse(); 243 | Move(PWM,PWM2); 244 | } 245 | 246 | if(!digitalRead(7)&&!!digitalRead(6)&&!!digitalRead(A0)&&!digitalRead(4)&&!!digitalRead(3)){//13 247 | //Reverse(); 248 | SoftRight(); 249 | } 250 | 251 | if(!digitalRead(7)&&!!digitalRead(6)&&!!digitalRead(A0)&&!!digitalRead(4)&&!digitalRead(3)){//14 252 | //Reverse(); 253 | Move(PWM,PWM2); 254 | } 255 | 256 | if(!digitalRead(7)&&!!digitalRead(6)&&!!digitalRead(A0)&&!!digitalRead(4)&&!!digitalRead(3)){//15 257 | //Reverse(); 258 | SoftRight(); 259 | } 260 | 261 | if(!!digitalRead(7)&&!digitalRead(6)&&!digitalRead(A0)&&!digitalRead(4)&&!digitalRead(3)){//16 262 | SoftLeft(); 263 | } 264 | 265 | if(!!digitalRead(7)&&!digitalRead(6)&&!digitalRead(A0)&&!digitalRead(4)&&!!digitalRead(3)){//17 266 | SoftLeft(); 267 | } 268 | 269 | if(!!digitalRead(7)&&!digitalRead(6)&&!digitalRead(A0)&&!!digitalRead(4)&&!digitalRead(3)){//18 270 | SoftLeft(); 271 | } 272 | 273 | if(!!digitalRead(7)&&!digitalRead(6)&&!digitalRead(A0)&&!!digitalRead(4)&&!!digitalRead(3)){//19 274 | SoftRight(); 275 | } 276 | 277 | if(!!digitalRead(7)&&!digitalRead(6)&&!!digitalRead(A0)&&!digitalRead(4)&&!digitalRead(3)){//20 278 | //Reverse(); 279 | Move(PWM,PWM2); 280 | } 281 | 282 | if(!!digitalRead(7)&&!digitalRead(6)&&!!digitalRead(A0)&&!digitalRead(4)&&!!digitalRead(3)){//21 283 | //Reverse(); 284 | SoftRight(); 285 | } 286 | 287 | if(!!digitalRead(7)&&!digitalRead(6)&&!!digitalRead(A0)&&!!digitalRead(4)&&!digitalRead(3)){//22 288 | //Reverse(); 289 | Move(PWM,PWM2); 290 | } 291 | 292 | if(!!digitalRead(7)&&!digitalRead(6)&&!!digitalRead(A0)&&!!digitalRead(4)&&!!digitalRead(3)){//23 293 | //Reverse(); 294 | SoftRight(); 295 | } 296 | 297 | if(!!digitalRead(7)&&!!digitalRead(6)&&!digitalRead(A0)&&!digitalRead(4)&&!digitalRead(3)){//24 298 | SoftLeft(); 299 | } 300 | 301 | if(!!digitalRead(7)&&!!digitalRead(6)&&!digitalRead(A0)&&!digitalRead(4)&&!!digitalRead(3)){//25 302 | SoftLeft(); 303 | } 304 | 305 | if(!!digitalRead(7)&&!!digitalRead(6)&&!digitalRead(A0)&&!!digitalRead(4)&&!digitalRead(3)){//26 306 | SoftLeft(); 307 | } 308 | 309 | if(!!digitalRead(7)&&!!digitalRead(6)&&!digitalRead(A0)&&!!digitalRead(4)&&!!digitalRead(3)){//27 310 | while(!digitalRead(A0)) 311 | SoftRight(); 312 | } 313 | 314 | if(!!digitalRead(7)&&!!digitalRead(6)&&!!digitalRead(A0)&&!digitalRead(4)&&!digitalRead(3)){//28 315 | //Move(); 316 | while(!!digitalRead(A0)) 317 | SoftLeft(); 318 | while(!digitalRead(A0)) 319 | SoftLeft(); 320 | } 321 | 322 | if(!!digitalRead(7)&&!!digitalRead(6)&&!!digitalRead(A0)&&!digitalRead(4)&&!!digitalRead(3)){//29 323 | //Reverse(); 324 | SoftRight(); 325 | } 326 | 327 | if(!!digitalRead(7)&&!!digitalRead(6)&&!!digitalRead(A0)&&!!digitalRead(4)&&!digitalRead(3)){//30 328 | // Reverse(); 329 | Move(PWM,PWM2); 330 | } 331 | 332 | if(!!digitalRead(7)&&!!digitalRead(6)&&!!digitalRead(A0)&&!!digitalRead(4)&&!!digitalRead(3)){//31 333 | digitalWrite(13,HIGH); 334 | Stop();delay(2000); 335 | digitalWrite(13,LOW); 336 | while(!!digitalRead(A0)) 337 | Move(PWM,PWM2); 338 | } 339 | } 340 | -------------------------------------------------------------------------------- /MazeSolverRobot/ArduinoCode_final.ino: -------------------------------------------------------------------------------- 1 | //Pin Connections 2 | int s1=2; 3 | int s2=3; 4 | int s3=4; 5 | int s4=5; 6 | int s5=7; 7 | int s6=8; 8 | int s7=12; 9 | int s8=13; 10 | 11 | int r=-1; 12 | 13 | int flag=0; 14 | int y=0; 15 | int flag1=0; 16 | 17 | int a=0,b=0,c=0,d=0,e=0,f=0; 18 | 19 | unsigned char path[1000]={}; 20 | 21 | int i=0,top=0; 22 | int flag3=0; 23 | int j=145; 24 | 25 | float k=1.1*j; 26 | 27 | float g=1/1.2;//adjustment Factor 28 | 29 | void setup() 30 | { 31 | pinMode(6,OUTPUT); 32 | pinMode(7,OUTPUT); 33 | pinMode(10,OUTPUT); 34 | pinMode(11,OUTPUT); 35 | 36 | pinMode(12,INPUT); 37 | pinMode(2,INPUT); 38 | pinMode(3,INPUT); 39 | pinMode(4,INPUT); 40 | pinMode(5,INPUT); 41 | pinMode(13,INPUT); 42 | pinMode(7,INPUT); 43 | pinMode(8,INPUT); 44 | 45 | Serial.begin(9600); 46 | 47 | for(i=0;i<1000;i++) 48 | path[i]='X'; 49 | } 50 | 51 | void pprint() 52 | { 53 | int x; 54 | x=top-1; 55 | 56 | Serial.print(x); 57 | Serial.print(" "); 58 | 59 | if(path[x]==82) Serial.print("R"); 60 | if(path[x]==66) Serial.print("B"); 61 | if(path[x]==76) Serial.print("L"); 62 | if(path[x]==83) Serial.print("S"); 63 | if(path[x]==77) Serial.print("M"); 64 | if(path[x]==78) Serial.print("N"); 65 | if(path[x]==84) Serial.print("T"); 66 | if(path[x]==89) Serial.print("Y"); 67 | if(path[x]==65) Serial.print("A"); 68 | if(path[x]==85) Serial.print("U"); 69 | 70 | Serial.print('\n'); 71 | 72 | if(Serial.available()){} 73 | 74 | char val= Serial.read(); 75 | } 76 | 77 | void ppprint(int x) 78 | { 79 | Serial.print(x); 80 | Serial.print(" "); 81 | if(path[x]==82) Serial.print("R"); 82 | if(path[x]==66) Serial.print("B"); 83 | if(path[x]==76) Serial.print("L"); 84 | if(path[x]==83) Serial.print("S"); 85 | if(path[x]==77) Serial.print("M"); 86 | if(path[x]==78) Serial.print("N"); 87 | if(path[x]==84) Serial.print("T"); 88 | if(path[x]==89) Serial.print("Y"); 89 | if(path[x]==65) Serial.print("A"); 90 | if(path[x]==85) Serial.print("U"); 91 | Serial.print('\n'); 92 | } 93 | 94 | void straight() 95 | { 96 | analogWrite(6,0); 97 | analogWrite(9,j); 98 | analogWrite(10,0); 99 | analogWrite(11,j); 100 | } 101 | 102 | void Reverse() 103 | { 104 | analogWrite(6,100); 105 | analogWrite(9,0); 106 | analogWrite(10,100); 107 | analogWrite(11,0); 108 | } 109 | 110 | void left() 111 | { 112 | analogWrite(6,0); 113 | analogWrite(9,j); 114 | analogWrite(10,j); 115 | analogWrite(11,0); 116 | } 117 | 118 | void right() 119 | { 120 | analogWrite(6,j); 121 | analogWrite(9,0); 122 | analogWrite(10,0); 123 | analogWrite(11,j); 124 | } 125 | 126 | void Stop() 127 | { 128 | analogWrite(6,0); 129 | analogWrite(9,0); 130 | analogWrite(10,0); 131 | analogWrite(11,0); 132 | } 133 | 134 | int calcshortpath() 135 | { 136 | int y=top-1; 137 | 138 | Serial.print("OUTSIDE FOR LOOP");Serial.print('\n'); 139 | int z=1,ch=0,x,getind,i,j,n,fa,k,key,ba,q=0;char temp1,temp2; 140 | 141 | for(i=0;(i0&&a%2==0) 355 | { 356 | path[top++]='R'; 357 | pprint(); 358 | // if A is even and bot has to take take decision then bot goes right 359 | do 360 | { 361 | if(flag1==0) 362 | { 363 | right(); 364 | delay(g*500); 365 | flag1=1;} 366 | right(); 367 | } 368 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&!digitalRead(s5)&&digitalRead(s6)&&digitalRead(s7)&&digitalRead(s8))); 369 | a++; 370 | } 371 | else if(flag>0&&a%2!=0) 372 | { 373 | path[top++]='S'; 374 | pprint(); 375 | // if A is odd and bot has to take take decision then bot goes straight 376 | straight(); 377 | delay(g*100); 378 | a++; 379 | } 380 | else 381 | { 382 | do 383 | { 384 | if(flag1==0) 385 | { 386 | right(); 387 | delay(g*500); 388 | flag1=1;} 389 | right(); 390 | } 391 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7)&&!digitalRead(s5))); 392 | path[top++]='R'; 393 | pprint(); 394 | } 395 | flag=0; 396 | } 397 | if((digitalRead(s8)&&digitalRead(s7)&&digitalRead(s6)&&!digitalRead(s5)&&!digitalRead(s4)&&!digitalRead(s3)&&!digitalRead(s2)&&!digitalRead(s1))||(digitalRead(s8)&&digitalRead(s7)&&!digitalRead(s6)&&!digitalRead(s5)&&!digitalRead(s4)&&!digitalRead(s3)&&!digitalRead(s2)&&!digitalRead(s1))) 398 | { 399 | //For LEFT 400 | straight(); 401 | delay(g*100); 402 | 403 | if(!digitalRead(s4)&&!digitalRead(s5)&&!digitalRead(s1)&&!digitalRead(s2)&&!digitalRead(s3)&&!digitalRead(s6)&&!digitalRead(s7)&&!digitalRead(s8)) 404 | goto asliwalaT; 405 | straight(); 406 | delay(g*200); 407 | 408 | //checking the type of left turn 409 | 410 | if(!digitalRead(s7)||!digitalRead(s8)) 411 | goto asliwala135right; 412 | straight(); 413 | delay(g*100); 414 | 415 | if(!digitalRead(s4)||!digitalRead(s5)) 416 | { 417 | flag++; 418 | path[top++]='B'; 419 | pprint();} 420 | 421 | if(flag>0&&b%2!=0) 422 | { 423 | path[top++]='L'; 424 | pprint(); 425 | // if B is odd and bot has to take take decision then bot goes straight 426 | do 427 | { 428 | if(flag1==0) 429 | { 430 | left(); 431 | delay(g*500); 432 | flag1=1; 433 | } 434 | left(); 435 | } 436 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7)&&!digitalRead(s5))); 437 | b++; 438 | } 439 | else if(flag>0&&b%2==0) 440 | { 441 | path[top++]='S'; 442 | pprint(); 443 | // if B is even and bot has to take take decision then bot goes straight 444 | straight(); 445 | delay(g*100); 446 | b++; 447 | } 448 | else 449 | { 450 | do 451 | { 452 | if(flag1==0) 453 | { 454 | left(); 455 | delay(g*500); 456 | flag1=1;} 457 | left(); 458 | } 459 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7)&&!digitalRead(s5))); 460 | path[top++]='L'; 461 | pprint(); 462 | } 463 | flag=0; 464 | } 465 | //***********************************FOR PERFECT ORIENTATION**************************************** 466 | 467 | if(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&digitalRead(s4)&&!digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7)&&!digitalRead(s5)) 468 | { 469 | analogWrite(6,0); 470 | analogWrite(9,0); 471 | analogWrite(10,0); 472 | analogWrite(11,k); 473 | } 474 | 475 | if(digitalRead(s1)&&digitalRead(s2)&&!digitalRead(s3)&&!digitalRead(s4)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7)&&digitalRead(s5)) 476 | { 477 | analogWrite(6,0); 478 | analogWrite(9,k); 479 | analogWrite(10,0); 480 | analogWrite(11,0); 481 | } 482 | 483 | //**************************************************************************************************** 484 | 485 | if(!digitalRead(s1)&&!digitalRead(s2)&&!digitalRead(s3)&&!digitalRead(s4)&&!digitalRead(s5)&&!digitalRead(s6)&&!digitalRead(s7)&&!digitalRead(s8)) 486 | { 487 | 488 | 489 | asliwalaT: 490 | //For T 491 | //Stop(); 492 | //delay(5000); 493 | path[top++]='T'; 494 | pprint(); 495 | straight(); 496 | delay(g*200); 497 | if(!digitalRead(s1)&&!digitalRead(s2)&&!digitalRead(s3)&&!digitalRead(s4)&&!digitalRead(s5)&&!digitalRead(s6)&&!digitalRead(s7)&&!digitalRead(s8)) 498 | { 499 | //REACHED END 500 | Stop(); 501 | delay(9999); 502 | flag3=1; 503 | goto code0; 504 | } 505 | //if((digitalRead(s4)&&(!digitalRead(s1)||!digitalRead(s2)))||(digitalRead(s4)&&(!digitalRead(s7)||!digitalRead(s8)))||(digitalRead(s5)&&(!digitalRead(s1)||!digitalRead(s2)))||(digitalRead(s5)&&(!digitalRead(s7)||!digitalRead(s8)))) 506 | // goto asliwalaY; 507 | straight(); 508 | delay(g*100); 509 | if(c%2==0) 510 | { path[top++]='R'; 511 | pprint(); 512 | // Bot reached T following RSLB rule when C is even 513 | do 514 | { 515 | if(flag1==0) 516 | { 517 | right(); 518 | delay(g*500); 519 | flag1=1; 520 | } 521 | right(); 522 | } 523 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7)&&!digitalRead(s5))); 524 | 525 | } 526 | else if(c%2!=0) 527 | { path[top++]='L'; 528 | pprint(); 529 | // Bot reached T following LSRB rule when C is odd 530 | do 531 | { 532 | if(flag1==0) 533 | { 534 | left(); 535 | delay(g*500); 536 | flag1=1; 537 | } 538 | left(); 539 | } 540 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7)&&!digitalRead(s5))); 541 | 542 | } 543 | c++; 544 | 545 | } 546 | 547 | if(digitalRead(s4)&&digitalRead(s5)&&digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&digitalRead(s6)&&digitalRead(s7)&&digitalRead(s8)) 548 | { 549 | //U TURN 550 | 551 | path[top++]='U'; 552 | pprint(); //RBRBLBL 553 | straight(); 554 | delay(g*200); 555 | while(digitalRead(s4)) 556 | { 557 | right(); 558 | } 559 | } 560 | if(0) 561 | { //For 135 deg right and 90 deg left 562 | asliwala135right: 563 | path[top++]='N'; 564 | pprint(); 565 | //Stop();delay(9999); 566 | straight(); 567 | delay(g*120); 568 | if(d%2==0) 569 | { 570 | path[top++]='R'; 571 | pprint(); 572 | 573 | right(); 574 | delay(g*10); 575 | while(digitalRead(s4)) 576 | { 577 | right(); 578 | } 579 | d++; 580 | } 581 | else if(d%2!=0) 582 | { 583 | path[top++]='L'; 584 | pprint(); 585 | do 586 | { 587 | if(flag1==0) 588 | { 589 | left(); 590 | delay(g*500); 591 | flag1=1; 592 | } 593 | left(); 594 | } 595 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&!digitalRead(s5)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7))); 596 | d++; 597 | } 598 | } 599 | if(0) 600 | { 601 | //For 135 deg left and 90 deg right 602 | asliwala135left: 603 | //Stop();delay(9999); 604 | path[top++]='M'; 605 | pprint(); 606 | straight();delay(g*120); 607 | 608 | 609 | if(e%2==0) 610 | { 611 | 612 | path[top++]='R'; 613 | pprint(); 614 | do 615 | { 616 | if(flag1==0) 617 | { 618 | right(); 619 | delay(250); 620 | flag1=1; 621 | } 622 | right(); 623 | } 624 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&!digitalRead(s5)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7))); 625 | e++; 626 | } 627 | else //if(e%2!=0) 628 | { 629 | 630 | path[top++]='L'; 631 | pprint(); 632 | e++; 633 | 634 | left(); 635 | delay(g*10); 636 | 637 | while(digitalRead(s5)) 638 | { 639 | left(); 640 | } 641 | } 642 | } 643 | 644 | /*if(path[0]==82&&path[1]==66&&path[2]==82) 645 | { 646 | Stop(); 647 | delay(5000); 648 | path[0]='S'; 649 | flag3=1; 650 | }*/ 651 | 652 | } 653 | 654 | f(flag3==1) 655 | { 656 | 657 | code0: 658 | Stop(); 659 | delay(5000); 660 | 661 | for(i=0;i0&&a%2==0) 781 | { 782 | 783 | // if A is even and bot has to take take decision then bot goes right 784 | do 785 | { 786 | if(flag1==0) 787 | { 788 | right(); 789 | delay(g*500); 790 | flag1=1; 791 | } 792 | right(); 793 | } 794 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&!digitalRead(s5)&&digitalRead(s6)&&digitalRead(s7)&&digitalRead(s8))); 795 | a++; 796 | } 797 | else if(flag>0&&a%2!=0) 798 | { 799 | 800 | // if A is odd and bot has to take take decision then bot goes straight 801 | straight(); 802 | delay(g*100); 803 | a++; 804 | } 805 | else 806 | { 807 | do 808 | { 809 | if(flag1==0) 810 | {right(); 811 | delay(g*500); 812 | flag1=1;} 813 | right(); 814 | } 815 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7)&&!digitalRead(s5))); 816 | 817 | 818 | } 819 | flag=0; 820 | } 821 | if((digitalRead(s8)&&digitalRead(s7)&&digitalRead(s6)&&!digitalRead(s5)&&!digitalRead(s4)&&!digitalRead(s3)&&!digitalRead(s2)&&!digitalRead(s1))||(digitalRead(s8)&&digitalRead(s7)&&!digitalRead(s6)&&!digitalRead(s5)&&!digitalRead(s4)&&!digitalRead(s3)&&!digitalRead(s2)&&!digitalRead(s1))) 822 | { 823 | //For LEFT 824 | straight(); 825 | delay(g*100); 826 | if(!digitalRead(s4)&&!digitalRead(s5)&&!digitalRead(s1)&&!digitalRead(s2)&&!digitalRead(s3)&&!digitalRead(s6)&&!digitalRead(s7)&&!digitalRead(s8)) 827 | goto asliwalaT2; 828 | straight(); 829 | delay(g*200); 830 | 831 | //checking the type of left turn 832 | 833 | if(!digitalRead(s7)||!digitalRead(s8)) 834 | goto asliwala135right2; 835 | straight(); 836 | delay(g*100); 837 | if(!digitalRead(s4)||!digitalRead(s5)){ 838 | flag++; 839 | if(rPointer()=='L') 840 | b=1; 841 | else 842 | b=0; 843 | 844 | } 845 | if(flag>0&&b%2!=0) 846 | { 847 | 848 | // if B is odd and bot has to take take decision then bot goes straight 849 | do 850 | { 851 | if(flag1==0) 852 | {left(); 853 | delay(g*500); 854 | flag1=1;} 855 | left(); 856 | } 857 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7)&&!digitalRead(s5))); 858 | b++; 859 | } 860 | else if(flag>0&&b%2==0) 861 | { 862 | 863 | // if B is even and bot has to take take decision then bot goes straight 864 | straight(); 865 | delay(g*100); 866 | b++; 867 | } 868 | else 869 | { 870 | do 871 | { 872 | if(flag1==0) 873 | {left(); 874 | delay(g*500); 875 | flag1=1;} 876 | left(); 877 | } 878 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7)&&!digitalRead(s5))); 879 | 880 | 881 | } 882 | flag=0; 883 | } 884 | //***********************************FOR PERFECT ORIENTATION**************************************** 885 | 886 | if(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&digitalRead(s4)&&!digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7)&&!digitalRead(s5)) 887 | { 888 | analogWrite(6,0); 889 | analogWrite(9,0); 890 | analogWrite(10,0); 891 | analogWrite(11,k); 892 | } 893 | 894 | if(digitalRead(s1)&&digitalRead(s2)&&!digitalRead(s3)&&!digitalRead(s4)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7)&&digitalRead(s5)) 895 | { 896 | analogWrite(6,0); 897 | analogWrite(9,k); 898 | analogWrite(10,0); 899 | analogWrite(11,0); 900 | } 901 | //**************************************************************************************************** 902 | 903 | if(!digitalRead(s1)&&!digitalRead(s2)&&!digitalRead(s3)&&!digitalRead(s4)&&!digitalRead(s5)&&!digitalRead(s6)&&!digitalRead(s7)&&!digitalRead(s8)) 904 | { 905 | asliwalaT2: 906 | //For T 907 | //Stop(); 908 | //delay(5000); 909 | 910 | 911 | straight(); 912 | delay(g*200); 913 | if(!digitalRead(s1)&&!digitalRead(s2)&&!digitalRead(s3)&&!digitalRead(s4)&&!digitalRead(s5)&&!digitalRead(s6)&&!digitalRead(s7)&&!digitalRead(s8)) 914 | { 915 | //REACHED END 916 | Stop(); 917 | delay(9999); 918 | flag3=4; 919 | } 920 | //if((digitalRead(s4)&&(!digitalRead(s1)||!digitalRead(s2)))||(digitalRead(s4)&&(!digitalRead(s7)||!digitalRead(s8)))||(digitalRead(s5)&&(!digitalRead(s1)||!digitalRead(s2)))||(digitalRead(s5)&&(!digitalRead(s7)||!digitalRead(s8)))) 921 | // goto asliwalaY; 922 | straight(); 923 | delay(g*100); 924 | 925 | if(rPointer()=='R') 926 | c=0; 927 | else 928 | c=1; 929 | if(c%2==0) 930 | { 931 | 932 | // Bot reached T following RSLB rule when C is even 933 | do 934 | { 935 | if(flag1==0) 936 | {right(); 937 | delay(g*500); 938 | flag1=1;} 939 | right(); 940 | } 941 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7)&&!digitalRead(s5))); 942 | 943 | } 944 | else if(c%2!=0) 945 | { 946 | 947 | // Bot reached T following LSRB rule when C is odd 948 | do 949 | { 950 | if(flag1==0) 951 | {left(); 952 | delay(g*500); 953 | flag1=1;} 954 | left(); 955 | } 956 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7)&&!digitalRead(s5))); 957 | 958 | } 959 | c++; 960 | 961 | } 962 | 963 | if(digitalRead(s4)&&digitalRead(s5)&&digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&digitalRead(s6)&&digitalRead(s7)&&digitalRead(s8)) 964 | { 965 | //U TURN 966 | 967 | //RBRBLBL 968 | straight(); 969 | delay(g*200); 970 | while(digitalRead(s4)) 971 | { 972 | right(); 973 | } 974 | } 975 | if(0) 976 | { 977 | //For 135 deg right and 90 deg left 978 | asliwala135right2: 979 | 980 | 981 | //Stop();delay(9999); 982 | straight(); 983 | delay(g*120); 984 | 985 | if(rPointer()=='L') 986 | d=1; 987 | else 988 | d=0; 989 | 990 | if(d%2==0) 991 | { 992 | 993 | 994 | 995 | right(); 996 | delay(g*10); 997 | while(digitalRead(s4)) 998 | { 999 | right(); 1000 | } 1001 | d++; 1002 | } 1003 | else if(d%2!=0) 1004 | { 1005 | do 1006 | { 1007 | if(flag1==0) 1008 | { 1009 | left(); 1010 | delay(g*500); 1011 | flag1=1; 1012 | } 1013 | left(); 1014 | } 1015 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&!digitalRead(s5)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7))); 1016 | d++; 1017 | } 1018 | } 1019 | if(0) 1020 | { 1021 | //For 135 deg left and 90 deg right 1022 | asliwala135left2: 1023 | //Stop();delay(9999); 1024 | 1025 | 1026 | straight();delay(g*120); 1027 | 1028 | if(rPointer()=='L') 1029 | e=1; 1030 | else 1031 | e=0; 1032 | if(e%2==0) 1033 | { 1034 | do 1035 | { 1036 | if(flag1==0) 1037 | { 1038 | right(); 1039 | delay(250); 1040 | flag1=1; 1041 | } 1042 | right(); 1043 | } 1044 | while(!(digitalRead(s1)&&digitalRead(s2)&&digitalRead(s3)&&!digitalRead(s4)&&!digitalRead(s5)&&digitalRead(s6)&&digitalRead(s8)&&digitalRead(s7))); 1045 | e++; 1046 | } 1047 | else //if(e%2!=0) 1048 | { 1049 | 1050 | e++; 1051 | 1052 | left(); 1053 | delay(g*10); 1054 | while(digitalRead(s5)) 1055 | { 1056 | left(); 1057 | } 1058 | } 1059 | } 1060 | 1061 | } 1062 | } 1063 | 1064 | /*void shortpath() 1065 | { label: 1066 | if(path[y]==83) 1067 | { 1068 | straight(); 1069 | delay(500); 1070 | y++; 1071 | } 1072 | else if(path[y]==82) 1073 | { 1074 | straight(); 1075 | delay(400); 1076 | right(); 1077 | delay(500); 1078 | while(digitalRead(s4)) 1079 | { 1080 | right(); 1081 | } 1082 | y++; 1083 | } 1084 | else if(path[y]==76) 1085 | { 1086 | straight(); 1087 | delay(400); 1088 | left(); 1089 | delay(500); 1090 | while(digitalRead(s5)) 1091 | { 1092 | left(); 1093 | } 1094 | y++; 1095 | } 1096 | //else if(path[y]==65||path[y]==66||path[y]==77||path[y]==78||path[y]==84||path[y]==89) 1097 | //{ 1098 | //y++; 1099 | //goto label; 1100 | //} 1101 | }*/ 1102 | 1103 | char rPointer() 1104 | { 1105 | 1106 | for(i=r+1;1;++i) 1107 | { 1108 | if(path[i]==65||path[i]==66||path[i]==77||path[i]==78||path[i]==84||path[i]==89) 1109 | { 1110 | r=i+1; 1111 | break; 1112 | } 1113 | } 1114 | 1115 | ppprint(r-1); 1116 | ppprint(r); 1117 | Serial.print('\n'); 1118 | return path[r]; 1119 | } 1120 | 1121 | 1122 | 1123 | 1124 | --------------------------------------------------------------------------------