EGR 277 – Digital Logic

Document Sample
scope of work template
							BOE-BOT Lecture #4         EGR 120 – Introduction to Engineering

     Navigating the BOE-BOT with whiskers
Reference:
For more complete documentation, the following items are available from
www.parallax.com or www.tcc.edu/faculty/webpages/PGordy
• Robotics with the BOEBOT Version 2.2
• BASIC Stamp Syntax and Reference Manual Version 2.1




                                                                          1
BOE-BOT Lecture #4          EGR 120 – Introduction to Engineering
                Tactile Navigation with the BOE-BOT
                   (Wall following using whiskers)

The following is an excerpt from Robotics, Version 2.2:

“Many types of robotic machinery rely on a variety of tactile switches. For example, a
tactile switch may detect when a robotic arm has encountered an object. The robot can
be programmed to pick up the object and place it elsewhere. Factories use tactile
switches to count objects on a production line, and also for aligning objects during
industrial processes.
In this chapter, you will build tactile switches, called whiskers, onto your BOE-BOT
and test them. You will then program the BOE-BOT to monitor the state of these
switches, and to decide what to do when it encounters an obstacle. The end result will
be autonomous navigation by touch.
The whiskers are so named because that is what these bumper switches look like,
though some argue they look more like antennae. Whiskers give the BOE-BOT the
ability to sense the world around it through touch, much like the antennae on an ant or
the whiskers on a cat.
                                                                                  2
BOE-BOT Lecture #4   EGR 120 – Introduction to Engineering




         Whiskers
                                                             3
BOE-BOT Lecture #4   EGR 120 – Introduction to Engineering
                                              Adding whiskers to the
                                    Header
                                              BOE-BOT
                                              If your BOE-BOT is not
                                              already equipped with
                                              whiskers, following the
                                              instructions shown from
                                              Robotics, Version 2.2 to
                                              add the whiskers. If your
                                              BOE-BOT is equipped with
                                              whiskers, skip to the next
                                              page.




                                                                   4
BOE-BOT Lecture #4           EGR 120 – Introduction to Engineering
Adding a whisker circuit to the BOE-BOT
Shown below is a circuit to read the status of each whisker. It works as follows: The
whiskers are connected to standoffs on the BOE which are connected to ground (Vss).
When the BOE-BOT runs into a wall, the whisker touches a “header” on the
breadboard which will make a connection to a point in the circuit below (see next
page). A whisker hitting a wall is equivalent to closing a switch in the circuit below.
In the circuit, if the right whisker hits a wall, it makes a connection to Vss making P7
LOW. If the whiskers is not pressed, P7 remains HIGH. In this way we can tell when
each whiskers hits a wall by monitoring the states of P5 and P7.




                                                                                   5
BOE-BOT Lecture #4          EGR 120 – Introduction to Engineering
Adding a whisker circuit to the BOE-BOT
Shown below is a circuit to read the status of each whisker. It works as follows: The




                                    Header

                                                          When the left whisker hits a
                                                          wall, it is pushed into the
                                                          header, essentially connecting
                                                          the header to ground (Vss).

                                                          The whisker is connected to
                                                          the corner of the BOE, which
                                                          is connected to ground (Vss)




                                                                                  6
BOE-BOT Lecture #4          EGR 120 – Introduction to Engineering
Whisker test circuit
It is nice to have a test circuit, so that we can tell if the whiskers are working
properly. An easy solution if to add two LED (with series resistors) so that one LED
lights when the left whisker hits a wall and the other LED lights when the right
whisker hits a wall.




                                                                                 7
BOE-BOT Lecture #4          EGR 120 – Introduction to Engineering
Final result: Whisker control circuit with LED test circuit.
Shown below is the BOE-BOT with the whisker control circuit (see Figure 5-4) and
the LED whisker test circuit (see Figure 5-7). You will need to add this circuit to your
BOE-BOT.




                                           Note: Ignore the round, black buzzer
                                           and the wire connecting it to P4. We
                                           will not be using the buzzer.




                                                                                  8
BOE-BOT Lecture #4           EGR 120 – Introduction to Engineering
Additional PBASIC Instructions
Before testing the whiskers, a few new PBASIC instructions need to be introduced.

Inputs to the Basic Stamp
The BASIC Stamp can easily determine whether an input connected to a pin is HIGH
or LOW by checking its value. This is done using:
INpin         where pin can be 0 through 15

so
     IN3 will have the value 1 if a HIGH (5V) input is connected to P3
     IN4 will have the value 0 if a LOW (0V) input is connected to P4




                                                                              9
BOE-BOT Lecture #4            EGR 120 – Introduction to Engineering
Decision structures
Most programming languages support
various types of decision structures which
allows the program to branch and perform
different tasks based on some sort of             Logical        F
logical test. A common type of decision            Test
structure is the IF .. THEN structure.
                                                  T
IF (Logical Statement) THEN statements
so that the program can respond one way        Do this if true       Do this if false
when the logical statement is true and
another way when it is false. Sometimes
this is illustrated with a diagram as shown.




                                                                                        10
BOE-BOT Lecture #4            EGR 120 – Introduction to Engineering
IF .. THEN statement in PBASIC                     Examples of Logical Tests:
IF (Logical Test) THEN                             X>2
   Instructions to perform if the test is true     IN3 = 0
ENDIF                                              IN7 <> 0 (not equal)
                                                   A <= B
Or                                                 A+B >= C+D

IF (Logical Test) THEN
   Instructions to perform if the test is true
ELSE
   Instructions to perform if the test is false
ENDIF

Example:                             Example:
IF (X < 0) THEN                      IF (IN8 = 0) THEN
   DEBUG “X is negative”                DEBUG “P8 is LOW”
ENDIF                                ELSE
                                        DEBUG “P8 is HIGH”
                                     ENDIF                                      11
BOE-BOT Lecture #4                  EGR 120 – Introduction to Engineering
                                                    Subprograms in PBASIC
                                                    In order to repeat useful sections of code,
‘ Main program
                                                    subprograms (or subroutines) are often
N VAR BYTE
GOSUB Blink              ‘Call subroutine Blink
                                                    used. Functions are also used for this
Other instructions
                                                    purpose in other programming languages.
….
GOSUB Blink              ‘Call subroutine Blink     For example, suppose that at several points
Other instructions                                  in a program you wanted to cause an LED
….                                                  connected to P3 to blink on and off ten
GOSUB Blink                ‘Call subroutine Blink   times. Instead of repeating the instructions
Other instructions                                  several times, they could be placed in a
Other instructions
                                                    subprogram as shown below.
….
END                       ‘End of main program      Note that three new PBASIC commands
‘-----Subroutine Blink is listed below---------
                                                    were introduced in this example.
Blink:
FOR N = 1 TO 10                                     Discuss each.
  HIGH 3
  PAUSE 500
                                                    GOSUB Label
  LOW 3
  PAUSE 500                                         Label:
NEXT                                                RETURN
RETURN
                                                                                        12
BOE-BOT Lecture #4         EGR 120 – Introduction to Engineering
Testing the whiskers
The program below can be used to test the whiskers. Each time a whiskers is pressed,
the input will be detected and an LED will light. It is important to use this test
program to be sure that the whiskers are functioning properly before navigation on a
track is attempted. This program will be used in Team Assignment #5.
  DO
   IF (IN7 = 0) THEN        ‘IN7 = 0 when right whisker hits wall
     HIGH 1                 ‘Turn on LED connected to P1 when IN7 = 0
   ELSE
     LOW 1                   ‘Turn off LED connected to P1 when IN7  0
   ENDIF
   IF (IN5 = 0) THEN         ‘IN5 = 0 when left whisker hits wall
     HIGH 10                 ‘Turn on LED connected to P10 when IN5 = 0
   ELSE
     LOW 10                  ‘Turn off LED connected to P10 when IN5  0
   ENDIF
   PAUSE 50                  ‘Test whiskers about every 50 ms
  LOOP


                                                                              13
BOE-BOT Lecture #4           EGR 120 – Introduction to Engineering
Sample whisker navigation program
A whisker navigation program is provided in the BOE-BOT manual that could
possibly be used to try to navigate any general maze. If a specific track is to be used,
modifications to the program might be made so that it will more efficiently navigate
that specific track.
The program works as follows:
• If neither whisker is pressed, go straight
• If the left whisker runs into an obstacle, back up a little bit and turn right 90º
• If the right whisker runs into an obstacle, back up a little bit and turn left 90º
• If both whiskers run into obstacles, back up a little bit and turn 180º (U-turn)

Video – a video of a BOE-BOT navigating using whiskers based on the sample
program described above is available at the following URL:
         http://www.parallax.com/dl/mm/video/boebot/whisker.mpg




                                                                                   14
 BOE-BOT Lecture #4                          EGR 120 – Introduction to Engineering
 Sample whisker navigation program
 The whisker navigation program from the BOE-BOT manual described on the previous slide is shown
 below.
' {$STAMP BS2}                                                           Turn_Left:                  'Turn left about 90 degrees
' {$PBASIC 2.5}                                                           FOR pulseCount = 0 TO 20
' {$PORT COM1}                                                             PULSOUT 13, 650           'Right wheel full speed CW
 'Sample program to navigate with whiskers from Robotics,                  PULSOUT 12, 650           'Right wheel full speed CW
Version 2.2, pp. 179-180                                                   PAUSE 20
pulseCount VAR Byte               'Loop counter for FOR .. NEXT loops     NEXT
DO                                                                        RETURN
  IF (IN5 = 0) AND (IN7 = 0)THEN 'Both whiskers detect obstacle
    GOSUB Back_Up                          'Back up and do U-turn        Turn_Right:                 'Turn right about 90 degrees
    GOSUB Turn_Left                                                       FOR pulseCount = 0 TO 20
    GOSUB Turn_Left                                                        PULSOUT 13, 850           'Right wheel full speed CCW
  ELSEIF (IN5 = 0) THEN                'Left whisker detects obstacle      PULSOUT 12, 850           'Right wheel full speed CCW
    GOSUB Back_Up                       'Back up and turn right            PAUSE 20
    GOSUB Turn_Right                                                      NEXT
  ELSEIF (IN7 = 0) THEN                'Right whisker detects obstacle    RETURN
    GOSUB Back_Up                       'Back up and turn left
    GOSUB Turn_Left                                                      Back_Up:                    'Back up a little bit
  ELSE                                   'No contact with whiskers        FOR pulseCount = 0 TO 40
    GOSUB Forward_Pulse                  'Go straight forward              PULSOUT 13, 650           'Left wheel full speed CW
  ENDIF                                  'and check again                  PULSOUT 12, 850           'Right wheel full speed CCW
LOOP                                                                       PAUSE 20
' ----- Subroutines -------------------------------------------------     NEXT
Forward_Pulse:                          'Go straight ahead
  PULSOUT 13, 850                      'Left wheel full speed CCW         RETURN
  PULSOUT 12, 650                      'Right wheel full speed CW
  PAUSE 20
  RETURN
                                                                                                                        15
BOE-BOT Lecture #4 EGR 120 – Introduction to Engineering
Modifying the whisker navigation program
There are many possible approaches to navigation by whiskers. Some approaches might include:

• Program the BOE-BOT to follow the
  outside (right) wall. Do this by giving       Counter VAR BYTE
  the BOE-BOT a slight bias (drift) to the      Counter = 0                               „Initialize counter to zero
                                                DO
  right. When the right whisker hits the           IF (IN5 = 0) AND (IN7 = 0)THEN 'Both whiskers detect obstacle
  wall, turn left for a short time and then           Counter = Counter + 1
  resume the slight bias to the right.                IF (Counter >=4) AND (Counter <=6) THEN
                                                         GOSUB Back_Up                      ‘Back up and turn left
• Same as above except follow the inside                 GOSUB Turn_Left
  (left) wall. This is illustrated on the             ELSE
                                                         GOSUB Back_Up                       'Back up and turn right
  following slide.                                       GOSUB Turn_Right
• Change the program as the BOE-BOT                   ENDIF
                                                  ELSEIF (IN7 = 0) THEN                'Right whisker detects obstacle
  proceeds through the course. For                  GOSUB Back_Up                       'Back up and turn left
  example:                                          GOSUB Turn_Left
     – The first three times that both            ELSE                                   'No contact with whiskers
                                                    GOSUB Forward_Pulse                  'Go straight forward
         whiskers hit a wall, turn right          ENDIF                                  'and check again
     – The 4th, 5th, and 6th time that both     LOOP
                                                ' ----- Subroutines -------------------------------------------------
         whiskers hit a wall, turn left         Forward_Pulse:                          'Go straight ahead
     – Turn right for additional times.           PULSOUT 13, 850                      'Left wheel full speed CCW
                                                  PULSOUT 12, 650                      'Right wheel full speed CW
     – Note that it may be necessary to           PAUSE 20
         use a counter to keep track of the       RETURN
                                                Etc …….
         walls.                                                                                            16
     – See the example shown
BOE-BOT Lecture #4 EGR 120 – Introduction to Engineering
Possible whisker navigation program – following the outside wall
                                                              Adding angled
        Path of                                                 barriers to
         robot                                                 corners may
                                                                  make
                                                                navigation
                            Right
 Place where left                                                 easier
                           Whisker
 whisker hits the
       wall



Robot naturally drives
slightly to the left and
  then corrects right
after left whisker hits                                             Areas of
        the wall                                                   difficulty?




                                                                     17

						
Related docs
Other docs by pengtt
Mainboard Manufacturer Gigabyte
Views: 161  |  Downloads: 0
9-11
Views: 75  |  Downloads: 0
NEUHEITEN 2. HALBJAHR 2010 GIRLS
Views: 5  |  Downloads: 0
Irrigation Development and Farme
Views: 63  |  Downloads: 0
CABIN JOHN ICE RINK - PDF
Views: 6  |  Downloads: 0
Sample Report
Views: 6  |  Downloads: 0
MINUTES OF A MEETING OF THE SADD
Views: 1  |  Downloads: 0
EXPRESS YOURSELF - Hoover City Schools
Views: 23  |  Downloads: 0
Dreams Resort and Spa
Views: 1  |  Downloads: 0