ProMRDS Home Page Line Following

Professional
   Microsoft Robotics Developer Studio
Home Page Book Contents This Chapter

Line Following using the Maze Simulator

Background

Questions about Line Following in the MRDS Simulator come up from time to time in the Discussion Forum. This example uses the Maze Simulator. The concept is very simple -- Make some really tiny walls (only a few millimeters high) to act as the lines! The result is shown in the screenshot below (click on the image for larger view):

Line Following using a Pioneer robot

To set up the Line Following environment there are several steps you need to take:

Creating a Bitmap Image for Line Following

The objective of creating a bitmap image is to specify the lines that the robot must follow. It only needs to be in two colors -- the background and the lines. A sample image is shown below (at half size - the full image is 500x500):

Line Following Plan

A copy of this image is included with the code. It is called, not surprisingly, LineFollowing.bmp, and should be in store/media/Maze_Textures.

The starting point is in the bottom left corner, and the finishing point is the circle near the middle. Notice that there are loops and dead ends. It is not an easy map to follow.

It is difficult to draw smooth curves in a bitmap, and the Maze Simulator is not very good at handling them because it is designed to work with straight lines. Robots cannot easily turn 90-degree corners. However, this just adds to the challenge!

As with any maze, the pixel in the top-left corner specifies the background color (which is grey in this case).

Changing the Config File

The Maze Simulator configuration is saved in MazeSimulator.Config.xml. This file should be 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.

The first thing that needs to be changed is the name of the Maze:
<Maze>/ProMRDS/Chapter9/MazeSimulator/LineFollowing.bmp</Maze>
In this example the file should be in the MazeSimulator source folder, but you can move it somewhere else.

You can change the line color if you wish, but line following is usually done using black lines on a light background (or vice versa). The ground color can be changed using the texture. The plaster texture is a good light background:
<GroundTexture>plaster.jpg</GroundTexture>
This texture file should already exist in the store\media folder.

The color of the lines can be changed using the corresponding entry in either the WallTextures or WallColors. In the sample config, the WallTexture is specified as black for the 8th entry in the WallTextures:
<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/SolidBlue.bmp</string>
  <string>Maze_Textures/SolidMagenta.bmp</string>
  <string>Maze_Textures/SolidCyan.bmp</string>
  <string>Maze_Textures/SolidBlack.bmp</string>
...
</WallTextures>
(The 8th entry corresponds to White, which is the color of the lines in the bitmap image.)

The lines have to be really, really low walls. So change the Height Map so that the 8th entry is tiny:
<HeightMap>
  <float>0.005</float>
  <float>5</float>
  <float>10</float>
  <float>8</float>
  <float>10</float>
  <float>15</float>
  <float>15</float>
  <float>0.01</float>
...
</HeightMap>

Side note: The value for black is set to 0.005. If you change the background color in the bitmap to black, then you can get white lines on a black background. The background has to be lower than the lines. This is a special case because black has a pixel value of zero.

Notice that the 8th entry is 0.01. Normall this would be 1cm high, which is still a decent step, so you also need to modify the parameters that affect the scaling:
<WallBoxSize>0.99</WallBoxSize>
<GridSpacing>0.01</GridSpacing>
<HeightScale>0.1</HeightScale>
This reduces the height by a further factor of 10. The Grid Spacing is also reduced so that the pixels in the bitmap only correspond to about 1cm.

Lastly, position the robot so that it starts from the correct location. This is done as follows:
<RobotStartCellRow>280</RobotStartCellRow>
<RobotStartCellCol>-180</RobotStartCellCol>

Modifying the Maze Simulator's Camera Orientation

When the Maze Simulator creates the simulated Pioneer 3DX robot, it places a webcam on top of the robot. By default, cameras are oriented so that they look out horizontally. In order to see the floor immediately in front of the robot, we need to make two changes: Move the camera forward to look over the front of the robot and tilt it downwards.

Edit the config file and change the following settings:
<CameraPosition>
  <X xmlns="http://schemas.microsoft.com/robotics/2006/07/physicalmodel.html">0</X>
  <Y xmlns="http://schemas.microsoft.com/robotics/2006/07/physicalmodel.html">0.5</Y>
  <Z xmlns="http://schemas.microsoft.com/robotics/2006/07/physicalmodel.html">-0.5</Z>
</CameraPosition>
<CameraTiltAngle>-85</CameraTiltAngle>
Note that you do not need to do this if you are using the sample Line Following config that was supplied.

These changes move the camera forwards and angle it down at 85 degrees (the -85 in the CaneraTiltAngle).

You might think that the camera should be angled down at 90 degrees. However, this causes some strange behavior in the simulator as the robot rotates. The image in the webcam suddenly jumps as the orientation of the robot crosses 90 degree boundaries and it gets confusing. Using 85 degrees is close enough.

Requirements and Installation

This example is just an application of the Maze Simulator. Therefore you need to download and install the Maze Simulator first. Make sure that you have this working before you try to implement Line Following. Then make the minor code change above and rebuild. If you want to return to the original camera orientation, just comment out the new lines and recompile again.

LineFollowing.bmp should already be in the store\media folder. A config file called ProMRDS\Config\MazeSimulator.LineFollowing.Config.xml is also supplied. You need to rename this to MazeSimulator.Config.xml. You should take a copy of your existing config file before you overwrite it.

How to run Line Following

NOTE: There is no code to perform Line Following! This application just provides the simulation environment you need to do Line Following. The rest is up to you. You do NOT modify the Maze Simulator service. Instead, write a new service that connects to a Webcam and a Differential Drive as partners.

At the MRDS Command Prompt, enter the following command:
dsshost -port:50000 -tcpport:50001 -manifest:"ProMRDS/Config/MazeSimulator.manifest.xml"

Alternatively, you can run the Maze Simulator from Visual Studio. Regardless of how you start the Maze Simulator, you must have copied LineFollowing.bmp and MazeSimulator.Config.xml to the correct folders first.

When the Simulator window appears, select the robocam from the Camera menu. You should see something like the following screenshot:

Camera view of a line

The objects in the window at the bottom are the bumpers at the front of the Pioneer robot. If you do not want these in the picture, you will have to adjust the Z coordinate of the camera Position a little more. However, this gives you a point of reference.

The T-junction is the start of the Line Following maze. This is where your robot should begin its journey, so it needs to start out by moving forwards until it recognizes the line.

If you use the Dashboard that comes in the Maze Simulator package, you can connect to the Pioneer's Differential Drive and also the camera. Try driving the robot around and following the line yourself. It's not easy!

The Challenge

Now it is over to you. Write a service that can successfully navigate by following the lines and locate the circle at the end point. Processing the images should not be too hard because the black line is very clear. 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.)

Legal Stuff

Thanks to Jason Summerour at RoboticsConnection for providing a sample line following plan.