Day active Boe-Bot
Here's something I came up with to add a creature like characteristic to my boe bot. My plan was to make the Boe-Bot avoid both objects and ledges. In addition, the Boe-Bot is also day active, and will go to sleep if it becomes dark. The definition of "dark" is determined by the boe bot alone. If his light sensor tells him it is dark, he will enter sleep mode, until someone switches on the light.
Because the Boe-Bot independently defines "dark" himself, you only have or can adjust the time he takes to define daylight. This is the constant called "updatetime".
Here's the code (With lots of comments
):
Try it out, but adjust the angle of your IR sensors on a flat surface, by using the DEBUG MENU before running the boe bot. (IR sensors are tilted downwards about 20-30 degrees)
Because the Boe-Bot independently defines "dark" himself, you only have or can adjust the time he takes to define daylight. This is the constant called "updatetime".
Here's the code (With lots of comments
):' {$STAMP BS2}
' {$PBASIC 2.5}
'BREADBOARDING INFO (README):
'2 IR sets and one lightsensor with capacitator (Comes with default Boe-Bot Kit)
'Light Sensor connected to P6 (with capacitator)
'Right IR LED connected to P2 and Left IR LED connected to P8
'Bend the two IR LEDs down, so they face the floor and use DEBUG MENU for adjustment
'Right IR reciever connected to P0 and Left IR reciever connected to P9
'Piezo speaker connected to P4
'NOTE: check "Robotics with the Boe-Bot" for resistor and other configurations of sensors!
'----UPDATE HISTORY:----
'V2.5 + robot takes nap, if it finds a dark area after update
'V2.3 + robot finds the relative darkest area after wandering around X seconds(updatetime)
'V2.0 + light sensor(1) -- searches for darkest spot
'V1.0 IR sensors(2) -- Avoids objects and ledges
updatetime CON 30 '<--- time the robot takes to decide what darkest area is. Feel free to change
floorL VAR Word
floorR VAR Word
objL VAR Word
objR VAR Word
pulse VAR Byte
light VAR Word
darkest VAR Word
counter VAR Word
DEBUG "LEFT RIGHT", CR, "Object sensors (0=object, 1=no object)"
DEBUG CRSRXY, 0, 3, "Floor Sensors (0=ground, 1=no ground)"
DEBUG CRSRXY, 0,5, "Light Sensor: "
FREQOUT 4,200,4000 'Start up sound...
PAUSE 1000
FREQOUT 4,300,4000
PAUSE 1000
FREQOUT 4,1500,4000
DO
FREQOUT 8,1,37500
floorL=IN9
FREQOUT 2,1,37500
floorR=IN0
FREQOUT 8,1,43000
objL=IN9
FREQOUT 2,1,43000
objR=IN0
HIGH 6
PAUSE 2
RCTIME 6,1,light
DEBUG CRSRXY, 2, 2, DEC1 objL,
CRSRXY, 9, 2, DEC1 objR,
CRSRXY, 2, 4, DEC1 floorL,
CRSRXY, 9, 4, DEC1 floorR,CR,
CRSRXY, 15,5, DEC3 light, "...where 0 is very bright" ,
CRSRXY, 2, 6, "...Darkest Area found: ", DEC3 darkest ,
CRSRXY, 0, 7, "Counter: ", DEC3 counter, "/", DEC3 updatetime
' 0 is contact, 1 is no contact
IF ((counter<updatetime) OR (darkest>light)) THEN 'logic is opposite
GOSUB update
IF ((floorL = 1 AND floorR = 1) OR (objL = 0 AND objR = 0) OR (objL = 0 AND floorR = 1) OR (floorL = 1 AND objR = 0)) THEN
GOSUB back
GOSUB left
GOSUB left
ELSEIF (floorR = 1 OR objR = 0) THEN
GOSUB left
ELSEIF (floorL = 1 OR objL = 0) THEN
GOSUB right
ELSE
GOSUB foward
ENDIF
ELSE
SLEEP 1 'after those X seconds, robot will stop if he finds anything darker and takes a "nap"
ENDIF '...until woken up by light
LOOP
'SUBroutine Functions
foward:
FOR pulse = 0 TO 5
PULSOUT 12, 850
PULSOUT 13, 650
PAUSE 20
NEXT
RETURN
back:
FOR pulse = 0 TO 20
PULSOUT 12, 650
PULSOUT 13, 850
PAUSE 20
NEXT
RETURN
left:
FOR pulse = 0 TO 5
PULSOUT 13, 650
PAUSE 20
NEXT
RETURN
right:
FOR pulse = 0 TO 5
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
update: 'counstantly updates definition of darkest area for X (updatetime) seconds
IF (counter<updatetime) THEN
IF(light>darkest) THEN
darkest=light
ELSE
darkest=darkest
ENDIF
counter=counter+1
PAUSE 100
ELSE
counter=updatetime
ENDIF
RETURN
Try it out, but adjust the angle of your IR sensors on a flat surface, by using the DEBUG MENU before running the boe bot. (IR sensors are tilted downwards about 20-30 degrees)

Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I would also appreciate some more feedback...