WallBot – an EOPD Based Wall Follower

The WallBot is wall follower that uses a HiTechnic EOPD sensor to track the wall on the right side of the robot and an Ultrasonic Sensor to detect inside corners.  The robot is based on the new HiTechnic Trike Base.  In this article the program is in the LEGO Mindstorms NXT-G programming language.  Future articles will demonstrate the WallBot in other languages too.

Essentials:
Building Instructions for the HiTechnic Trike Base
View Instructions for adding sensors to make the WallBot
NXT-G WallBot Program for LEGO Mindstorms 1.1
NXT-G WallBot Program for LEGO Mindstorms 2.0

First, a note about this new model.

HiTechnic Trike

The HiTechnic Trike has been designed so that it can be built from either the LEGO Mindstorms NXT 1.0 or 2.0 sets.  The Trike only uses parts that are available in both sets with the note that some part colors are different and the tires are a different size.  Either the tires from the 1.0 or the 2.0 sets will work with this model.  The building instructions show the model using the part colors that are included in the 2.0 set, if you are using the older LEGO Mindstorms set , you will need to substitute using the similar parts that you have.

You can download the building instructions here:  HiTechnic Trike Base Instructions

The Trike is a simple three wheeled robot base with one drive motor for each side plus a caster wheel in the back.  The robot features an accessory bar in the front to allow mounting either sensors or even for the third motor to add additional capability to your robot.  Feel free to use this robot base for your own projects.  If you publish anything, either in print or on the Internet using this robot base, all we ask is that you give credit back to HiTechnic.

The EOPD Sensor

Several times I have been asked, “Is the EOPD sensor like the LEGO Light Sensor or the Ultrasonic Sensor?”  Well… yes, it is.  In way it is a little like both of those sensors.  Like the LEGO Light Sensor, the EOPD sensor has an LED for illumination and the light sensativ element for measuring light.  Like the Ultrasonic sensor, it can measure distance though with light and not sound.  How it measures distance, though, is very different than the Ultrasonic sensor, I will discuss that in a different post.

So what exactly is the EOPD sensor?  EOPD stands for Electro-Optical Proximity Detector.  Without dwelling on what that those words mean, let me explain how it works.  The EOPD consists of a red LED and light sensitive element.  The LED on the EOPD pulses, i.e. it switches on and off, rapidly.  As the LED comes on, the electronics in the sensor measures how much more light comes into the sensor element.  Since it is looking for the change in light as the LED comes on, ambient light has very little effect on the value of the sensor.  Basically, light comes out of the LED, and shines on something in front of it, some of that light then comes back into the sensor.  It is this light that comes back into the sensor that the EOPD measures.  That means the value is dependent on not just what it shines on, but also how far away it is.  Thus “Proximity Detector” since the EOPD sensor will only “see” what is in the proximity of the sensor.

There are really two things that determine what value the EOPD sensor will return.  One is the reflective nature of the surface it is pointing at.  If it is observing something dark, more light is absorbed, thus less light comes back to the sensor.  If it is pointing at something light colored, then more light comes back and you get a higher value.  The other thing that determines the value is the distance to the surface.  If the surface is close to the sensor, then more light comes back than if the surface is further away.  I think of these as two variables in an equation.  One variable is the reflective nature of the surface and the other is the distance.   If you can control one of these two variables, then you can use the EOPD sensor to determine the other.

For this project we are going to use the ability to measure distance to build a wall follower.  The goal will be for the robot to drive along a wall, a few centimeters away, and not touch it.  It should handle sharp corners, both inside ones and outside corners.

The EOPD sensor can opertate in either a short range or a long range mode.  Short range is less sensitive and best for ranges less then 5cm.  For the WallBot, it is best to use Long Range which can handle distance of more than 20cm.

The HiTechnic Trike Wall Follower

First build the HiTechnic Trike and then add the EOPD Sensor and the Ultrasonic Sensor using these instructions:

Click to enlarge image

The EOPD sensor is used to track the wall while the robot is driving trying to keep it at a safe distance from the wall.  The Ultrasonic sensor is used to detect inside corners.  If the robot approaches an inside corner, then the Ultrasonic sensor will detect the upcoming wall and the robot will turn sharply to the left to avoid the wall.

You can download the NXT-G Prgrams for the WallBot here:

NXT-G WallBot Program for LEGO Mindstorms 1.1

NXT-G WallBot Program for LEGO Mindstorms 2.0

Each zip file above contain two NXT-G programs HTWallBot and HTWallBotView.  HTWallBotView is just a sensor view so you can see the values of the two sensors.  This will be useful in understanding how the program works.  HTWallBot is the main wall following robot.  I will talk more about it below.

The basic strategy for wall following with the EOPD sensor to determine where the robot is relative to the wall.  If the robot is too close, steer away and if it is too far away then turn closer to the wall.  To make it smooth the amount that the robot turns will be based on the value of the sensor, in other words, the amount that the robot turns will be proportional to the error.  In the simplest form, the Wall Follwer program can look this:

If you want, you can try this program and see how it works.  You will find that it does okay with straight walls but can’t handle corners very well, especially outside corners since the robot will turn in too early since it will start turning as soon as the EOPD sensor goes past the corner.  It also may not handle inside corners very well because it is likely to either turn too late or too sharp and hitting one or both of the walls.

You notice that the program above consists of a loop and three main parts: read the sensor, process the data to decide on the action, and then perform the action by controlling the motors.  Lets take these instructions one at a time to make sense of this program.

  1. The EOPD Sensor is set to long range and we are using the raw value.  This value can range from 0 to a theoretical 1023.  I tested it and found that will the WallBot it was about 100 when the robot was 5cm from the wall and would go up to as much as 700 if the EOPD sensor is really close to the wall and down to zero, or almost zero, if there is nothing if front of the sensor.
  2. Since I liked the distance that the robot was at when the EOPD sensor had a value of 100, I subtract the raw value from 100 so that I get a negative value when the robot is too close and a positive value when it is too far away and a value close to zero when the robot is just right.  You can think of this value as the error.
  3. I take this error and plug it in directly to the Steering Input of the Move block.  Often when you do something like this you need to scale the number up or down by multiplying it with a constant, I found that plugging it in directly worked pretty well as a starting point.

The program HTWallBot.rbt does those same basic three things but takes corners into account and does the action a little different to improve performance.  Here is what the whole program looks like:

You can’t actually see the whole program in this view because the Switch structures are in tabbed and not in a flat view.  The best way to view this program is in the LEGO Mindstorms Software so you can click on the tabs of the Switch structures to see the code for each condition.  The view above is what it looks like under normal wall tracking when it is not approaching either an inside or outside corner.

Just like the simple version, it starts by reading the EOPD Sensor and subtracting the raw value from 100 to get an error, then things get a little more complicated.  Before it uses the error value it does a little more advanced processing.  First it saves this error into a variable called Steer. Then it compares the EOPD value to see if it is less than 30, this is the condition that can happen if the robot is approaching an outside corner where the wall just appears to go away.  Assuming normal wall tracking, it will take the false case of that first switch statement.

Inside the False case of the first Switch statement, the B motor Rotation Sensor is reset to zero.  This will happen every time through the loop while there is a wall on the side of the robot that the EOPD sensor can see.  This will be used for outside corners where the wall goes away and we want to measure the distance since the last time the wall was seen.  After the motor reset, the Steer variable is compared with -180.  For the steer value to be this low, the EOPD sensor must be very close to the wall, most likely in the middle of inside corner.  The True case for this swich simply sets the Steer value to -180 so that even if the EOPD sensor is very close, the Steer value is limited to -180 and will not go beyond that.  I found that if the robot turned to sharply in an inside corner, the back wheel would often hit the wall that the robot had been tracking.

Under normal wall tracking conditions, the program will go to the False case of the second Switch statement.  Here two things are examined: the Steer variable value is compared with -100 and the Ultrasonic Sensor is check to see if there is a wall less than 20cm away.  Basically what is happening here is that if the Ultrasonic sensor detects a wall of an inside corner, I want to set the Steering value to -100, a fairly sharp left (It will work out to be a turn where the inside wheel is stopped and the outside wheel goes full power).  If at the same time the EOPD sensor detects a distance so close to the wall that it warrants a sharper turn than that, then that will take precedence and it will go for the sharper turn.

At the end the Steer variable is used to set the power of the two drive motors.  I found that using two Motor commands gave me better performance than setting the Steering value of a single Move command so that is what this code does.  For the C motor the power is basically 100 + the Steer variable and for the B motor the power is 100 – the Steer variable.  Since the Motor commands always take the absolute value of the Power value, in order to get the motor to go backwards for a negative power it is necessary to set the Direction value based on the sign of the desired power.  That is what the Comparison blocks before each of the Motor commands is all about.

Conclusion

The EOPD sensor can be used to measure short distances when the nature of the wall is known.  One huge advantage of the EOPD Sensor is that it is immune to the variations of ambient light.  During the video, for example, you can see that the robot tracks the wall just as well when it is on the illuminated side as on the dark, back, side of the wall.  Another feature of the EOPD sensos is that as an analog sensor, it is very fast.  A new value of the EOPD sensor can be read every 3 milliseconds.

Tags: , , ,

4 Responses to “WallBot – an EOPD Based Wall Follower”

  1. This is wonderful, my son really loves star wars lego and regularly annoying me regarding it – this post has clarified some of my doubts. Time for lots more browsing!

  2. Only recently my own son actually asked if I can obtain him some lego products for his birthday celebration, I am surprised and also thrilled, it’s a great studying toy.

  3. Abdullah Alhammadi says:

    I like it !
    but is there a problem with the program ? I downloaded it and extracted it and it wouldn’t work ..
    do you think there’s a problem with the program ?

  4. Gus says:

    Not that I am aware of. What problem did you encounter?

Leave a Reply