Boe-Bot Maze Navigation with QTIs

Boe-Bot Maze Navigation with QTIs·
Maze navigation is the heart of many robotic competitions, including the Micromouse maze and the Trinity firefighting competitions.· It is considered by most to be the one of the most challenging competitions since it requires a fair amount of work and ingenuity.· This project introduces basic maze navigation logic by using the Boe-Bot® Robot and the QTI Line Follower AppKit to navigate through an electrical tape maze containing 90° left and right turns, T-intersections and even dead ends!

Before continuing, make sure that you have already completed this checklist.· Especially if you have not already completed the Robotics with the Boe-Bot text, do that before you continue here.· It’s a great way to get started with Robotics!·
√······· Complete all activities in Robotics with the Boe-Bot
√······· Download the documentation for the QTI Line Follower AppKit and follow all instructions listed
√······· Review the How to - Boe-Bot QTI Line Following with 4 QTI Sensors for in-depth information on how the line follower code works.· This will be important when modifying the code for maze navigation.

Follow the instructions included with the QTI Line Follower AppKit.· Or, you can download them here.· Some hardware modifications are needed for this application.· In the AppKit instructions, each QTI is mounted edge to edge, but in this application, more spacing will be required between the QTIs so the Boe-Bot can detect turns and other obstacles.· Use Figure 1 as a guide and mount the QTIs so the two center QTIs are 0.8 cm apart, and the outermost sensors are 2 cm from the center QTIs.·Figure 1 – Mounted QTI Sensors

Building the Maze

Figure 2 shows a maze with a variety of obstacles for the Boe-Bot to navigate, including short and long straight tracks, 90° left and right turns, a T-Intersection, and a Dead End.· These obstacles pose a number of navigation challenges that you can solve, and in doing so, improve your Boe-Bot’s performance in larger and more complex mazes.· When constructing your maze, use a large piece of poster board and make sure each lane stripe is 1.5 inches of black vinyl electrical tape thick.· Figure 2 shows the maze designed for this activity (not to scale).·Figure 2 – Boe-Bot Electrical Tape Maze

Calibration, Calibration, and More Calibration

Before we begin, you should know that the last program in this project may be larger than the example programs you may have tried in Robotics with the Boe-Bot.· That’s because there are a lot of conditions that have to be taken into account!· This “mini project” demonstrates how to take a complex problem and break it down into small pieces in order to successfully solve it.· In order to do this, we’re going to have to calibrate our Boe-Bot to maneuver through each condition before putting the whole thing together.· This will save us time when troubleshooting if we know that each individual piece works as it should.

Moving Forward

Since the Boe-Bot will need to move slowly at some points in the maze, we’ll have to slow down the servos form the normal 850, 650 PUSLOUT durations.· This will help ensure that QTI readings aren’t missed as the Boe-Bot navigates through the maze, and you can use the same testing procedure introduced in Robotics with the Boe-Bot Chapter 4, Activity #2.· To slow forward movement, remember that a PULSOUT value of 750 stops the servo motors.· So we’ll want to pick values closer to 750 so the Boe-Bot slowly moves forward.· For further explanation, see the Rotational Velocity vs. Pulse Width for Servo graph in Robotics with the Boe-Bot Chapter 3, Activity #4.· Notice how the speed only really starts slowing as the pulses approach 700 from 650 and 800 from 850, so don’t worry if the change from 850 to 840 does not appear to have any effect.· Below is an adaptation of BoeBotForwardTenSeconds.bs2, and can be used to calibrate your Boe-Bot.

Once you’ve got the slow-forward code calibrated, the next step is to calibrate 90° turns.· There are a lot of them in the maze, so do a good job here.· It’s simple, and you’ve already calibrated your Boe-Bot to complete one in Robotics with the Boe-Bot Chapter 4, Activity #2…right?· If not, do not proceed until you are done with this important step! Now all we have to do is program the Boe-Bot to turn left when the maze path does.· You can set conditions for the Boe-Bot to follow using SELECT…CASE statements.· That way, if the QTIs are sending readings that the tell the BASIC Stamp the Boe-Bot needs to turn left, the BASIC Stamp can then send pulses to the servos to execute a 90° left turn.

·
Use the sample code below and adjust the values as necessary so your Boe-Bot executes 90° left turns while staying centered on the maze path.

Calibrating your Boe-Bot to execute 90° right turns works the same way as calibrating left turns.· These values probably won’t be a mirror image of left turns, so it’s important to test and find the necessary PULSOUT Duration Values to make the right turns as reliable as the left turns.· Use the sample code below and adjust the values as necessary so your Boe-Bot executes 90° right turns while staying centered on the maze path.

Alright, now what happens when the Boe-Bot encounters a T-Intersection?· One solution, which we will use here, is to program the Boe-Bot to make a random decision when it reaches the· T-Intersection.· We can do this by generating a pseudo-random number, and then turn left or right based a single bit of that random number (0 or 1).·
In MazeNavigation_TIntersection.bs2, a pseudo-random number ranging from 0 to 65535 is generated each time through the Main loop using the RANDOM command.· By looking at a single bit of that number, the Boe-Bot can turn left or right depending if the value of that bit is 0 or 1.·

Using MazeNavigation_TIntersection.bs2, complete the following tests:

√······· Run the code, and use the Debug Terminal to verify that you get pseudo random results each time
√······· Press the reset button and move the Boe-Bot along a straight track until it reaches a T-Intersection
√······· Repeat this process several times and verify that the turn results vary each time the T-Intersection is reached.

The dead end is another common maze obstacle, and therethththth are a lot of different approaches to solve this problem.· The program below handles it in the following way: tthe Boe-Bot will back up until it reaches the turn that led to the dead end, and then it will execute a 90° turn to get back on the maze path.·But what then?· The Boe-Bot still made another turn that brought it to the dead end, and if it makes that turn again, it will return to start instead of continuing to the end.· One way to solve this problem would be to create a new variable.· Let’s call it “AI”. When this variable is equal to 1, the Boe-Bot will ignore the left turn that would take it back to Start.· By creating a new subroutine named “AI_Decision”, the Boe-Bot can execute left turns based on the value of the AI variable.·Use the following code to verify that your Boe-Bot can successfully navigate its way out of a dead end.· Remember, some tweaking may be required!

The final calibration step will be to write code that keeps the Boe-Bot centered on the electrical tape, since there are several factors that could knock it off course: the tape not being perfectly straight, slippage during turns, etc.· Keep in mind that line correction can be difficult when navigating through mazes, since there are a lot of different ways that the Boe-Bot can move off track, and each response would be different.· In the solution below, whenever the Boe-Bot detects that it has gone off course, it responds in as follows:

•········· Stop
•········· Slowly rotate until both middle sensors are back on the line
•········· Turn slightly left/right depending which way the Boe-Bot went off track
•········· Turn in the other direction slightly to center the Boe-Bot back on the line

This code was taken through several iterations of calibration, testing, recalibration, re-testing, etc.· Since the values may be completely different you may also have to go through several iterations of test and recalibrate.· Keep in mind that these steps are essential for successful line following though the maze, since the center sensors need to be on the line when moving forward.· Use the following steps to make sure the Boe-Bot can stay centered on the maze path:

√······· Start with the far left sensor on the electrical tape and see how long it takes the Boe-Bot to center itself on the line
√······· If you find that the Boe-Bot doesn’t correct fast enough, try increasing the pulseCount durations in the FOR...NEXT loops
√······· On the other hand, if you find the Boe-Bot turns too far, try decreasing the pulseCount durations in the FOR…NEXT loops
√······· Repeat with the far right sensor, far left and mid left sensors, and far right and mid right sensors
√······· Once those values seem OK, try sliding the poster board to force the Boe-Bot to go off track and see how quickly it reacts

Comments

Congratulations, you’ve completed the calibration process!· After calibration, the final program may seem long, but it’s really just a compilation of all the short programs we’ve just written and tested. Breaking maze navigation, or and any other robotic problem, down into small pieces and calibrating at each step helps ensure success.· If you develop these habits now, it can save you tremendous amounts of time preparing for your next robotics project or contest entry.··································
The final code has some extra features to make navigation more reliable.· For example, there’s a Turn_Check subroutine that prevents the Boe-Bot from misinterpreting %0111 or %1110 as a full 90° turn.· It’s true that those QTI patterns do sometimes indicate a turn, but the same patterns can also indicate that the Boe-Bot has just drifted a little to the left or right of the line.· The Turn_Check subroutine figures out whether the Boe-Bot is off course or on a turn by: ·
•········· Moving the Boe-Bot forward for 5 pulses
•········· Obtaining another QTI reading
•········· If the sensors still tell Boe-Bot to turn, it will, any other reading returns the program to Main for line adjustment·
Another extra feature of the final code is that each SELECT…CASE statement in the main routine is sent to a subroutine.· This is because we want the code to execute as quickly as possible.· Each QTI reading is crucial to accurate maze navigation, so the faster the main program executes, the more QTI readings we obtain.· If we put every movement in the main routine, this severely slows down our code, which could cause missed readings in important areas, such as turns or T-intersections.· That’s why the code in the main routine only checks the QTI states, and depending on the result, gets sent to the corresponding subroutine.·
Before the code below will work on your Boe-Bot, it is essential for you to go through and update all the values you determined in this article’s calibration and testing steps.· When running your Boe-Bot through the maze, you may find that some values need to be adjusted to account for unforeseen obstacles.· That’s OK!· Experiment with the code until your Boe-Bot can consistently navigate through your electrical tape maze.

Although this code was written specifically for the maze in Figure 2, it can be adapted to a variety of other situations as well as expanded for more complex mazes.· Challenge yourself by creating a random maze and see if you can program your Boe-Bot to get through it!· You can also challenge your friends and see who can best navigate through mazes, or who can do it the fastest. As a final touch, try adding obstacles that can be detected by Whiskers, infrared or photoresistors, and try programming your Boe-Bot to navigate around these obstacles and get back on the maze.·_____________________________________________________________________________··(c) 2009·by Parallax Inc - all rights reserved.

In this case, there isn't a way to differentiate between the dead end and the end points. The tutorial was meant to be a simple 'starter' tutorial to cover the basics of maze navigation.

You could put a different tape pattern for the end of the maze so that the robot could be programmed to tell the difference. For example, maybe the end of the maze has a strip of tape that's detected by the outer two QTI sensors. You could then add a CASE statement to end the program if the robot detects that condition.

If you wanted to use 3 QTI sensors instead, you would want to use a thinner strip of electrical tape and position the sensors so that the robot will move straight forward if the middle sensor is over the line and the left and right sensors are over a white surface. Since you won't easily be able to tell whether the robot needs to adjust itself to keep moving straight or if it's at a left or right turn, you'll also need to take a different approach to the code.

One approach would be: if the robot detects 0 or 1 cases, you could keep moving forward instead of executing a turn. Then, if the robot detects no line after a few pulses, you know that it was a 90° turn and can execute the movement accordingly. You would then need to make small adjustments to get your robot back on the line.

There is also a line-following example from Andy using three QTI Sensors instead of four. You can find it here. This is best used for courses with rounded turns, but it should help get you started!

You'll need to do some experimenting, certainly, but that's part of the fun! Let us know how it goes & if you have any other questions!

I know this thread is semi - old, but this year at my High School I plan on spending an entire year learning this code.

My question here is: how do you insert the code to tell the Boe-Bot where it has already been. In other words, so it won't back track in the maze?

As of now, I am only using the basic IR transmitter and receiver to navigate a maze. Last year I used the Line Following kit, but I never got into it enough to be able to code something like my question above. Soon enough though I will have the PING))) Ultra Sonic sensor and several other components, but the gold is in the code. So that's what I want to learn the most.

"When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

Before I got involved in a lot of other stuff, I was a member of a robotics club where I was the token Boe-Bot in a bunch of Vexs ( also the token senior in a bunch of elementary school kids and parents) but any robot club in a storm! The club leaders started a maze challenge from a Vex website where the maze squares were rotated 45 degrees and the entry/exit points were at the corners of the squares. Just to make life interesting, none of the squares was perfectly laid out so the angles varied quite a bit. If I hadn't been half bald when I started to code for this maze I would have been when I finished! For some reason, the Vex sensors handled the configuration without a problem given the correct coding, but my Boe-Bot would always seem to stumble after handling the first several intersections OK.

I teach Math and Computer Science, and my students are trying to program our Boe Bot to follow lines for an upcoming competition. They successfully installed 4 QTIs and were able to follow a simple line using the Line Following with Check QTI program. When the kids try to get our Boe Bot to follow more complicated lines, our robot behaves strangely. We set up the program to debug the QTIs and we found that when the robot deviates from the course in a way we didn't anticipate, it is usually the result of the QTIs "seeing" a line that is not actually present. I thought it might have been the material that we are using to prepare for competition, so we made the maze and attempted to follow the directions listed above. For some reason, our QTi's will indicate that a sensor is looking at a line that is not on our white poster board.

To clarify, if the line is directly under the middle two sensors as configured in the pictures for this activity, instead of the QTIs displaying 0110, sometimes they will display 1110 or 0111 when only the two middle sensors are over the line. For some reason, they will sometimes randomly display 1010, or 1001.

Has anybody else ever encountered this problem? I know from my past experience in aviation that some aircraft sensors can be tuned to be more sensitive or less sensitive. Is this something that we can do with QTIs? Any advice would be appreciated.

There are four paragraphs below the code that describe it, then the 5th paragraph explains tuning. A second explanation with some visual aids is in Applied Robotics with the SumoBot, Chapter 3, Activity #4.

The Check_Qtis subroutine charges up capacitors in the QTIs with DIRB = %1111, which connects each QTI to the BASIC Stamp's 5 V supply through I/O pins 7...4. The PAUSE 0 command causes a 230 us delay for the capacitors to charge up to some value in the 5 V neighborhood. Then, DIRB = %0000 sets the I/O pins that were charging the QTIs capacitors to inputs. As inputs, the I/O pins have no effect on the QTI circuits, but can monitor for whether the voltage that each QTI circuit applies to each I/O pin has decayed below 1.3 V (binary-0) or is still above 1.3 V (binary 1). Then, qtis = INB copies the binary values for P7, P6, P5, and P4 from the BASIC Stamp's B input register to the qtis variable.

A white surface reflecting infrared light the QTI emits more intensely makes the phototransistor in a given QTI conduct more current from its capacitor to ground, causing its voltage to decay more rapidly. A black surface reflecting light less causes the phototransistor to conduct less current and drains the capacitor less rapidly.

The trick to tuning the QTIs is setting the delay between changing I/O to input with DIRB = %0000 and checking their values with qtis = INB. That will give all the QTI's more or less time for their capacitor's to draing through the phototransistors. What we are looking for is a sweet spot delay time that allows QTIs over white to discharge below 1.3 V, but not so long that it allows the QTIS over black to also decay below 1.3 V.

I added 'PULSOUT UnusedPin, 0 to to that code to make it tunable. For example, assuming nothing else is connected to P11, you could comment the lower of the two PAUSE 0 by putting an apostrophe to its left. Then, uncomment the PULSOUT command by removing its apostrophe, and make it something like PULSOUT 11, 100. This should change the delay from 230 us to 408 us (208 + 200 * 2 us = 408 us).

I think the best approach would be to first increase PULSOUT duration arguments from 100 up to the point where they are long enough that even the QTIs over black lines report 0. Then, adjust the duration below 100, short enough to make QTIS that are over while surfaces report 1. Finally, set the duration in PULSOUT 11, duration to the half way point between the two values.