Shortest Path of Line Maze - Curved and Zig-zag Track

Traverse all path and find the shortest path from starting point to finish.

Aug 11, 2017

15301 views

16 respects

Components and supplies

1

Arduino UNO

Apps and platforms

1

Arduino IDE

Project description

Code

Line Maze Solving - Curved and Zig-zag Track

arduino

Just copy and paste this to your Arduino IDE. I am using right hand rule. Sorry that's all for now (12 Aug 2017 5:38AM) I don't have more time to update more of this now. Someone asked about the "O" in "void choosepath()", then I realized that I have to update the "void shortpath()". (10 May 2019 10:38 MYT)

Comments

Only logged in users can leave comments

Anonymous user

2 years ago

path[readpath]=='O' what does 'O' mean in the above line?

rajajack21

2 years ago

Sorry I just saw your comment. The "O" there is explained below. In "void shortpath() //calculate the shortest path", the short path are replaced with a direction and two O(es). This is like double steps to get the chosen path. The "void shortpath" starts checking from the character number 3 from the last, if it is a "U".. then the previous and the following characters are being checked as seen here: ``` > void shortpath() //calculate the shortest path > { > //because (..F) is the last and there is no U recorderd before F > int x = (pathlength-2); > > while (x > 0) > { > if (path[x]=='U') > { > if (path[x-1]=='L' && path[x+1]=='L') > {path[x-1]='S';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='L' && path[x+1]=='S') > {path[x-1]='R';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='R' && path[x+1]=='R') > {path[x-1]='S';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='R' && path[x+1]=='S') > {path[x-1]='L';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='S' && path[x+1]=='L') > {path[x-1]='R';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='S' && path[x+1]=='R') > {path[x-1]='L';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='L' && path[x+1]=='R') > {path[x-1]='U';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='R' && path[x+1]=='L') > {path[x-1]='U';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='S' && path[x+1]=='S') > {path[x-1]='U';path[x]='O';path[x+1]='O';} > //--------------------------------------- > x--; > } > else > {x--;} > } > } ``` > Example: > RURURRRURURURRURF > ...RUR is changed into SOO > RURURRRURURURSOOF > ...RUR is changed into SOO > RURURRRURUSOOSOOF > ...RUS is changed into LOO > RURURRRULOOOOSOOF > ...RUL is changed into UOO > RURURRUOOOOOOSOOF > ... RUS with a lot of O(es) between U and S, changed into LOO > here I just realized that my code (void shortpath) has a defect, thanks to you. My code needs to be updated. 10 May 2019. > RURURLOOOOOOOOOOF > ...RUR is changed into SOO > RUSOOLOOOOOOOOOOF > ...RUS is changed into LOO > LOOOOLOOOOOOOOOOF > > So the shortest path is LLF. That is why we need "else if (path[readpath]=='O')" in "void choosepath": ``` void choosepath()//to get rid of the effect of “path[]==0” in the record { if (path[readpath]=='F') ... ... else if (path[readpath]=='O') { readpath++;choosepath(); } readpath++; shortestpath(); } ```

Anonymous user

2 years ago

Great job

rajajack21

2 years ago

Thank you

Anonymous user

2 years ago

What are the components used????

rajajack21

2 years ago

Try to contact this person: https://www.linkedin.com/in/yudanarko/ I got the line tracer robot from him So I almost know nothing about the components

Anonymous user

6 years ago

Great job

rajajack21

2 years ago

Thank you

Anonymous user

6 years ago

path[readpath]=='O' what does 'O' mean in the above line?

rajajack21

2 years ago

Sorry I just saw your comment. The "O" there is explained below. In "void shortpath() //calculate the shortest path", the short path are replaced with a direction and two O(es). This is like double steps to get the chosen path. The "void shortpath" starts checking from the character number 3 from the last, if it is a "U".. then the previous and the following characters are being checked as seen here: ``` > void shortpath() //calculate the shortest path > { > //because (..F) is the last and there is no U recorderd before F > int x = (pathlength-2); > > while (x > 0) > { > if (path[x]=='U') > { > if (path[x-1]=='L' && path[x+1]=='L') > {path[x-1]='S';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='L' && path[x+1]=='S') > {path[x-1]='R';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='R' && path[x+1]=='R') > {path[x-1]='S';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='R' && path[x+1]=='S') > {path[x-1]='L';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='S' && path[x+1]=='L') > {path[x-1]='R';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='S' && path[x+1]=='R') > {path[x-1]='L';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='L' && path[x+1]=='R') > {path[x-1]='U';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='R' && path[x+1]=='L') > {path[x-1]='U';path[x]='O';path[x+1]='O';} > else if (path[x-1]=='S' && path[x+1]=='S') > {path[x-1]='U';path[x]='O';path[x+1]='O';} > //--------------------------------------- > x--; > } > else > {x--;} > } > } ``` > Example: > RURURRRURURURRURF > ...RUR is changed into SOO > RURURRRURURURSOOF > ...RUR is changed into SOO > RURURRRURUSOOSOOF > ...RUS is changed into LOO > RURURRRULOOOOSOOF > ...RUL is changed into UOO > RURURRUOOOOOOSOOF > ... RUS with a lot of O(es) between U and S, changed into LOO > here I just realized that my code (void shortpath) has a defect, thanks to you. My code needs to be updated. 10 May 2019. > RURURLOOOOOOOOOOF > ...RUR is changed into SOO > RUSOOLOOOOOOOOOOF > ...RUS is changed into LOO > LOOOOLOOOOOOOOOOF > > So the shortest path is LLF. That is why we need "else if (path[readpath]=='O')" in "void choosepath": ``` void choosepath()//to get rid of the effect of “path[]==0” in the record { if (path[readpath]=='F') ... ... else if (path[readpath]=='O') { readpath++;choosepath(); } readpath++; shortestpath(); } ```

Anonymous user

7 years ago

Great job! Long time never heard you. The robot which was used by Raja Joko was my first version of Arduino robot. It uses 5 line sensor, cheap locomotion made from 2 toy cars, 1 own made motor driver, and a Arduino Uno.

rajajack21

2 years ago

Thank you very much, Pak Yudanarko. If anyone wants to ask more about the components of the robot, please ask Mr. Yudanarko.

Anonymous user

7 years ago

What are the components used????

rajajack21

2 years ago

Try to contact this person: https://www.linkedin.com/in/yudanarko/ I got the line tracer robot from him So I almost know nothing about the components

rajajack21

0 Followers

1 Projects

+3

Work attribution

16

14