How to - Boe-Bot Line Following with 4 QTI Sensors

edited 2006-06-29 - 02:35:00 in Learn with BlocklyProp
How to -·Boe-Bot Line Following·with 4 QTI Sensors

The number of times per second the BASIC Stamp checks the QTI sensors is an important consideration for line following.· If a given PBASIC program doesn't take enough samples per second, it means it's waiting too long between samples, which can cause the Boe-Bot to miss a sudden change in the line's direction, or even lose the line altogether.· On the other hand, if the program devotes itself entirely to checking the line, there might not be enough time for the BASIC Stamp to check other sensors.· By studying the relationship between sampling rate and line following performance, you can determine the minimum sampling rate necessary to navigate a course with a certain set of features.· You can then use whatever time is left to check other sensors.

The rate at which a microcontroller checks a sensor is commonly referred to as sampling rate, and it's typically expressed as a number of samples per second.· The sample interval is the amount of time between each sample, which is expressed in terms of seconds.· In cases where the sample interval doesn't change, it's called a constant sample interval.· When the sample interval is constant, the sampling rate is just the reciprocal of the sample interval, and visa versa.·

······· attachment.php?attachmentid=42276

attachment.php?attachmentid=73984

There are quite a number of adjustments that can be made to existing QTI example programs to make them more efficient and improve their sampling rates.· One of the most important changes involves reducing the amount of time it takes to check the QTIs.· This activity introduces a subroutine for reading multiple QTIs that takes very little time and is especially reliable for detecting black vinyl electrical tape on a white background (see Figure 1).· This activity also features a line following example program that uses a subroutine to follow a line with four QTIs.

Figure 1 – Fully Assembled Boe-Bot and QTI Line Follower AppKit
·
attachment.php?attachmentid=59651


Getting Started

This project contains advanced topics, not intended for Boe-Bot beginners.· Before continuing, it is highly recommended you complete the following tasks in order to gain a better understanding on how this application works:

······· Complete all activities in Robotics with the Boe-Bot
······· Download the documentation for the QTI Line Follower AppKit and follow all instructions listed

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) Nylon washers
····· (4) 10” servo cable extenders
····· (misc) Jumper wires

For this activity, you will also need to supply your own:
Ÿ······· #2 Philips-head screwdriver
Ÿ······· Black ¾-inch electrical tape
Ÿ······· White poster board

A Closer Look at the QTI

The QTI module is designed for close proximity infrared (IR) detection.· Take a look at the small square black box just above the QTI label.· It’s nested below the capacitor and between the two resistors.· That’s a QRD1114 reflective object sensor.· There’s an infrared diode behind its clear window and an infrared transistor behind its black window.· When the infrared emitted by the diode reflects off a surface and returns to the black window, it strikes the infrared transistor’s base, causing it to conduct current.· The more infrared incident on the transistor’s base, the more current it conducts.

When used as an analog sensor, the QTI can detect shades of gray on paper and distances over a short range if the light in the room remains constant.· With this circuit, you can set P3 high and then test it with RCTIME to measure how long it takes the capacitor to discharge through the IR transistor.· Since the IR transistor conducts more or less current depending on how much IR it receives, the RCTIME measurement can give you an indication of distance or shade of gray.···

If all you want to know is whether a line is black or white, the QTI can also be converted to a digital sensor. This is how the array of four QTI sensors will be used later in our Boe-Bot line-following application.

When W is connected to Vdd and B is connected to Vss, the R terminal’s voltage will drop below 1.4 V when the IR transistor sees infrared reflected from the IR LED.· When the IR LED’s signal is mostly absorbed by a black surface, the voltage at R goes above 1.4 V.· Since the BASIC Stamp interprets any voltage above 1.4 V as 1 and any voltage below 1.4·V as 0, this circuit shown in Figure 2 gives us a quick and easy way to detect a black line on a white background.

Figure 2 – QTI Circuit
attachment.php?attachmentid=59652

Mounting the QTIs

1.······ Match the components in your kit to the Kit Contents above to make sure all pieces are present.· If anything is missing, contact Parallax Tech Support.
2.······ Referring to Figure 2, insert the 7/8-inch screws through the top of the Boe-Bot chassis, at the three slots near the front. Two screws will go through the center slot, and one screw each in the right and left slots.
3.······ On the underside of the chassis, slip a 1/2-inch unthreaded spacer on each screw, followed by a 1-inch threaded standoff.·
4.······ Attach a QTI sensor to the other end of each threaded standoff, using a 3/8-inch screw. The sensors should be facing downwards, and the 3-pin headers on each sensor should be pointing towards the back of the chassis.
5.······ If necessary, slightly loosen the 7/8-inch screws and adjust the position of the QTI sensors so that they are closely positioned edge to edge.
6.······ Tighten all connections securely.

Figure 3 – QTI Mechanical Assembly
attachment.php?attachmentid=59653

QTI Line Follower Circuit

Figure 4 shows the schematic for four QTIs along with a partially completed wiring diagram. Although there are many ways this circuit can be built, the setup shown below is useful because it's thrifty with breadboard real-estate.

Figure 4 - QTI Circuit and Wiring Diagram Part 1
attachment.php?attachmentid=59654
Figure 5 shows how to connect the servo extension cables to the male-male headers that were plugged into the breadboard in Figure 4. The other end of each cable is plugged into a QTI. Be careful when you make these connections, and pay close attention to the wire colors listed in the figure. Notice that the far left and mid left cables have white wires that plug onto header pins in the same breadboard row. The same applies to the mid right and far right QTI cables. Instead of common white wires, the mid left and mid right QTI cables share a pair of black wires.

Figure 5 – QTI Circuit and Wiring Diagram Part 2
attachment.php?attachmentid=59655


Testing the QTI Detection Subroutine

It's a good idea to test all the sensors with the Debug Terminal before taking the Boe-Bot for a spin on the line following course. ·The next example program (CheckQtiSubroutine.bs2) has a Debug Terminal display you can use to make sure the QTIs are properly discerning the difference between black vinyl electrical tape and white paper. Figure 6 shows what you'd want to see in the Debug Terminal display when the middle-right and far-right QTIs are over black electrical tape, and the other two are over white paper.

Figure 6 – QTI Debug Terminal Test Display
attachment.php?attachmentid=59656


Example Program: CheckQtiSubroutine.bs2

······· Affix two 3/4-inch wide pieces of electrical tape to a white sheet of paper, each a few inches long and spaced 3/4-inches apart.
······· Use the BASIC Stamp Editor to open and run CheckQtiSubroutine.bs2.
······· Place each QTI over the electrical tape and then over the white paper and verify that it detects the difference, 0 for white and 1 for black.
······· Verify that the QTIs are connected in the right order and that they are close enough together. As you slide the Boe-Bot slowly across the electrical tape stripe, from right to left, verify that this sequence appears in the Debug Terminal: %0000, %1000, %1100, %0100, %0110, %0010, %0011, %0001, %0000.
······· Also try placing all the QTIs over the electrical tape. The qtis variable should display %1111.

attachment.php?attachmentid=73985

[color=#008000]' {$STAMP BS2}[/color]
[color=#008000]' {$PBASIC 2.5}[/color]
 
[color=#008000]' CheckQtiSubroutine.bs2[/color]
[color=#008000]' Displays QTI sensor states. 0 means white surface, 1 means black.[/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=#0000ff]DEBUG [/color][color=#800080]CRSRX[/color][color=#000000], 8,[/color] [color=#ff0000]"FMMF"[/color][color=#000000],[/color] [color=#800080]CR[/color][color=#008000],   ' Display bit positions[/color]
      [color=#800080]CRSRX[/color][color=#000000], 8,[/color] [color=#ff0000]"LLRR"[/color][color=#000000],[/color] [color=#800080]CR[/color]
 
[color=#0000ff]DO[/color][color=#008000]                            ' Main DO...LOOP[/color]
  [color=#0000ff]GOSUB[/color] [color=#000000]Check_Qtis            [/color][color=#008000]' Get QTI states[/color]
  [color=#0000ff]DEBUG[/color] [color=#000000]BIN4 ? qtis, [/color][color=#800080]CRSRUP[/color][color=#008000]   ' Display QTI states[/color]
  [color=#0000ff]PAUSE [/color][color=#000000]100[/color][color=#008000]                   ' 1/10 s delay[/color]
[color=#0000ff]LOOP[/color]
 
[color=#000000]Check_Qtis:[/color]
[color=#008000]' Result -> qtis variable. 0 means white surface, 1 means black[/color]
[color=#008000]' surface.[/color]
 
  [color=#800080]DIRB[/color] [color=#000000]= %1111                  [/color][color=#008000]' P7..P4 -> output[/color]
  [color=#0000ff]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=#0000ff]PAUSE[/color] [color=#000000]0[/color][color=#008000] ' Delay = 230 us[/color]
[color=#008000]  ' PULSOUT UnusedPin, 0        ' Delays = 208 + (Duration*2) us[/color]
[color=#008000]  qtis = [/color][color=#800080]INB[/color][color=#008000] ' Store QTI outputs in INB[/color]
 
  [color=#0000ff]RETURN[/color]



If you had problems with two QTIs sensing 1 when only one of them should have, try adjusting the standoffs so that the QTIs are further apart. Not so far that you can get 0000 when the line is between two QTIs though!· On the other hand, if only one QTI sensed 1 when the stripe was between two of them, they may need to be positioned closer together. Otherwise, your Boe-Bot is ready for line following.

How CheckQtiSubroutine.bs2 Works

The BASIC Stamp has a variety of parallel I/O control features that make it possible to perform operations on groups of I/O pins. CheckQtiSubroutine.bs2 uses the BASIC Stamp's DIRB and OUTB variables to control the directions and output states of the I/O pins P7, P6, P5, and P4. When these I/O pins are set to input with DIRB = %0000, the program also takes a snapshot of the binary states these I/O pins sense as a result of the four QTIs' R pin voltages with the command qtis = INB. Before going into detail about how these variables are used in the Check_Qtis subroutine to simultaneously check the four QTIs, let's take a closer look at how the BASIC Stamp's Parallel I/O control variables work..

BASIC Stamp Parallel I/O Control

In addition to the 13 words of variable RAM, the BASIC Stamp has three extra words of memory for controlling the directions of the I/O pins, setting their output states and reading their input states. These word variables don't have to be declared as variables because they already have the following PBASIC keyword names:

········· DIRS – Controls I/O pin directions
········· OUTS – Controls I/O pin directions
········· INS – Monitors I/O pin states

Since each word variable has 16 bits, the DIRS, OUTS, and INS variables conveniently have one bit apiece for each of the BASIC Stamp's 16 I/O pins. Each bit either stores a 1 or a 0, which in turn relates to some I/O pin characteristic, be it I/O pin direction, high/low output state, or sensed input state.

Figure 7(a) shows how each bit in the DIRS, OUTS, and INS variables maps to the BASIC Stamp's I/O pins. Bit-0 of each variable either controls or senses P0. Bit-1 of each variable controls/senses P1, and so on, all the way up to bit-15, which controls/senses P15. Figure 7(b) shows some example commands that can be used to control as well as read all 16 I/O pins with single commands that write values to and read values from DIRS, OUTS, and INS. Figure 7(c) shows how each variable's bits can be individually accessed with bit variables DIR0 through DIR15, OUT0 through OUT15 and IN0 through IN15. Each of these bit variable names are also PBASIC keywords. PBASIC even has variables with keywords for parallel byte and nibble operations, shown in Figure 7(d). Notice that the DIRB, OUTB, and INB nibble variables used in CheckQtiSubroutine.bs2 map to the BASIC Stamp I/O pins that are connected to the QTIs' R pins.

Figure 7 - Parallel I/O Control Variables
attachment.php?attachmentid=59657

Notice in Figure 7(a) how each I/O pin has one bit in the DIRS, OUTS, and INS variables. Collectively, the three bits define the I/O pin's direction, output state (when it's an output) and sense the signal the I/O pin is either sending or receiving. For example, bit-3 of the DIRS variable (DIRS.BIT3 or DIR3) sets the direction of I/O pin P3 to output if it is 1, or input if it is 0. If the direction of P3 is output, bit-3 in the OUTS variable (OUTS.BIT3 or OUT3) makes the I/O pin send a high signal if it's 1 or a low signal if it's 0. If P3 is set to output, bit-3 of the INS variable will store whatever is in bit-3 of the OUTS variable. If P3 is set to input, it will store a 0 if the voltage at P3 is below 1.4 V, or a 1 if the input signal is at or above 1.4 V.

attachment.php?attachmentid=73986

Here is an example of two commands that define a variety of settings, simultaneously, on all sixteen I/O pins with just two commands:

OUTS = %1010101010101010

DIRS = %0000000011111111
OUTS = %1010101010101010 sets and clears alternate bits in the OUTS variable. The leftmost bit is 1, which means P15 will send a high signal, so long as bit15 in the DIRS variable is 1 (output). The second bit from the far left in the OUTS variable controls the P14 output state, and it's 0, which will make P14 send a low signal. This pattern repeats itself down through bit-0, the rightmost bit, which controls P0.

After setting and clearing alternate bits in the OUTS variable, the command DIRS = %0000000011111111 sets P15 through P8 to input, so they just listen for signals, and won't pay any attention to the OUTS variable. However, the command also sets the bits for P7 through P0 in the DIRS variable to 1s, making them outputs. Since the OUTS variable has alternating 1s and 0s, P7 will send a high (5 V) signal, and P6 will send a low (0 V) signal. P5 also sends a high signal, and so on through P0, which sends a low.

Here, also is an example of using the INS variable to take a snapshot of all the BASIC Stamp's I/O pins with just two commands:

DIRS = %0000000000000000

variable = INS
The command DIRS = %0000000000000000, sets all the I/O pins to input. Then, variable = INS takes all the input states sensed by the I/O pins at the instant the command is executed and copies them to variable. Let's say you didn't use the command DIRS = %0000000000000000 before variable = INS.

If DIRS is still %0000000011111111 from the parallel output example, the I/O pins will behave differently. Since bits 15 through 8 in the DIRS variable are all 0, bits 15 through 8 in the INS variable will still store whatever input states the P15 through P8 I/O pins sense. Again, those states depend on the voltages of the devices or circuits connected to those I/O pins. On the other hand, bits 7 through 0 in the DIRS variable are all 1s, so those I/O pins are outputs. As a result, bits 7 through 0 in the INS variable will instead store whatever they sense the I/0 pins are transmitting - 1 if it's high (5 V), or 0 if it's low (0 V). Let's say again that the values in the OUTS variable are also from the previous example; that's OUTS = %1010101010101010. Because of this, bits 7 through 0 in the INS variable will store %10101010.


attachment.php?attachmentid=73987

You can also access the I/O direction, output and input variables as bytes, nibbles or even bits. The byte variable keyword names end in H for P15 through P8 and L for P7 through P0. So, there's DIRH, OUTH, and INH, and there's also DIRL, OUTL, and INL. There are also A, B, C and D I/O nibbles. A is P3 through P0, B is P7 through P4, C is P11 through P8, and D is P15 through P12. So, OUTB = %1101 sets up P7, P6, and P4 to send high signals and P5 to send a low signal. DIRB = %1111 changes all the I/O pins to outputs so that the high/low signals can be sent. Each I/O variable is also bit addressable. For example, DIR15, OUT15 control the direction and output state of P15 while IN15 reads its input. The same applies to for P14 and DIR14, OUT14, and IN14, and so on...

attachment.php?attachmentid=73988


Parallel I/O Control for Monitoring Four QTIs

Going back to Figure 7(d), the QTIs are connected to P7 through P4, so the parallel I/O operations are performed using DIRB, OUTB, and INB. In the example program, DIRB sets the direction of those four I/O pins, OUTB sets the output states, and INB reads inputs.

At the beginning of the program, the command OUTB = %1111 sets the bits for P7, P6, P5, and P4 so that the I/O pins will all send high signals. Since the BASIC Stamp initializes all I/O pins to input, this command will not have any effect until the corresponding bits in the DIRB variable are set to 1, which happens later in the program.· The I/O pins remain inputs, but they are now all ready to send high signals when the
DIRB variable bits are set to %1111.

In the Check_Qtis subroutine, P7 through P4 have to be set high to discharge all the QTIs' capacitors. Since the lower plate of each capacitor is connected to the R pin as shown in Figure 8, the voltage at the each R pin rises as each QTI's capacitor discharges. The command that sets P7 through P4 to output is DIRB = %1111, and since all the OUTB bits were set to 1 at the beginning of the program, all the I/O pins send high signals. After all the I/O pins change to output-high, which causes the BASIC Stamp I/O pins to short the QTI's R pin to the BASIC Stamp's 5 V supply, a brief delay is necessary to let the QTI capacitors discharge. PAUSE 0 inserts a 0.23 ms delay into the BASIC Stamp 2 program to give the QTIs' capacitors enough time to fully discharge.

Figure 8 – QTI Schematic
attachment.php?attachmentid=59658
After DIRB = %1111 and PAUSE 0, the QTIs' capacitors are all just about fully discharged, and the voltage at each R pin is very close to 5 V. The next step is to set all the I/O pins to input and wait for another 0.23 ms with the commands DIRB = %0000 and PAUSE 0. When all the I/O pins that were output high get changed to input, the QTIs' capacitors start to charge. How quickly they charge is governed by how much infrared the QRD1114's infrared transistor receives. The QTI should be between 1/16 and 3/16 of an inch from a surface. So, the IR light the QRD1114's IR transistor receives should come from the QRD1114's IR emitting diode as it reflects off the surface.

Since white surfaces reflect infrared, more of it gets back to the QRD1114's IR transistor's base, which causes the IR transistor to conduct more current. When the IR transistor conducts more current, the capacitor can charge quickly, which in turn causes the R pin's voltage to drop below 1.4 V during the 0.23 ms delay caused by the Check_Qtis subroutine's second PAUSE 0 command. If the QTI is over a black surface, very little IR will get back to the transistor's base, which means it won't conduct much current. In that case, the capacitor charges slowly in comparison, and the voltage at the R pin doesn't make it to 1.4 V during the 230 μs pause. With all this in mind, the program has to record what the P7 through P4 input bits store after the second PAUSE 0 with the command qtis = INB. After this command, each bit in the qtis variable will be 1 if the R pin's voltage didn't make it to 1.4 V, or 0 if the voltage did drop below 1.4 V.

attachment.php?attachmentid=73989

Let's say the qtis variable stores %0011 after the qtis = INB command. It will cause the Debug Terminal display to look like Figure 2-4 on page 16. In this situation, the two QTIs on the Boe-Bot's right are over black electrical tape, and the two on the left are over white paper. The leftmost 0 indicates the R pin connected to P7 decayed below the BASIC Stamp's 1.4 V logic threshold during the pause, as did the R pin connected to P6. Those QTIs must be over white paper since their R pin voltages decayed quickly. The qtis variable's P5 and P4 bits are both 1s, indicating that those two QTIs' R pins decayed so slowly that they didn't make it past the 1.4 V threshold before the qtis = INB snapshot. So, those QTIS must be over the black electrical tape.
attachment.php?attachmentid=73990

Line Following with 4 QTIs

LineFollowWithCheckQtis.bs2 checks the QTIs and updates the servos every 9 ms.· Remember that for a constant interval, the QTI sampling rate is the reciprocal of the sample interval. Since the sample interval is 9 ms, which is 0.009 or 9 x 10-3, the sampling rate is:

····· attachment.php?attachmentid=42281

111 samples per second is actually more than enough for Boe-Bot line following. The servos could even go faster with higher battery voltage, and the Boe-Bot should continue following the line with ease. One thing to keep in mind is that each PBASIC command takes a fraction of a millisecond. So, to keep the sampling interval short, don't go overboard with long routines that make lots of decisions. Even more caution should be exercised when checking other sensors in addition to the QTIs each time through the main loop. If you're not careful, the sample interval can end up in the 40 ms neighborhood. The resulting sampling rate would be 25 Hz, which will probably be too low, which can lead to a variety of line tracking problems.

Reading other sensors doesn't necessarily have to delay the program that long. There are lots of techniques you can use to reduce sensor reading times, and their impact on the program's sampling rate. For example, you can use smaller capacitors for sensors other than QTIs that rely on RC decay. Also, instead of checking five additional sensors along with the QTIs between each servo pulse, your program can check one sensor along with the QTIs between each servo pulse. After five servo pulses, all five sensors will have been checked.

The next example program, LineFollowWithCheckQtis.bs2 does not check any other sensors. However, the Your Turn section following the program demonstrates how you can test various parts of a line following course to figure out how room there is for sensor measurements in the sample interval.

Example Program: LineFollowWithCheckQtis.bs2

Keep in mind that this is a bare-bones line following example. Making it robust and versatile is up to you. The Boe-Bot starts maneuvers when it sees one of the cases listed in the SELECT...CASE statement. This is convenient for a simple demonstration program because the Boe-Bot doesn't go anywhere when it is on an all white or all black surface.· It only starts navigation when it detects a line.

A sample course is shown in Figure 9.· You can add extra code, especially in the form of CASE statements to deal with special situations and more complex courses. The impact of the extra code on the sampling rate is usually pretty small.
[color=#008000]' {$STAMP BS2}[/color]
[color=#008000]' {$PBASIC 2.5}[/color]
 
[color=#008000]' LineFollowWithCheckQtis.bs2[/color]
[color=#008000]' Navigates based on values acquired with the Check_Qtis subroutine.[/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=#0000ff]DO[/color][color=#008000]                                   ' Main DO...LOOP[/color]
  [color=#0000ff]GOSUB[/color] [color=#000000]Check_Qtis[/color][color=#008000]                   ' Get QTI states[/color]
 
  [color=#0000ff]SELECT[/color] [color=#000000]qtis[/color][color=#008000]                        ' Control servo speeds/directions[/color]
    [color=#0000ff]CASE[/color] [color=#000000]%1000[/color][color=#008000]                       ' Rotate right[/color]
      [color=#0000ff]PULSOUT[/color] [color=#000000]13, 650[/color]
      [color=#0000ff]PULSOUT[/color] [color=#000000]12, 650[/color]
    [color=#0000ff]CASE[/color] [color=#000000]%1100[/color][color=#008000]                       ' Pivot right[/color]
      [color=#0000ff]PULSOUT[/color] [color=#000000]13, 750[/color]
      [color=#0000ff]PULSOUT[/color] [color=#000000]12, 650[/color]
    [color=#0000ff]CASE[/color] [color=#000000]%0100[/color][color=#008000]                       ' Curve right[/color]
      [color=#0000ff]PULSOUT[/color] [color=#000000]13, 800[/color]
      [color=#0000ff]PULSOUT[/color] [color=#000000]12, 650[/color]
    [color=#0000ff]CASE[/color] [color=#000000]%0110[/color][color=#008000]                       ' Straight ahead[/color]
      [color=#0000ff]PULSOUT[/color] [color=#000000]13, 850[/color]
      [color=#0000ff]PULSOUT[/color] [color=#000000]12, 650[/color]
    [color=#0000ff]CASE[/color] [color=#000000]%0010[/color][color=#008000]                       ' Curve left[/color]
      [color=#0000ff]PULSOUT[/color] [color=#000000]13, 850[/color]
      [color=#0000ff]PULSOUT[/color] [color=#000000]12, 700[/color]
    [color=#0000ff]CASE[/color] [color=#000000]%0011[/color][color=#008000]                       ' Pivot left[/color]
      [color=#0000ff]PULSOUT[/color] [color=#000000]13, 850[/color]
      [color=#0000ff]PULSOUT[/color] [color=#000000]12, 750[/color]
   [color=#0000ff] CASE [/color][color=#000000]%0001[/color][color=#008000]                       ' Rotate left[/color]
      [color=#0000ff]PULSOUT[/color] [color=#000000]13, 850[/color]
      [color=#0000ff]PULSOUT[/color] [color=#000000]12, 850[/color]
    [color=#0000ff]CASE ELSE                        [/color][color=#008000]' Do nothing[/color]
      [color=#0000ff]PAUSE[/color] [color=#000000]3[/color]
 [color=#0000ff] ENDSELECT[/color]
[color=#0000ff]LOOP[/color]
 
[color=#000000]Check_Qtis:[/color]
[color=#008000]' Result -> qtis variable. 0 means white surface, 1 means black[/color]
[color=#008000]' surface.[/color]
 
  [color=#800080]DIRB [/color][color=#000000]= %1111[/color][color=#008000]                       ' P7..P4 -> output[/color]
  [color=#0000ff]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=#0000ff]PAUSE[/color] [color=#000000]0[/color][color=#008000]                            ' Delay = 230 us[/color]
[color=#008000]  ' PULSOUT UnusedPin, 0             ' Delays = 208 + (Duration*2) us[/color]
  [color=#000000]qtis =[/color] [color=#800080]INB[/color][color=#008000]                         ' Store QTI outputs in INB[/color]
 
  [color=#0000ff]RETURN[/color]



Figure 9 - Sample S-Shaped Boe-Bot Course
attachment.php?attachmentid=59659

Sampling Rate Experiments

With line following competitions, it's important to test the various conditions your robot will encounter to determine how much room there is in the sample interval for other sensors. Here are just a few basic test examples. To fully prepare for a contest, you'll especially want to test the most severe obstacles the course might have.

······· Make these line following obstacles:
········· 45° corner
········· 12-inch diameter circle
······· Test LineFollowWithCheckQtis.bs2 on the obstacles. It shouldn't have any problem.
······· Add PAUSE 1 to the right before the GOSUB command in the program's DO...LOOP.
······· Test the program again.
······· Keep increasing the PAUSE command's Duration argument and re-testing the Boe-Bot on each of the obstacles.

With no PAUSE command in the DO...LOOP, the sample interval is 9 ms and the sampling rate.

······· Keep increasing the PAUSE command's Duration argument and note the value at which the Boe-Bot started missing the change in the line for each obstacle.
······· What is the minimum sampling rate for each obstacle?
······· Repeat the checklist instructions above with a 90° corner. You will have to modify the example program so that the Boe-Bot can successfully detect and navigate it before testing for the minimum sampling rate.

Self Calibrating Code

Adapting the Calibrate_Qtis subroutine from Applied Robotics with the SumoBot will take some work, but it's worth it. Start by reading Chapter 3, Activity #2, #3, and #4.· The Calibrate_Qtis subroutine is in Activity #4. It takes RCTIME measurements on both of the SumoBot's QTIs. Then, it calculates the average of the two QTI measurements and divides that result by 4. When the QTI sees its infrared reflection, the voltage at the R pin decays very quickly. With a black surface, it takes a lot longer. By setting the threshold time at 1/4 of the average time it takes a QTI to discharge to 1.4 V over a black surface, it makes the QTIs fairly immune to fluctuations in ambient light that occur as the Boe-Bot changes direction.

attachment.php?attachmentid=73991
·
Incorporating the Calibrate_Qtis subroutine into your program involves keeping a running total of four RCTIME measurements (one for each QTI) and dividing by 4 to take the average. After calculating the average amount of time it takes the QTIs to decay over black, divide the averaged result by 4 (a second time) to set the decay threshold time.· Instead of dividing by 4 twice, you can alternately divide the sum of the dark QTI decay times by 16. The program's Check_Qtis subroutine should then use PULSOUT UnusedPin, threshold instead of PAUSE 0 between the DIRB = %1111 and DIRB = %0000 commands.

An initialization routine should also be added to a modified version of LineFollowWithCheckQtis.bs2.· Whenever the program starts or is reset, its QTIs should all be over the black electrical tape until the calibration is done. The amount of time it takes to complete the calibration after a reset will vary depending on how large the program is. So, it's a good idea to add a speaker or LED circuit to signal when the calibration is complete and the Boe-Bot is done self-calibrating and ready to be placed on the course.
·

Other Mechanical Setups and Navigation Programs

The QTIs in this activity were mounted very close together, and right below the front of the Boe-Bot. This is just one example of sensor placement and coding strategy; there are many others you can (and should) try. For example, pairs of QTIs could be placed several inches apart and several inches in front of the Boe-Bot. The code could be modified so that the Boe-Bot rolls forward so long as it does not detect a line and adjusts when it detects that the line is either under its left or right QTIs. This is just one of many different setups that might turn out to be optimum for line following performance. Especially if you are preparing for a contest, build a variety of courses and then test various programs and mechanical setups to figure out what's going to work the best. Also make sure to verify that the sampling rate can keep up with the most extreme changes in line direction that you would expect to see on the course.

Post Edited By Moderator (Jessica Uelmen (Parallax)) : 8/25/2010 6:19:25 PM GMT
260 x 359 - 17K
593 x 196 - 13K
532 x 339 - 27K
604 x 264 - 33K
593 x 401 - 66K
553 x 217 - 25K
668 x 72 - 5K
668 x 286 - 16K
668 x 166 - 11K
668 x 130 - 9K
668 x 122 - 10K
668 x 238 - 16K
668 x 72 - 5K

Comments

Sign In or Register to comment.