Quantcast
Channel: Learn with BlocklyProp — Parallax Forums
Viewing all articles
Browse latest Browse all 293

Boe-Bot Maze Navigation with QTIs

$
0
0
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!


View Video Introduction (YouTube)

Download Source Code – Boe-Bot Maze Navigation

Getting Started

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.

Parts Required

(1) Boe-Bot® Robot, assembled and tested
The parts below are included in the Boe-Bot Robot kit:
····· (1) Piezospeaker
····· (misc)· Jumper wires
(1) QTI Line Follower AppKit
The parts below are included in the QTI Line Follower AppKit:
····· (4) 3-pin Male-Male Headers
····· (4) QTI Sensor Modules
····· (4) 3/8” 4-40 pan-head screws
····· (4) 7/8” 4-40 pan-head screws
····· (4) 1” round standoffs
····· (4) 1/2" round spacers
····· (4) 10” servo cable extenders

Building the Circuits···········

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

attachment.php?attachmentid=59877

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

attachment.php?attachmentid=59878

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.

attachment.php?attachmentid=74107

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.

[color=#008000]' SlowlyForward.bs2[/color]
[color=#008000]' Calibrate your Boe-Bot to slowly move forward in a straight line.[/color]
 
[color=#008000]' {$STAMP BS2}[/color]
[color=#008000]' {$PBASIC 2.5}[/color]
 
[color=#000000]counter   VAR    Word[/color]
 
[color=#020FC0]FOR[/color][color=#000000] counter = 1 [/color][color=#020FC0]TO[/color][color=#000000] 407[/color]
  [color=#020FC0]PULSOUT[/color][color=#000000] 13, 770[/color]
  [color=#020FC0]PULSOUT[/color][color=#000000] 12, 730[/color]
  [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
[color=#020FC0]NEXT[/color]
 
[color=#020FC0]END[/color]


90° Left Turn Calibration

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.

attachment.php?attachmentid=74108
·
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.

[color=#008000]' MazeNavigation_LeftTurn.bs2[/color]
[color=#008000]' Boe-Bot turns left based on values from the QTIs.[/color]
 
[color=#008000]' {$STAMP BS2}[/color]
[color=#008000]' {$PBASIC 2.5}[/color]
 
[color=#000000]qtis            VAR   Nib                 [/color][color=#008000]' qti black/white states[/color]
[color=#000000]pulseCount      VAR   Byte                [/color][color=#008000]' FOR..NEXT loop counter for turning[/color]
 
[color=#800080]OUTB[/color][color=#000000] = %1111                              [/color][color=#008000]' Set OUTB bits to 1[/color]
 
[color=#020FC0]DO[/color]                                        [color=#008000]' Main DO...LOOP[/color]
  [color=#020FC0]GOSUB[/color][color=#000000] Check_Qtis                        [/color][color=#008000]' Get QTI states[/color]
 
  [color=#020FC0]SELECT[/color][color=#000000] qtis                             [/color][color=#008000]' Control servo speeds/directions[/color]
    [color=#020FC0]CASE[/color][color=#000000] %0110                            [/color][color=#008000]' Straight ahead[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 13, 770[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 12, 730[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
    [color=#020FC0]CASE[/color][color=#000000] %1110[/color]
      [color=#020FC0]GOSUB[/color][color=#000000] Turn_Left[/color]
    [color=#020FC0]CASE[/color] [color=#020FC0]ELSE[/color]                             [color=#008000]' Do nothing[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 3[/color]
  [color=#020FC0]ENDSELECT[/color]
[color=#020FC0]LOOP[/color]
 
[color=#000000]Check_Qtis:[/color]
[color=#008000]' Checks the state of each QTI Sensor. 0 means white surface, 1 means black surface.  [/color]
  [color=#800080]DIRB[/color][color=#000000] = %1111                            [/color][color=#008000]'[/color] [color=#008000]P7..P4 -> output[/color]
  [color=#020FC0]PAUSE[/color][color=#000000] 0                                 [/color][color=#008000]' Delay = 230 us[/color]
  [color=#800080]DIRB[/color][color=#000000] = %0000                            [/color][color=#008000]' P7..P4 -> input[/color]
  [color=#020FC0]PAUSE[/color][color=#000000] 0                                 [/color][color=#008000]' Delay = 230 us[/color]
[color=#000000]  qtis = [/color][color=#800080]INB[/color]                              [color=#008000]' Store QTI outputs in INB[/color]
[color=#020FC0]RETURN[/color]
 
[color=#000000]Turn_Left:[/color]
  [color=#020FC0]FOR[/color][color=#000000] pulseCount = 0 [/color][color=#020FC0]TO[/color][color=#000000] 15                [/color][color=#008000]' Go forward a bit so Boe-Bot[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 13, 770                       [/color][color=#008000]' stays on course[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 12, 730[/color]
    [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
  [color=#020FC0]NEXT[/color]
  [color=#020FC0]FOR[/color][color=#000000] pulseCount = 0 [/color][color=#020FC0]TO[/color][color=#000000] 24                [/color][color=#008000]' Turn left, about 90-degrees[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 13, 650[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 12, 650[/color]
    [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
  [color=#020FC0]NEXT[/color]
[color=#020FC0]RETURN[/color]


90° Right Turn Calibration

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.

[color=#008000]' MazeNavigation_LeftTurn.bs2[/color]
[color=#008000]' Boe-Bot turns left based on values from the QTIs.[/color]
 
[color=#008000]' {$STAMP BS2}[/color]
[color=#008000]' {$PBASIC 2.5}[/color]
 
 
[color=#000000]qtis            VAR   Nib                 [/color][color=#008000]' qti black/white states[/color]
[color=#000000]pulseCount      VAR   Byte                [/color][color=#008000]' FOR..NEXT loop counter for turning[/color]
 
[color=#800080]OUTB[/color][color=#000000] = %1111                              [/color][color=#008000]' Set OUTB bits to 1[/color]
 
[color=#020FC0]DO[/color]                                        [color=#008000]' Main DO...LOOP[/color]
  [color=#020FC0]GOSUB[/color][color=#000000] Check_Qtis                        [/color][color=#008000]' Get QTI states[/color]
 
  [color=#020FC0]SELECT[/color][color=#000000] qtis                             [/color][color=#008000]' Control servo speeds/directions[/color]
    [color=#020FC0]CASE[/color][color=#000000] %0110                            [/color][color=#008000]' Straight ahead[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 13, 770[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 12, 730[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
    [color=#020FC0]CASE[/color][color=#000000] %0111[/color]
      [color=#020FC0]GOSUB[/color][color=#000000] Turn_Right[/color]
    [color=#020FC0]CASE[/color] [color=#020FC0]ELSE[/color]                             [color=#008000]' Do nothing[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 3[/color]
  [color=#020FC0]ENDSELECT[/color]
[color=#020FC0]LOOP[/color]
 
[color=#000000]Check_Qtis:[/color]
[color=#008000]' Checks the state of each QTI Sensor. 0 means white surface, 1 means black surface.  [/color]
  [color=#800080]DIRB[/color][color=#000000] = %1111                            [/color][color=#008000]'[/color] [color=#008000]P7..P4 -> output[/color]
  [color=#020FC0]PAUSE[/color][color=#000000] 0                                 [/color][color=#008000]' Delay = 230 us[/color]
  [color=#800080]DIRB[/color][color=#000000] = %0000                            [/color][color=#008000]' P7..P4 -> input[/color]
  [color=#020FC0]PAUSE[/color][color=#000000] 0                                 [/color][color=#008000]' Delay = 230 us[/color]
[color=#000000]  qtis = [/color][color=#800080]INB[/color]                              [color=#008000]' Store QTI outputs in INB[/color]
[color=#020FC0]RETURN[/color]
 
[color=#000000]Turn_Right:[/color]
  [color=#020FC0]FOR[/color][color=#000000] pulseCount = 0 [/color][color=#020FC0]TO[/color][color=#000000] 15                [/color][color=#008000]' Go forward a bit so Boe-Bot[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 13, 770                       [/color][color=#008000]' stays on course[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 12, 730[/color]
    [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
  [color=#020FC0]NEXT[/color]
  [color=#020FC0]FOR[/color][color=#000000] pulseCount = 0 [/color][color=#020FC0]TO[/color][color=#000000] 24                [/color][color=#008000]' Turn right, about 90-degrees[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 13, 850[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 12, 850[/color]
    [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
  [color=#020FC0]NEXT[/color]
[color=#020FC0]RETURN[/color]


T-Intersection Calibration

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.
·

attachment.php?attachmentid=74109

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.

[color=#008000]' MazeNavigation_TIntersection.bs2[/color]
[color=#008000]' When all QTI sensors detect a black line, the Boe-Bot randomly decides to turn[/color]
[color=#008000]' left or right.  This codes simulates the decision by printing "Turn Left!" or[/color]
[color=#008000]' "Turn Right!" to the debug terminal.[/color]
 
[color=#008000]' {$STAMP BS2}[/color]
[color=#008000]' {$PBASIC 2.5}[/color]
 
 
[color=#000000]rng             VAR   Word                [/color][color=#008000]' random number[/color]
[color=#000000]turnDecision    VAR   rng.BIT0            [/color][color=#008000]' Bit0 of the random number[/color]
[color=#000000]qtis            VAR   Nib                 [/color][color=#008000]' qti black/white states[/color]
 
[color=#800080]OUTB[/color][color=#000000] = %1111                              [/color][color=#008000]' Set OUTB bits to 1[/color]
[color=#020FC0]DEBUG[/color] [color=#800080]CLS                                  [/color][color=#008000]' Clear the Debug screen[/color]
 
[color=#020FC0]DO                                        [/color][color=#008000]' Main DO...LOOP[/color]
  [color=#020FC0]GOSUB [/color][color=#000000]Check_Qtis                        [/color][color=#008000]' Get QTI states[/color]
  [color=#020FC0]RANDOM [/color][color=#000000]rng                              [/color][color=#008000]' Create random number[/color]
 
  [color=#020FC0]SELECT [/color][color=#000000]qtis                             [/color][color=#008000]' Control servo speeds/directions[/color]
    [color=#020FC0]CASE [/color][color=#000000]%0110                            [/color][color=#008000]' Straight ahead[/color]
      [color=#020FC0]PULSOUT [/color][color=#000000]13, 770[/color]
      [color=#020FC0]PULSOUT [/color][color=#000000]12, 730[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
    [color=#020FC0]CASE [/color][color=#000000]%1111[/color]
      [color=#020FC0]GOSUB [/color][color=#000000]T_Intersection[/color]
    [color=#020FC0]CASE [/color][color=#000000]ELSE                             [/color][color=#008000]' Do nothing[/color]
      [color=#020FC0]PAUSE [/color][color=#000000]3[/color]
  [color=#020FC0]ENDSELECT[/color]
[color=#020FC0]LOOP[/color]
 
[color=#000000]Check_Qtis:[/color]
[color=#008000]' Checks the state of each QTI Sensor. 0 means white surface, 1 means black surface[/color]
  [color=#800080]DIRB[/color][color=#000000] = %1111                            [/color][color=#008000]' P7..P4 -> output[/color]
  [color=#020FC0]PAUSE [/color][color=#000000]0                                 [/color][color=#008000]' Delay = 230 us[/color]
  [color=#800080]DIRB[/color][color=#000000] = %0000                            [/color][color=#008000]' P7..P4 -> input[/color]
  [color=#020FC0]PAUSE [/color][color=#000000]0                                 [/color][color=#008000]' Delay = 230 us[/color]
[color=#000000]  qtis = [/color][color=#800080]INB[/color]                              [color=#008000]' Store QTI outputs in INB[/color]
[color=#020FC0]RETURN[/color]
 
[color=#000000]T_Intersection:[/color]
  [color=#020FC0]IF [/color][color=#000000](turnDecision = 0) [/color][color=#020FC0]THEN[/color]
    [color=#020FC0]DEBUG [/color][color=#ff0000]"Turn Right!"[/color][color=#000000], [/color][color=#800080]CR[/color]
    [color=#020FC0]PAUSE [/color][color=#000000]100[/color]
  [color=#020FC0]ELSEIF [/color][color=#000000](turnDecision = 1) [/color][color=#020FC0]THEN[/color]
    [color=#020FC0]DEBUG [/color][color=#ff0000]"Turn Left!"[/color][color=#000000], [/color][color=#800080]CR[/color]
    [color=#020FC0]PAUSE [/color][color=#000000]100[/color]
  [color=#020FC0]ENDIF[/color]
[color=#020FC0]RETURN[/color]


Dead End Navigation and “Artificial Intelligence”

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!
[color=#008000]' MazeNavigation_DeadEnd.bs2[/color]
[color=#008000]' Boe-Bot backs up until it notices a turn and then moves forward again.[/color]
 
[color=#008000]' {$STAMP BS2}[/color]
[color=#008000]' {$PBASIC 2.5}[/color]
 
[color=#000000]qtis            VAR   Nib                 [/color][color=#008000]' qti black/white states[/color]
[color=#000000]AI              VAR   Byte                [/color][color=#008000]' "Artificial Intelligence" remembers dead ends[/color]
[color=#000000]pulseCount      VAR   Byte                [/color][color=#008000]' FOR..NEXT loop counter for turning[/color]
 
[color=#800080]OUTB[/color][color=#000000] = %1111                              [/color][color=#008000]' Set OUTB bits to 1[/color]
 
[color=#000000]DO                                        [/color][color=#008000]' Main DO...LOOP[/color]
  [color=#020FC0]GOSUB[/color][color=#000000] Check_Qtis                        [/color][color=#008000]' Get QTI states[/color]
 
  [color=#020FC0]SELECT[/color][color=#000000] qtis                             [/color][color=#008000]' Control servo speeds/directions[/color]
    [color=#020FC0]CASE[/color][color=#000000] %0110                            [/color][color=#008000]' Straight ahead[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 13, 770[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 12, 730[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
    [color=#020FC0]CASE[/color][color=#000000] %1110[/color]
      [color=#020FC0]GOSUB[/color][color=#000000] AI_Decision[/color]
    [color=#020FC0]CASE[/color][color=#000000] %0000                            [/color][color=#008000]' Back-up until it sees another turn[/color]
      [color=#020FC0]GOSUB[/color][color=#000000] Dead_End[/color]
    [color=#020FC0]CASE[/color] [color=#020FC0]ELSE[/color]                             [color=#008000]' Do nothing[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 3[/color]
  [color=#020FC0]ENDSELECT[/color]
[color=#020FC0]LOOP[/color]
 
[color=#000000]Check_Qtis:[/color]
[color=#008000]' Checks the state of each QTI Sensor. 0 means white surface, 1 means black surface[/color]
  [color=#800080]DIRB[/color][color=#000000] = %1111                            [/color][color=#008000]' P7..P4 -> output[/color]
  [color=#020FC0]PAUSE[/color][color=#000000] 0                                 [/color][color=#008000]' Delay = 230 us[/color]
  [color=#800080]DIRB[/color][color=#000000] = %0000                            [/color][color=#008000]' P7..P4 -> input[/color]
  [color=#020FC0]PAUSE[/color][color=#000000] 0                                 [/color][color=#008000]' Delay = 230 us[/color]
[color=#000000]  qtis = [/color][color=#800080]INB[/color]                              [color=#008000]' Store QTI outputs in INB[/color]
[color=#020FC0]RETURN[/color]
 
[color=#000000]AI_Decision:[/color]
  [color=#020FC0]IF[/color][color=#000000] (AI = 1) [/color][color=#020FC0]THEN[/color]                        [color=#008000]' If the AI variable is 1, Boe-Bot was in dead end[/color]
    [color=#020FC0]AI[/color][color=#000000] = 0                                [/color][color=#008000]' Set AI variable to 0[/color]
    [color=#020FC0]GOSUB[/color][color=#000000] Ignore_Turn                     [/color][color=#008000]' Ignore the turn that leads to Start[/color]
  [color=#020FC0]ELSEIF[/color][color=#000000] (AI = 0) THEN                    [/color][color=#008000]' If the AI variable is 0, Boe-Bot was not in[/color]
    [color=#020FC0]GOSUB[/color][color=#000000] Turn_Left                       [/color][color=#008000]' dead end, so it's OK to turn left.[/color]
  [color=#020FC0]ENDIF[/color]
[color=#020FC0]RETURN[/color]
 
[color=#000000]Ignore_Turn:[/color]
  [color=#020FC0]FOR[/color][color=#000000] pulseCount = 0 [/color][color=#020FC0]TO[/color][color=#000000] 50[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 13, 770[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 12, 730[/color]
    [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
  [color=#020FC0]NEXT[/color]
[color=#020FC0]RETURN[/color]
 
[color=#000000]Turn_Left:[/color]
  [color=#020FC0]FOR[/color][color=#000000] pulseCount = 0 [/color][color=#020FC0]TO[/color][color=#000000] 15                [/color][color=#008000]' Go forward a bit so Boe-Bot stays on course.[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 13, 770[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 12, 730[/color]
    [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
  [color=#020FC0]NEXT[/color]
  [color=#020FC0]FOR[/color][color=#000000] pulseCount = 0 [/color][color=#020FC0]TO[/color][color=#000000] 17                [/color][color=#008000]' Turn left, about 90-degrees[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 13, 650[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 12, 650[/color]
    [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
  [color=#020FC0]NEXT[/color]
[color=#020FC0]RETURN[/color]
 
[color=#000000]Dead_End:[/color]
  [color=#020FC0]DO[/color]
    [color=#020FC0]GOSUB[/color][color=#000000] Check_Qtis[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 13, 730[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 12, 770[/color]
    [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
  [color=#020FC0]LOOP[/color] [color=#020FC0]UNTIL[/color][color=#000000] (qtis = %0111)[/color]
 
  [color=#020FC0]IF[/color][color=#000000] (qtis = %0111) [/color][color=#020FC0]THEN[/color]
    [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
    [color=#020FC0]FOR[/color][color=#000000] pulseCount = 0 [/color][color=#020FC0]TO[/color][color=#000000] 15[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 13, 770[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 12, 730[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
    [color=#020FC0]NEXT[/color]
    [color=#020FC0]FOR[/color][color=#000000] pulseCount = 0 [/color][color=#020FC0]TO[/color][color=#000000] 17[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 13, 850[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 12, 850[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
    [color=#020FC0]NEXT[/color]
  [color=#020FC0]ENDIF[/color]
[color=#000000]  AI = 1[/color]
[color=#020FC0]RETURN[/color]


Keep the Boe-Bot on Track!

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


[color=#008000]' MazeNavigation_StayOnStripe.bs2[/color]
[color=#008000]' Calibration program to keep the Boe-Bot on the electrical tape path.[/color]
 
[color=#008000]' {$STAMP BS2}[/color]
[color=#008000]' {$PBASIC 2.5}[/color]
 
[color=#000000]qtis          VAR     Nib                 [/color][color=#008000]' qti black/white states[/color]
[color=#000000]pulseCount    VAR     Word                [/color][color=#008000]' FOR...NEXT loop counter for smooth turning[/color]
 
[color=#800080]OUTB[/color][color=#000000] = %1111                              [/color][color=#008000]' Set OUTB bits to 1[/color]
 
[color=#020FC0]DO[/color]                                        [color=#008000]' Main DO...LOOP[/color]
  [color=#020FC0]GOSUB[/color][color=#000000] Check_Qtis                        [/color][color=#008000]' Get QTI states[/color]
 
  [color=#020FC0]SELECT[/color][color=#000000] qtis                             [/color][color=#008000]'[/color] [color=#008000]Control servo speeds/directions[/color]
    [color=#020FC0]CASE[/color][color=#000000] %0110                            [/color][color=#008000]'[/color] [color=#008000]Mid Left and Right sensors detected, go forward[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 13, 770[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 12, 730[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
    [color=#020FC0]CASE[/color][color=#000000] %1000                            [/color][color=#008000]' Far Left sensor detected[/color]
      [color=#020FC0]GOSUB[/color][color=#000000] BackOnTrack_OneSensorLeft[/color]
    [color=#020FC0]CASE[/color][color=#000000] %1100                            [/color][color=#008000]' Far and Mid Left sensors detected[/color]
      [color=#020FC0]GOSUB[/color][color=#000000] BackOnTrack_TwoSensorsLeft[/color]
    [color=#020FC0]CASE[/color][color=#000000] %0001                            [/color][color=#008000]' Far Right sensor detected[/color]
      [color=#020FC0]GOSUB[/color][color=#000000] BackOnTrack_OneSensorRight[/color]
    [color=#020FC0]CASE[/color][color=#000000] %0011                            [/color][color=#008000]' Far and Mid Right sensor detected[/color]
      [color=#020FC0]GOSUB[/color][color=#000000] BackOnTrack_TwoSensorsRight[/color]
    [color=#020FC0]CASE[/color] [color=#020FC0]ELSE[/color]                             [color=#008000]' Do nothing[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 3[/color]
  [color=#020FC0]ENDSELECT[/color]
[color=#020FC0]LOOP[/color]
 
[color=#000000]Check_Qtis:[/color]
[color=#008000]' Checks the state of each QTI Sensor. 0 means white surface, 1 means black surface.  [/color]   
  [color=#800080]DIRB[/color][color=#000000] = %1111                            [/color][color=#008000]'[/color] [color=#008000]P7..P4 -> output[/color]
  [color=#020FC0]PAUSE[/color][color=#000000] 0                                 [/color][color=#008000]' Delay = 230 us[/color]
  [color=#800080]DIRB[/color][color=#000000] = %0000                            [/color][color=#008000]' P7..P4 -> input[/color]
  [color=#020FC0]PAUSE[/color][color=#000000] 0                                 [/color][color=#008000]' Delay = 230 us[/color]
[color=#000000]  qtis = [/color][color=#800080]INB[/color]                              [color=#008000]' Store QTI outputs in INB[/color]
[color=#020FC0]RETURN[/color]
 
[color=#000000]BackOnTrack_OneSensorLeft:[/color]
  [color=#020FC0]PULSOUT[/color][color=#000000] 13, 750                         [/color][color=#008000]' Stop[/color]
  [color=#020FC0]PULSOUT[/color][color=#000000] 12, 750[/color]
  [color=#020FC0]DO[/color]                                      [color=#008000]' Slowly rotate until the middle[/color]
    [color=#020FC0]GOSUB[/color][color=#000000] Check_Qtis                      [/color][color=#008000]' QTIs are back on the line[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 13, 750[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 12, 740[/color]
    [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
  [color=#020FC0]LOOP[/color] [color=#020FC0]UNTIL[/color][color=#000000] (qtis = %0110)[/color]
 
  [color=#020FC0]IF[/color][color=#000000] (qtis = %0110) [/color][color=#020FC0]THEN[/color]                  [color=#008000]' When the middle QTIs are back[/color]
    [color=#020FC0]FOR[/color][color=#000000] pulseCount = 1 [/color][color=#020FC0]TO[/color][color=#000000] 20              [/color][color=#008000]' on the line, rotate left for[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 13, 750                     [/color][color=#008000]' 20 pulses and then rotate right[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 12, 740                     [/color][color=#008000]' for 10 pulses to center the Boe-[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20                            [/color][color=#008000]' Bot on the line.[/color]
    [color=#020FC0]NEXT[/color]
    [color=#020FC0]FOR[/color][color=#000000] pulseCount = 0 [/color][color=#020FC0]TO[/color][color=#000000] 10[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 13, 770[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 12, 750[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
    [color=#020FC0]NEXT[/color]
  [color=#020FC0]ENDIF[/color]
[color=#020FC0]RETURN[/color]
 
[color=#000000]BackOnTrack_TwoSensorsLeft:[/color]
  [color=#020FC0]PULSOUT[/color][color=#000000] 13, 750                         [/color][color=#008000]' Stop[/color]
  [color=#020FC0]PULSOUT[/color][color=#000000] 12, 750[/color]
  [color=#020FC0]DO[/color]
    [color=#020FC0]GOSUB[/color][color=#000000] Check_Qtis                      [/color][color=#008000]' Slowly rotate until the middle[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 13, 750                       [/color][color=#008000]' QTIs are back on the line[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 12, 740[/color]
    [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
  [color=#020FC0]LOOP[/color] [color=#020FC0]UNTIL[/color][color=#000000] (qtis = %0110)[/color]
 
  [color=#020FC0]IF[/color][color=#000000] (qtis = %0110) [/color][color=#020FC0]THEN[/color]                  [color=#008000]' When the middle QTIs are back[/color]
    [color=#020FC0]FOR[/color][color=#000000] pulseCount = 1 [/color][color=#020FC0]TO[/color][color=#000000] 20              [/color][color=#008000]' on the line, rotate left for[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 13, 750                     [/color][color=#008000]' 20 pulses and then rotate right[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 12, 730                     [/color][color=#008000]' for 10 pulses to center the Boe-[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20                            [/color][color=#008000]' Bot on the line.[/color]
    [color=#020FC0]NEXT[/color]
    [color=#020FC0]FOR[/color][color=#000000] pulseCount = 0 [/color][color=#020FC0]TO[/color][color=#000000] 10[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 13, 770[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 12, 750[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
    [color=#020FC0]NEXT[/color]
  [color=#020FC0]ENDIF[/color]
[color=#020FC0]RETURN[/color]
 
[color=#000000]BackOnTrack_OneSensorRight:[/color]
  [color=#020FC0]PULSOUT[/color][color=#000000] 13, 750                         [/color][color=#008000]' Stop[/color]
  [color=#020FC0]PULSOUT[/color][color=#000000] 12, 750[/color]
  [color=#020FC0]DO[/color]
    [color=#020FC0]GOSUB[/color][color=#000000] Check_Qtis                      [/color][color=#008000]' Slowly rotate until the middle[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 13, 760                       [/color][color=#008000]' QTIs are back on the line[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 12, 750[/color]
    [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
  [color=#020FC0]LOOP[/color] [color=#020FC0]UNTIL[/color][color=#000000] (qtis = %0110)[/color]
 
  [color=#020FC0]IF[/color][color=#000000] (qtis = %0110) [/color][color=#020FC0]THEN[/color]                  [color=#008000]' When the middle QTIs are back[/color]
    [color=#020FC0]FOR[/color][color=#000000] pulseCount = 1 [/color][color=#020FC0]TO[/color][color=#000000] 20              [/color][color=#008000]' on the line, rotate right for[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 13, 760                     [/color][color=#008000]' 20 pulses and then rotate left[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 12, 750                     [/color][color=#008000]' for 10 pulses to center the Boe-[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20                            [/color][color=#008000]' Bot on the line.[/color]
    [color=#020FC0]NEXT[/color]
    [color=#020FC0]FOR[/color][color=#000000] pulseCount = 0 TO 10[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 13, 750[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 12, 730[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
    [color=#020FC0]NEXT[/color]
  [color=#020FC0]ENDIF[/color]
[color=#020FC0]RETURN[/color]
 
[color=#000000]BackOnTrack_TwoSensorsRight:[/color]
  [color=#020FC0]PULSOUT[/color][color=#000000] 13, 750                         [/color][color=#008000]' Stop[/color]
  [color=#020FC0]PULSOUT[/color][color=#000000] 12, 750[/color]
  [color=#020FC0]DO[/color]
    [color=#020FC0]GOSUB[/color][color=#000000] Check_Qtis                      [/color][color=#008000]' Slowly rotate until the middle[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 13, 760                       [/color][color=#008000]' QTIs are back on the line[/color]
    [color=#020FC0]PULSOUT[/color][color=#000000] 12, 750[/color]
    [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
  [color=#020FC0]LOOP[/color] [color=#020FC0]UNTIL[/color][color=#000000] (qtis = %0110)[/color]
 
  [color=#020FC0]IF[/color][color=#000000] (qtis = %0110) [/color][color=#020FC0]THEN[/color]                  [color=#008000]' When the middle QTIs are back[/color]
    [color=#020FC0]FOR[/color][color=#000000] pulseCount = 1 [/color][color=#020FC0]TO[/color][color=#000000] 20              [/color][color=#008000]' on the line, rotate right for[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 13, 770                     [/color][color=#008000]' 20 pulses and then rotate left[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 12, 750                     [/color][color=#008000]' for 10 pulses to center the Boe-[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20                            [/color][color=#008000]' Bot on the line.[/color]
    [color=#020FC0]NEXT[/color]
    [color=#020FC0]FOR[/color][color=#000000] pulseCount = 0 [/color][color=#020FC0]TO[/color][color=#000000] 10[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 13, 750[/color]
      [color=#020FC0]PULSOUT[/color][color=#000000] 12, 730[/color]
      [color=#020FC0]PAUSE[/color][color=#000000] 20[/color]
    [color=#020FC0]NEXT[/color]
  [color=#020FC0]ENDIF[/color]
[color=#020FC0]RETURN[/color]


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jessica Uelmen
Education Department
Parallax Inc.

Post Edited (Jessica Uelmen (Parallax)) : 8/25/2010 6:24:04 PM GMT

Viewing all articles
Browse latest Browse all 293

Trending Articles