13.07.2015 Views

QTI Line Follower AppKit for the Boe-Bot (#28108) - Parallax Inc

QTI Line Follower AppKit for the Boe-Bot (#28108) - Parallax Inc

QTI Line Follower AppKit for the Boe-Bot (#28108) - Parallax Inc

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

' {$STAMP BS2}' {$PBASIC 2.5}' CheckQtiSubroutine.bs2' Displays <strong>QTI</strong> sensor states. 0 means white surface, 1 means' black.qtis VAR Nib' qti black/white statesOUTB = %1111 ' Set OUTB bits to 1DEBUG CRSRX, 8, "FMMF", CR,CRSRX, 8, "LLRR", CRDOGOSUB Check_QtisDEBUG BIN4 ? qtis, CRSRUPPAUSE 100LOOP' Display bit positions' Main DO...LOOP' Get <strong>QTI</strong> states' Display <strong>QTI</strong> states' 1/10 s delayCheck_Qtis:' Result -> qtis variable. 0 means white surface, 1 means' black surface.DIRB = %1111' P7..P4 -> outputPAUSE 0' Delay = 230 usDIRB = %0000' P7..P4 -> inputPAUSE 0' Delay = 230 usqtis = INB ' Store <strong>QTI</strong> outputs in INBRETURNThe BASIC Stamp has a variety of parallel I/O control features that make it possible to per<strong>for</strong>moperations on groups of I/O pins. CheckQtiSubroutine.bs2 uses <strong>the</strong> BASIC Stamp's DIRB and OUTBvariables to control <strong>the</strong> directions and output states of <strong>the</strong> I/O pins P7, P6, P5, and P4. When <strong>the</strong>se I/Opins are set to input with DIRB = %0000, <strong>the</strong> program also takes a snapshot of <strong>the</strong> binary states <strong>the</strong>seI/O pins sense as a result of <strong>the</strong> four <strong>QTI</strong>s' R pin voltages with <strong>the</strong> command qtis = INB.Simple <strong>Line</strong>-Following<strong>Line</strong>FollowWithCheckQtis.bs2 is designed to start following a line as soon as you place a <strong>QTI</strong> over <strong>the</strong>electrical tape. It will stop line following as soon as it runs out of electrical tape. Start with an easycourse, like a large S shape as shown below. If <strong>the</strong> <strong>QTI</strong>s passed <strong>the</strong> "Testing <strong>for</strong> <strong>Line</strong> Detection" tests, itshould navigate <strong>the</strong> course with ease.√√Enter and run <strong>Line</strong>FollowWithCheckQtis.bs2.Place <strong>the</strong> <strong>Boe</strong>-<strong>Bot</strong> on <strong>the</strong> course so that in straddles <strong>the</strong> line with <strong>the</strong> mid left and mid right <strong>QTI</strong>sover <strong>the</strong> electrical tape.If your <strong>QTI</strong>s’ cables are reversed, <strong>the</strong> <strong>Boe</strong>-<strong>Bot</strong> will appear to try to jump off <strong>the</strong> line at <strong>the</strong> firstopportunity. O<strong>the</strong>rwise, it should faithfully follow <strong>the</strong> line until it reaches <strong>the</strong> end of <strong>the</strong> tape.Copyright © <strong>Parallax</strong> <strong>Inc</strong>. <strong>QTI</strong> LIne <strong>Follower</strong> <strong>AppKit</strong> (<strong>#28108</strong>) v2.0 3/23/2009 Page 5 of 6


' {$STAMP BS2}' {$PBASIC 2.5}' <strong>Line</strong>FollowWithCheckQtis.bs2' Navigates based on values acquired with <strong>the</strong>' Check_Qtis subroutine.qtis VAR Nib' black/white statesOUTB = %1111 ' Set OUTB bits to 1DO' Main DO...LOOPGOSUB Check_Qtis' Get <strong>QTI</strong> statesSELECT qtisCASE %1000PULSOUT 13, 650PULSOUT 12, 650CASE %1100PULSOUT 13, 750PULSOUT 12, 650CASE %0100PULSOUT 13, 800PULSOUT 12, 650CASE %0110PULSOUT 13, 850PULSOUT 12, 650CASE %0010PULSOUT 13, 850PULSOUT 12, 700CASE %0011PULSOUT 13, 850PULSOUT 12, 750CASE %0001PULSOUT 13, 850PULSOUT 12, 850CASE ELSEPAUSE 3ENDSELECTLOOPCheck_Qtis:' Result -> qtis variable.' 0 means white surface' 1 means black surface.DIRB = %1111PAUSE 0DIRB = %0000PAUSE 0qtis = INBRETURN' Control servo' speeds/directions' Rotate right' Pivot right' Curve right' Straight ahead' Curve left' Pivot left' Rotate left' Do nothing' P7..P4 -> output' Delay = 230 us' P7..P4 -> input' Delay = 230 us' Store <strong>QTI</strong> outputs' in INBKeep in mind that this is a bare-bones linefollowing example. Making it robust andversatile is up to you. The <strong>Boe</strong>-<strong>Bot</strong> startsmaneuvers when it sees one of <strong>the</strong> caseslisted in <strong>the</strong> SELECT...CASE statement.This is convenient <strong>for</strong> a simpledemonstration program because <strong>the</strong> <strong>Boe</strong>-<strong>Bot</strong> doesn't go anywhere when it is on anall white or all black surface. It only startsnavigation when it detects a line. You canadd extra code, especially in <strong>the</strong> <strong>for</strong>m ofCASE statements to deal with specialsituations and more complex courses.√√√√√Try o<strong>the</strong>r courses to test <strong>the</strong> limitsof <strong>the</strong> program.Try modifying <strong>the</strong> program tosolve courses that <strong>the</strong> unmodifiedprogram could not solve.Modify <strong>the</strong> program so that itsmoo<strong>the</strong>s out <strong>the</strong> <strong>Boe</strong>-<strong>Bot</strong>'sresponses to changes in <strong>the</strong> line'sdirection. Your code should takesteps toward a maximum speedeach time it detects that a givenpattern is detected.Detect intersections and makerandom turns.Challenge a friend, or set up a<strong>Boe</strong>-<strong>Bot</strong> line followingcompetition.Copyright © <strong>Parallax</strong> <strong>Inc</strong>. <strong>QTI</strong> LIne <strong>Follower</strong> <strong>AppKit</strong> (<strong>#28108</strong>) v2.0 3/23/2009 Page 6 of 6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!