Center First Routing Alorithm

16
MICROMOUSE IEEE micro-mouse routing in maze competition is a popular event on the world, and has been a high level competition for several years overseas. At present, this event is being introduced into China, the Chinese first micro- mouse routing competition is held in Shanghai in November 2007.Some universities and companies participate in this tournament . It has a center, which is the destination cell for the Micromouse. The robot has to search the entire maze and find the path that it can travel in the shortest possible time. This maze is a standard used in all the competitions held worldwide by the IEEE and other standard Institutions. Maze Specification: The maze in the Micromouse competition consists of multiples of an 18cmx18cm square. It consists of 16x16unit squares . The walls of the maze are 5 cm high and 1.2 cm thick . Rules of Micromouse: The robot must be completely autonomous The robot must reach the center in the least possible time. No external power source is allowed. Hardware requirements for micromouse:

Transcript of Center First Routing Alorithm

  • MICROMOUSE

    IEEE micro-mouse routing in maze competition is a popular event on the world, and has been a high level competition for several years overseas. At present, this event is being introduced into China, the Chinese first micro-mouse routing competition is held in Shanghai in November 2007.Some universities and companies participate in this tournament . It has a center, which is the destination cell for the Micromouse. The robot has to search the entire maze and find the path that it can travel in the shortest possible time. This maze is a standard used in all the competitions held worldwide by the IEEE and other standard Institutions.

    Maze Specification: The maze in the Micromouse competition consists of multiples of an 18cmx18cm square. It consists of 16x16unit squares . The walls of the maze are 5 cm high and 1.2 cm thick . Rules of Micromouse:

    The robot must be completely autonomous The robot must reach the center in the least possible time. No external power source is allowed.

    Hardware requirements for micromouse:

  • 2 | P a g e

    Microcontroller : It is the brain of the robot ,it decides the path followed by robot by analyzing input from sensors.

    Sensors: They are used to detect side walls and wall in the front. Sensors can be either analog or digital.

    External EEPROM for storing coordinates of maze . Motors : They can be either DC or Servo. Motor Drivers for controlling the motors. Power supply.

    Software Details:

    Microcontroller can be programmed in either assembly or c language. It requires multiple layers of programming.

    The Motion Layer: It is comprised of Code that controls the motion of the robot. The Code from the Logic layer calls this layer to move the robot from one cell to another as and when required. This layer would also automatically correct the motion of the robot if it has strayed towards left or right.

    The Logic Layer: Objective of this competition is to find the shortest path towards the center therefore a logic or algorithms are used for deciding the optimal path. Some of the algorithms commonly used are: o Depth first search. o Floodfill o Follow the wall on left( basic algorithm) o LRSRT o LSRRT o RLSRT o Center first routing theorem.

  • 3 | P a g e

    CENTER FIRST ROUTING THEOREM ALGORITHM

    In the algorithm, a Center-First-Theorem is applied to find out several short roads in maze, then the shortest road can be find out among those roads by comparing with each other. Therefore, the algorithm is able to escape from the complex work of recording whole routing information of the maze. Methods to realizing coordinate recording, center-first routing and optimum path sorting are put forward. In practice, it is proved that this algorithm can reduces error execution and improves efficiency. Existing maze routing algorithms generally concentrate on recording information of the whole maze, deal with and repair this information and pick out the best road. In theory, those algorithms seem have no bug and can work very well in any maze. But, because of recording, repairing and managing the whole information, the process is very complexity and is apt to making mistakes and time consuming. For these reasons, those algorithms arent easy to be carried out in practice. This paper presents a high efficiency algorithm of micro-mouse routing in maze, It applies the Center-First-Routing-Theorem (CFRT) to finding out the shortest road without recording, repairing, and managing whole messages of maze, at the same time, it reduces error execution and improves efficiency in practice. The basic ideas of CFRT algorithm is as follows. According to CFRT, the algorithm finds out several short roads and records the details of the road with coordinate, then calculate the number of the total steps of the road and the times of turning it has. Using a matrix to record the directions that micro-mouse searching in maze, it select another direction when reach the same bifurcation junction next time. The messages mentioned above is also used by the mouse to avoid searching the same route and turn back when it has no direction to go (meet a cul-de-sac). Each time a new route being found out, it is compared with former shortest route which is stored in the mouse. If total steps of the new route is less than the former shortest one, the former shortest route is replaced by the new route, otherwise do nothing. And the original shortest route is the route searched at first time. Searching within the allowed time and getting the shortest route, the best speed is tuned to run to the end.

  • 4 | P a g e

    DETAILS OF ALGORITHM

    1. Maze Information:

    A maze can be very confusing because every cell has four possible paths and choosing the optimal path is complicated. The four possible paths are:

    Cul-de-sac

    Straight

    Turning

    Crossroad

    T-shaped Road

  • 5 | P a g e

    In order to maintain the maze information one byte is used to mark traffic information of each cell of the roads, lower four bits 0-3 of the byte mark whether four sides (the right, down, left and up of cell, respectively to the directions of east, south, west and north, as shown in Figure 2) of the cell have obstacles or not. If one side has obstacle, set the marker of it to1, or do nothing. The middle two bits, 4th and 5th of the byte, mark the state of cul-de-sac. If there is no cul de-sac, set the marker to 11, and, one cul-de-sac corresponding to 01 and two to 10, or do nothing. The rest two bits mark the situation of road. While 00denotes one side to go (straight, left and right turning), 01 denotes T-shaped road and 10 means crossroad.(Given the original state of byte is 00H).

    BIT 3 2 1 0 DIRECTION NORTH(U) WEST(L) SOUTH(D) EAST(R)

    CUL DE-SAC INDICATOR

    BIT 5 4 NO CUL DE-SAC 1 1 1 CUL DE-SAC 0 1 2 CUL DE-SAC 1 0

    BIT 7 6 1 SIDE TO GO 0 0

    T-SHAPED ROAD 0 1 CROSSROAD 1 0

    Original state of the register: 00H

  • 6 | P a g e

    2. Recording coordinate and information of mazes cell

    The information of cell is recorded in a matrix whose name is maze and size is 1515. Making the cells location of maze respectively to coordinate, the left-down corner starting cell is to origin (0,0), north toy-axis and east to x-axis ( a quarter random maze as shown in Figure ). At the same time, members of the matrix strictly fit to the coordinate. For example, the cell 3 4 maze fits the coordinate (3, 4). And, except the start and the end, set all the original message of the mazes cell to FFH. Using a register named Dir to recording the direction each time mouse selected. Dir Direction 0 Y++ : north 1 X++: east 2 y--: south 3 X++: west Therefore, according to rules of the competition, the original location of micro-mouse is (0, 0), and the routing direction is north.

  • 7 | P a g e

    In process, once micro-mouse turns left, 1 is subtracted from the value of register Dir . And when the value of Dir is 0, it becomes 3 if the subtraction is done. The

    same thing is do for right turn, but the subtracting 1 is replaced by adding 1, and the value becomes 0 when 1 is added to the value 3. For turning back from left or from right, subtracting 1 or adding 1are become subtracting 2 and adding 2. And the valueof Dir circulates among 0 and 3. However, nothing is done to the value

    of the Dir when micro-mouse keeps going ahead straightly. Therefore, we mouse can deduce variation between adjacent cells coordinates from value change between current Dir and the former Dir . And we can deduce two formulas to

    calculate coordinate of current cell as follows:

    Where are coordinates off ormer and current cells respectively, d is value of Dir of current cell. The traffic situation of each cell can be detected by infrared sensors of the micromouse ,so the information can be recorded in matrix maze with the coordinate we get from above formulas. For example, micro-mouse straightly walks a step from cell (0, 0) to (0, 1) with the Dir s original value is 0, the value of the Dir keeps no change, we can work out the coordinate (0, 1) of current cell by formulas (1) and (2). Then it can detect other sides of cell (0, 1). If the east side has wall, we set the east marker of cell (0, 1) and the west marker of cell (1, 1) to 1. Detecting and dealing with other sides in this way. Moreover, we can know whether there is a T shaped road or crossroad on this cell and change the marker of it by detecting four sides information of the cell. At same time, we also can know that right side of the micro-mouse is east (the side x++), left is west (the side x--).

  • 8 | P a g e

    3. Cut Cul de-sac. There are some roads cant lead to end and has no way to go to next cell of the maze, we call it cul-de sac. In order to avoid micro-mouse to walk into those roads again, we should make a marker and block its information from the road and matrix maze. Specific method are taken as follows: Firstly, each time when micro-mouse makes a back turning (means there is a cul-de-sac), both turning back from left and from right, making a marker in a register whose name is noroad ,with the value of 1 means there is a cul-de-sac while 0 is no. So we can know if there is a cul-de-sac or not by the value of register noroad , and set values of all cells to FFH, which belong to the cul-de-sac between the end of it and the crossing cell nearest to it. Then ,marker of this direction of the nearest crossing cell is set to 1 to prevent micro-mouse from selecting this direction when it goes here again. At last, micro-mouse turns to other directions from the crossing by judging the information stored before.

    For instance, in Figure 3cell (3, 0) is a cul-de-sac. When micro-mouse reaches this cell, it must make a back turning and set the value of noroad to 1. Because the value of noroad is 1,micro-mouse should keep walking forward and changing the information of the passed cells from (3,0) to (1, 1) to FFH while it comes back. After it reached the nearest crossing cell (1, 2), it clears the register noroad to 0, sets the marker of cul-de-sac of this cell and selects a new direction to go by judging the information of this cell stored before.

  • 9 | P a g e

    Implementation Of CFRT

    From the starting cell, micro-mouse detects which direction of the front, left, right sides can be taken. In consideration of the information stored in the register Dir , micro-mouse selects a direction to go. When micro-mouse comes to a cell that has only one direction to go, it doesnt make choice but just go by this direction. For a crossing, it chooses the direction pointing to the end which can makes the value of Dir become 0 or 1 after it made a action ( That is direction of x++ or y++), than other directions. If there are two adjacent road junctions or be a crossing again, let x++ and y++ direction be prior alternatively. And if the direction leads to the end, other directions are not taken into consideration. By this way, micro-mouse keep on searching roads till it reached the end cell (7, 7).But, how to select searching direction? Given value of the former cell Dir is dn-1 and the current is dn , the relation between them can be shown in the following:

    Dn=dn-1 + m

    Where, m = (-2, -1, 0, 1, 2), and the value -2 means turning back from left (exiting a cul-de-sac), -1 means turn left (no obstacle at left side), 0 for going ahead (no obstacle at front), 1 for turning right (no obstacle at right side) and 2 for turning back from right (exiting from a cul-de-sac). So the direction corresponding to the action that can make the value of Dir turn to 0 or 1 is prior to the other directions. At the same time, it uses a times register named times (original value is 0) to alternate priority of direction x++ and y++ between two adjacent road junctions. The value 0 means y++ first and 1 means x++ first.

  • 10 | P a g e

    THE SHORTEST PATH Two arrays are used to store the coordinate of roads being searched out. One array [] New Road stores the roads coordinate of current time, another array[] Short Road stores the coordinate of the shortest route picked out before. Each time a new route is searched out, the information of it is recorded in matrix maze and the coordinate of it is in [] New Road . If the total steps of the new route are less than the former, replace the shortest routes coordinate in [] Short Road with the coordinates of the new route in array [] New Road . If not, do nothing but keep searching new route. And the original state of [] Short Road is coordinate of the route searched out at first time.The time cost in straight road and turning is different, and the difference will becoming more large if the running speeds of straight road and turning are different, therefore, the total steps of a route is not simply equals to the sum of all steps taken in the route. Because the turning costs more time, method of calculating total steps can be shown as following formula [7]:

    In this formula, s is number of roads total steps, n is number of total cells of a route but without the cell in cul-de-sac. The t is times of turning, in which a 90 degree turning increases one number, while 180 degree increases two number. And a is for modulus of turning, it is very important to the result and should be chose on experiments and specific micro-mouse. If the speedthe micro-mouse cant be changed in the running process, value of a can be chose from 0.4 to 1.0, otherwise it can be larger.

  • 11 | P a g e

    ROUTING BY CFRT

    First Attempt

    Picking the quarter random maze as example again, we show the way how to select direction and calculate the total step. According to CFRT, micro-mouse starts the first searching road from cell (0, 0). At the T-shaped cell (1, 2), it selects x++ (east) to go for only x++ go next. When it reaches the crossing road cell (2, 2), it chooses the direction y++ (north) to go because it is the first time ( times is 0). And to the second T-shape road cell (5, 7), it chooses the direction x++ (east) to go because of no y++. When being the third T-shape road cell (6, 7), it chooses direction x++ again because of no y++ again, then it can go to the end. So a road can be shown in Figure above And the information of this route is stored in matrix maze. At the same time, the coordinates of this route are recorded in [] Short Road . From the figure and table, we can know the number n of cell in this road is 25, with 7 turnings of 90 degree. So s =25+7 0.5=28.5 (Given a is 0.5).

  • 12 | P a g e

    Second Attempt

    The second time searching: At the first T-shape road cell (1, 2), it also chooses x++ because of no y++ lead to next. And at the crossing cell (2, 2), it changes priority of direction x++ and y++, and chooses x++ to go, Then it reaches the second T-shape cell (6, 4), and chooses direction y++ to go because of no x++. After this, it can get to the second crossing cell (5, 5) and selects the direction y++ because of last is x++. When to the third T-shape road cell (5, 7), it selects direction x++. And at the last T-shape road cell (6, 7), it chooses direction x++ to go and can go to the end. The route is shown in Figure 4, and the information of this route is stored in matrix maze (As shown in table 2 with a two-dimension table). Also, the coordinates of this route are recorded in [] New Road . In this time, n is 23, t is 7, s =23+7 0.5=26.5. It is smaller than last s 28.5. So we store the coordinate of the route of this time in [] Short Road replace with former. But, t of each road maybe different, so we should choose a carefully on experiments. And different micro-mouse of the same style may have different a . For example, there are two routes, n is 26 and t is 4 for one route, n is 24 and t is 7 for another route. If we choose a as 0.5 at first time and 0.8 at second, we will get different shortest routes.

  • 13 | P a g e

    SPRINT

    After we got the shortest road, sprint is the key to win the game. Micro-mouse should sprint to the end with a best speed according to the coordinate of the road stored in [] New Road . The Followings denotes how to do it. Because we have got the shortest road, micromouse neednt do any searching and detecting. What it should to do is making actions and running to the end by judging coordinate of the roads cells. For instance, given that micro-mouse is on square cell (1, 4) and direction it running to is y++(north), and if the next cell is (1, 5), what it should do is running straight. And if the next cell is (2, 4), it should turn right. If next cell is (0, 4), it should turn left. The hardwares performance of micro-mouse plays an important place in sprint. If the micro-mouse can change speed while it running, a faster speed should be chose on straight in straight road and a slower speed in turning. And if the micro-mouses speed cant be changed in running, a best fixed speed should be selected to do the sprint. All those speeds should be chose carefully with specific micro-mouse after we do several experiments.

  • 14 | P a g e

    COMPARISON WITH OTHER ALGORITHMS Many different algorithms are there for solving micromouse maze. Some of them are enlisted below:

    Left-right-straight algorithm(LRSRT): Left sides priority is first, right is secondary, and straight is last.

    Left-straight-right algorithm (LSRRT) Right-left-straight algorithm (RLSRT) Right-straight left algorithm (RSLRT) Straight-left-right algorithm(SRLRT) Straight-right-left algorithm (SLRRT) Random algorithm (RRT): Each sides priority is same and which side to

    choose is random.

    Given the searching rule adopt by other algorithms is that the priorities of directions which have not been searched before are higher than those have at a crossing, and the time cost for searching a cell is 1s. Comparing with result of CFRT we can conclude that other algorithms often search more cells, cost more times and find out longer roads. We can see the result in the following table, too. And the differences will become more evidence if the searching time is added.

    LRSRT LSRRT RLSRT RSLRT SLRRT

    SRLRT

  • 15 | P a g e

    Conclusion

    By analyzing in theory and carrying it out in practice, we conclude that Center First Routing algorithm can avoid a lot of work in information recording, repairing and managing, and can improve efficiency. At the same time, it makes the programming of route searching become easily and reduces error execution in practice.

  • 16 | P a g e

    REFRENCES

    Center First Routing Theorem in Micromouse. We found the algorithm published in a 2008 IEEE paper by Yifeng Chen, Hengkai Zhao, Wanggen Wan, Xiaoqing Yu from School of Communication and Information Engineering, Shanghai University.

    www.wikipedia.com http://www.micromouseinfo.com