![]() |
![]() |
Professional
Microsoft Robotics Developer Studio
Having a Maze Simulator raises the obvious question of how to create mazes in the first place. A simple program is provided that can be used to generate new mazes using the Depth-First Search algorithm.
If you click on the image to see a larger view, and look very closely near the green wall segment at the left-hand side (the start point) you might just see the Pioneer robot and the bright red dots from the Laser Range Finder hitting the wall.
To set up a new maze there are several steps you need to take:
Run the Maze Generator. Select the Maze Parameters from the Options menu:
The generated mazes are always square. (If you want rectangular, then you will have to modify the code). Therefor the number of Grid Blocks per row is also the number of columns.
The Grid Block size is the number of pixels in the bitmap for each "cell" or Grid Block. Remember that you can scale the pixels using the GridSpacing parameter in the Maze Simulator config file. For example, if you make the GridSpacing 0.1 and use 20 pixels per block, then the cells will be 2 meters square in the simulated world.
Wall Thickness is also specified in pixels. It must be less than the Grid Block size or there will not be any corridors!
You can repeatedly generate new mazes until you find one you are happy with by using File \ Generate New Maze. When you see one you like, use File \ Save As to save it as a BMP or GIF file.
If you wish, you can open the maze in Microsoft Paint and change it or adjust its size. Note that there are cells marked with green and red which can act as the start and finish points. However, any clear cell on the left should have a path to any clear cell on the right of the maze. You can simply recolor the wall segments as appropriate. Note that colors correspond to textures in the Maze Simulator.
A sample maze is shown below. This was actually edited in Paint to reduce the padding around the edges. However, remember that the top-left pixel is the floor color, so do not remove all of the padding. (This is always white in the generated mazes).
A copy of this image is included with the code. It is called, not surprisingly, NewMaze.bmp, and should be in store\media\Maze_Textures.
The Maze Simulator configuration is called MazeSimulator.Config.xml. This file is located in the ProMRDS\Config folder. Note that you should make a backup copy of the existing config file first!
You can edit this file using Notepad. The following instructions explain the changes to the file, but you do not have to make them if you use the supplied file, MazeSimulator.MazeGen.Config.xml.
The first thing that needs to be changed is the name of the Maze:
<Maze>NewMaze.bmp</Maze>
In this particular example the file must be in store\media\Maze_Textures folder, but you
can move it somewhere else by specifying a path.
The ground
color can be changed using the texture. The cellfloor or concrete textures
might be suitable:
<GroundTexture>concrete.jpg</GroundTexture>
This texture file should already exist in the store\media folder.
The color of the walls can be changed using the corresponding entry
in either the WallTextures or WallColors. You might like to set the
texture for the blue walls to Maze_Textures\bricks.jpg.
The order is Black, Red, Green (Lime), Yellow, Blue, Magenta, Cyan,
White, etc.
<WallTextures>
<string>Maze_Textures/SolidBlack.bmp</string>
<string>Maze_Textures/SolidRed.bmp</string>
<string>Maze_Textures/SolidLime.bmp</string>
<string>Maze_Textures/SolidYellow.bmp</string>
<string>Maze_Textures/bricks.jpg</string>
<string>Maze_Textures/SolidMagenta.bmp</string>
<string>Maze_Textures/SolidCyan.bmp</string>
<string>Maze_Textures/SolidBlack.bmp</string>
...
</WallTextures>
You can also change the Height Map so that the start and end points are a different height from the rest of the walls.
Lastly, position the robot so that it starts from the correct location.
This is done as follows:
<RobotStartCellRow>105</RobotStartCellRow>
<RobotStartCellCol>-190</RobotStartCellCol>
Unfortunately, for historical reasons, the way that you determine this location
is a little complicated. You have to find the pixel location in the bitmap
image where you want to put the robot. For this example it is (25,320) which
is next to the green start point.
The origin in the simulated world is at the center of the map.
The map is 430x430 pixels, which places the origin at (215,215).
Cell row numbers (vertical coordinates) increase as you move down the image
and cell column numbers (horizontal coordinates) increase from left to right.
So, in this example, the coordinates of the robot are (-190,105), calculated as follows:
Row = 320 - 215 = 105
Col = 25 - 215 = -190
NOTE: If you accidentally place the robot inside a wall, then it will probably be thrown up in the air when the simulation starts and fall down on its side. Keep adjusting the robot's position and re-running the Maze Simulator until it starts up OK.
If you plan to use the ExplorerSim program with a generated maze, you will have
to modify the config file for ExplorerSim to adjust the size of the map that it
generates. Otherwise you might not see anything on the map! For this example,
a size of 44 meters should be sufficient:
<MapWidth>44</MapWidth>
<MapHeight>44</MapHeight>
Now it is over to you. Write a service that can successfully navigate the maze using the Webcam or the Laser Range Finder. Processing the images should not be too hard because walls should be quite different colors from the floor. You can either handle the images yourself or use a package like RoboRealm. (Look in the Dashboard code to see how to connect to a webcam and capture images.)
If you want to use the Laser Range Finder, look at the code in the ExplorerSim service.
The original DFS Maze Generator was written by Mike Gold. It was modified by Trevor Taylor.
This program is free for non-commercial use.