Difference between revisions of "BoeBot"

From RoboWiki
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Example 1:
 
  
<source lang="pas">
+
== Example 1: ==
 +
 
 +
 
 +
<source lang="vb">
 
' Robotics with the Boe-Bot - StartResetIndicator.bs2
 
' Robotics with the Boe-Bot - StartResetIndicator.bs2
 
' Test the piezospeaker circuit.
 
' Test the piezospeaker circuit.
Line 19: Line 21:
  
  
<source lang="Basic">
+
== Example 2: ==
 +
 
 +
 
 +
<source lang="vb">
 +
' Robotics with the Boe-Bot - TestServoSpeed.bs2
 +
' Enter pulse width, then count revolutions of the wheel.
 +
' The wheel will run for 6 seconds
 +
' Multiply by 10 to get revolutions per minute (RPM).
 +
 
 +
'{$STAMP BS2}
 +
'{$PBASIC 2.5}
 +
 
 +
counter          VAR    Word
 +
pulseWidth      VAR    Word
 +
 
 +
FREQOUT 4, 2000, 3000              ' Signal program start/reset.
 +
 
 +
DO
 +
 
 +
  DEBUG "Enter pulse width: "
 +
  DEBUGIN DEC pulseWidth
 +
 
 +
  FOR counter = 1 TO 244
 +
  PULSOUT 12, pulseWidth
 +
  PULSOUT 13, pulseWidth
 +
  PAUSE 20
 +
  NEXT
 +
 
 +
LOOP
 +
</source>
 +
 
 +
 
 +
== Example 3: ==
 +
 
 +
 
 +
<source lang="vb">
 +
' Robotics with the Boe-Bot - EepromNavigation.bs2
 +
' Navigate using characters stored in EEPROM.
 +
 
 +
' {$STAMP BS2}                    ' Stamp directive.
 +
' {$PBASIC 2.5}                    ' PBASIC directive.
 +
 
 +
DEBUG "Program Running!"
 +
 
 +
' -----[ Variables ]----------------------------------------------------------
 +
 
 +
pulseCount  VAR  Word            ' Stores number of pulses.
 +
address      VAR  Byte            ' Stores EEPROM address.
 +
instruction  VAR  Byte            ' Stores EEPROM instruction.
 +
 
 +
' -----[ EEPROM Data ]--------------------------------------------------------
 +
 
 +
'    Address: 0123456789          ' These two commented lines show
 +
'            ||||||||||          ' EEPROM address of each datum.
 +
DATA        "FLFFRBLBBQ"          ' Navigation instructions.
 +
 
 +
' -----[ Initialization ]-----------------------------------------------------
 +
 
 +
FREQOUT 4, 2000, 3000              ' Signal program start/reset.
 +
 
 +
' -----[ Main Routine ]-------------------------------------------------------
 +
 
 +
DO UNTIL (instruction = "Q")
 +
 
 +
  READ address, instruction        ' Data at address in instruction.
 +
  address = address + 1            ' Add 1 to address for next read.
 +
 
 +
  SELECT instruction              ' Call a different subroutine
 +
    CASE "F": GOSUB Forward        ' for each possible character
 +
    CASE "B": GOSUB Backward      ' that can be fetched from
 +
    CASE "L": GOSUB Left_Turn      ' EEPROM.
 +
    CASE "R": GOSUB Right_Turn
 +
  ENDSELECT
 +
 
 +
LOOP
 +
 
 +
END                                ' Stop executing until reset.
 +
 
 +
 
 +
' -----[ Subroutine - Forward ]-----------------------------------------------
 +
 
 +
Forward:                          ' Forward subroutine.
 +
FOR pulseCount = 1 TO 64          ' Send 64 forward pulses.
 +
  PULSOUT 13, 850                ' 1.7 ms pulse to left servo.
 +
  PULSOUT 12, 650                ' 1.3 ms pulse to right servo.
 +
  PAUSE 20                        ' Pause for 20 ms.
 +
NEXT
 +
RETURN                            ' Return to Main Routine loop.
 +
 
 +
 
 +
' -----[ Subroutine - Backward ]----------------------------------------------
 +
 
 +
Backward:                          ' Backward subroutine.
 +
FOR pulseCount = 1 TO 64          ' Send 64 backward pulses.
 +
  PULSOUT 13, 650                ' 1.3 ms pulse to left servo.
 +
  PULSOUT 12, 850                ' 1.7 ms pulse to right servo.
 +
  PAUSE 20                        ' Pause for 20 ms.
 +
NEXT
 +
RETURN                            ' Return to Main Routine loop.
 +
 
 +
 
 +
' -----[ Subroutine - Left_Turn ]---------------------------------------------
 +
 
 +
Left_Turn:                        ' Left turn subroutine.
 +
FOR pulseCount = 1 TO 24          ' Send 24 left rotate pulses.
 +
  PULSOUT 13, 650                ' 1.3 ms pulse to left servo.
 +
  PULSOUT 12, 650                ' 1.3 ms pulse to right servo.
 +
  PAUSE 20                        ' Pause for 20 ms.
 +
NEXT
 +
RETURN                            ' Return to Main Routine loop.
 +
 
 +
 
 +
' -----[ Subroutine – Right_Turn ]--------------------------------------------
 +
 
 +
Right_Turn:                        ' right turn subroutine.
 +
FOR pulseCount = 1 TO 24          ' Send 24 right rotate pulses.
 +
  PULSOUT 13, 850                ' 1.7 ms pulse to left servo.
 +
  PULSOUT 12, 850                ' 1.7 ms pulse to right servo.
 +
  PAUSE 20                        ' Pause for 20 ms.
 +
NEXT
 +
RETURN                            ' Return to Main Routine section.
 +
 
 +
 
 +
</source>
 +
 
 +
 
 +
 
 +
 
 +
== Example 4: ==
 +
 
 +
 
 +
<source lang="vb">
 +
' Robotics with the Boe-Bot - TestWhiskers.bs2
 +
' Display what the I/O pins connected to the whiskers sense.
 +
 
 +
' {$STAMP BS2}                        ' Stamp directive
 +
' {$PBASIC 2.5}                      ' PBASIC directive.
 +
 
 +
DEBUG "WHISKER STATES", CR,
 +
      " Left  Right", CR,
 +
      "------ -------"
 +
 
 +
DO
 +
  DEBUG CRSRXY, 0, 3,
 +
        "P5 = ", BIN1 IN5,
 +
        " P7 = ", BIN1 IN7
 +
  PAUSE 50
 +
LOOP
 +
 
 +
 
 +
' Later on.. Let's add following:
 +
 
 +
IF (IN7 = 0) THEN
 +
  HIGH 1
 +
ELSE
 +
  LOW 1
 +
ENDIF
 +
 
 +
 
 +
IF (IN5 = 0) THEN
 +
  HIGH 10
 +
ELSE
 +
  LOW 10
 +
ENDIF
  
 +
'And finally:
 +
DO
 +
  IF (IN5 = 0) AND (IN7 = 0) THEN ' Both whiskers detect obstacle
 +
    GOSUB Back_Up ' Back up & U-turn (left twice)
 +
    GOSUB Turn_Left
 +
    GOSUB Turn_Left
 +
  ELSEIF (IN5 = 0) THEN ' Left whisker contacts
 +
    GOSUB Back_Up ' Back up & turn right
 +
    GOSUB Turn_Right
 +
  ELSEIF (IN7 = 0) THEN ' Right whisker contacts
 +
    GOSUB Back_Up ' Back up & turn left
 +
    GOSUB Turn_Left
 +
  ELSE ' Both whiskers 1, no contacts
 +
    GOSUB Forward_Pulse ' Apply a forward pulse
 +
  ENDIF ' and check again
 +
LOOP
 
</source>
 
</source>

Latest revision as of 12:30, 11 December 2008

Example 1:

' Robotics with the Boe-Bot - StartResetIndicator.bs2
' Test the piezospeaker circuit.

' {$STAMP BS2}                   ' Stamp directive.
' {$PBASIC 2.5}                  ' PBASIC directive.

 DEBUG CLS, "Beep!!!"            ' Display while speaker beeps.
 FREQOUT 4, 2000, 3000           ' Signal program start/reset.

 DO                              ' DO...LOOP
  DEBUG CR, "Waiting for reset…" ' Display message
  PAUSE 500                      ' every 0.5 seconds
 LOOP                            ' until hardware reset.


Example 2:

' Robotics with the Boe-Bot - TestServoSpeed.bs2
' Enter pulse width, then count revolutions of the wheel.
' The wheel will run for 6 seconds
' Multiply by 10 to get revolutions per minute (RPM).

'{$STAMP BS2}
'{$PBASIC 2.5}

counter          VAR    Word
pulseWidth       VAR    Word

 FREQOUT 4, 2000, 3000              ' Signal program start/reset.

 DO

  DEBUG "Enter pulse width: "
  DEBUGIN DEC pulseWidth

  FOR counter = 1 TO 244
   PULSOUT 12, pulseWidth
   PULSOUT 13, pulseWidth
   PAUSE 20
  NEXT

 LOOP


Example 3:

' Robotics with the Boe-Bot - EepromNavigation.bs2
' Navigate using characters stored in EEPROM.

' {$STAMP BS2}                     ' Stamp directive.
' {$PBASIC 2.5}                    ' PBASIC directive.

DEBUG "Program Running!"

' -----[ Variables ]----------------------------------------------------------

pulseCount   VAR  Word             ' Stores number of pulses.
address      VAR  Byte             ' Stores EEPROM address.
instruction  VAR  Byte             ' Stores EEPROM instruction.

' -----[ EEPROM Data ]--------------------------------------------------------

'    Address: 0123456789           ' These two commented lines show
'             ||||||||||           ' EEPROM address of each datum.
DATA         "FLFFRBLBBQ"          ' Navigation instructions.

' -----[ Initialization ]-----------------------------------------------------

FREQOUT 4, 2000, 3000              ' Signal program start/reset.

' -----[ Main Routine ]-------------------------------------------------------

DO UNTIL (instruction = "Q")

  READ address, instruction        ' Data at address in instruction.
  address = address + 1            ' Add 1 to address for next read.

  SELECT instruction               ' Call a different subroutine
    CASE "F": GOSUB Forward        ' for each possible character
    CASE "B": GOSUB Backward       ' that can be fetched from
    CASE "L": GOSUB Left_Turn      ' EEPROM.
    CASE "R": GOSUB Right_Turn
  ENDSELECT

LOOP

END                                ' Stop executing until reset.


' -----[ Subroutine - Forward ]-----------------------------------------------

Forward:                           ' Forward subroutine.
 FOR pulseCount = 1 TO 64          ' Send 64 forward pulses.
   PULSOUT 13, 850                 ' 1.7 ms pulse to left servo.
   PULSOUT 12, 650                 ' 1.3 ms pulse to right servo.
   PAUSE 20                        ' Pause for 20 ms.
 NEXT
RETURN                             ' Return to Main Routine loop.


' -----[ Subroutine - Backward ]----------------------------------------------

Backward:                          ' Backward subroutine.
 FOR pulseCount = 1 TO 64          ' Send 64 backward pulses.
   PULSOUT 13, 650                 ' 1.3 ms pulse to left servo.
   PULSOUT 12, 850                 ' 1.7 ms pulse to right servo.
   PAUSE 20                        ' Pause for 20 ms.
 NEXT
RETURN                             ' Return to Main Routine loop.


' -----[ Subroutine - Left_Turn ]---------------------------------------------

Left_Turn:                         ' Left turn subroutine.
 FOR pulseCount = 1 TO 24          ' Send 24 left rotate pulses.
   PULSOUT 13, 650                 ' 1.3 ms pulse to left servo.
   PULSOUT 12, 650                 ' 1.3 ms pulse to right servo.
   PAUSE 20                        ' Pause for 20 ms.
 NEXT
RETURN                             ' Return to Main Routine loop.


' -----[ Subroutine – Right_Turn ]--------------------------------------------

Right_Turn:                        ' right turn subroutine.
 FOR pulseCount = 1 TO 24          ' Send 24 right rotate pulses.
   PULSOUT 13, 850                 ' 1.7 ms pulse to left servo.
   PULSOUT 12, 850                 ' 1.7 ms pulse to right servo.
   PAUSE 20                        ' Pause for 20 ms.
 NEXT
RETURN                             ' Return to Main Routine section.



Example 4:

' Robotics with the Boe-Bot - TestWhiskers.bs2
' Display what the I/O pins connected to the whiskers sense.

' {$STAMP BS2}                        ' Stamp directive
' {$PBASIC 2.5}                       ' PBASIC directive.

 DEBUG "WHISKER STATES", CR,
       " Left   Right", CR,
       "------ -------"

 DO
  DEBUG CRSRXY, 0, 3,
        "P5 = ", BIN1 IN5,
        " P7 = ", BIN1 IN7
  PAUSE 50
 LOOP


 ' Later on.. Let's add following:

 IF (IN7 = 0) THEN
  HIGH 1
 ELSE
  LOW 1
 ENDIF


 IF (IN5 = 0) THEN
  HIGH 10
 ELSE
  LOW 10
 ENDIF

 'And finally:
 DO
  IF (IN5 = 0) AND (IN7 = 0) THEN ' Both whiskers detect obstacle
    GOSUB Back_Up ' Back up & U-turn (left twice)
    GOSUB Turn_Left
    GOSUB Turn_Left
  ELSEIF (IN5 = 0) THEN ' Left whisker contacts
    GOSUB Back_Up ' Back up & turn right
    GOSUB Turn_Right
  ELSEIF (IN7 = 0) THEN ' Right whisker contacts
    GOSUB Back_Up ' Back up & turn left
    GOSUB Turn_Left
  ELSE ' Both whiskers 1, no contacts
    GOSUB Forward_Pulse ' Apply a forward pulse
  ENDIF ' and check again
 LOOP