Shop OBEX P1 Docs P2 Docs Learn Events
im having a problem with the whiskers and IR's — Parallax Forums

im having a problem with the whiskers and IR's

dragonmantwodragonmantwo Posts: 3
edited 2012-03-21 04:46 in Accessories
so i tried making the boe-bot wander around a table top avoiding the ledges with the sensor arms as well. all the Boe-bot dose is spin in circles... is there a problem with the code? the IR's are reading constand 001's that flash faster as u put your hand infront of the IR's. im very new at this...

' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "program running"
irdetectleft VAR Bit
irdetectright VAR Bit
pulseleft VAR Word
pulseright VAR Word
loopcount VAR Byte
pulsecount VAR Byte
FREQOUT 15, 2000, 3000
DO
FREQOUT 8, 1, 38500
irdetectleft = IN9
FREQOUT 2, 1, 38500
irdetectright = IN0
DEBUG "Left = ", BIN1 IN9, " Right = ", BIN1 IN0, CR
IF (irdetectleft = 0) AND (irdetectright = 0) THEN
pulsecount = 1
pulseleft = 850
pulseright = 650
DEBUG "hERE"
ELSEIF (irdetectright = 1)AND (irdetectleft = 0) THEN
pulsecount = 10
pulseleft = 650
pulseright = 650
DEBUG "THERE"
ELSEIF (irdetectleft = 1) AND (irdetectright = 0) THEN
pulsecount = 10
pulseleft = 850
pulseright = 850
DEBUG "eVERYWHERE"
ELSEIF (irdetectleft = 1) AND (irdetectright = 1) THEN
pulsecount = 15
pulseleft = 650
pulseright = 850
DEBUG "nOWHERE"
ENDIF

IF (IN5 = 0) AND (IN3 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN5 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Right
ELSEIF (IN3 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
ENDIF
FOR loopcount = 1 TO pulsecount
PULSOUT 13, pulseleft
PULSOUT 12, pulseright
PAUSE 20
NEXT

LOOP

'subrountines
Turn_Left:
FOR pulsecount = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulsecount = 0 TO 20
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Back_Up:
FOR pulsecount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN


thank you very much :smile:

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-03-16 16:51
    First of all, temporarily throw out all the code from the DEBUG "nOWHERE" and ENDIF to the end of the program. You first want to make sure that the sensors work the way you expect them to work.

    If the whiskers are attached to I/O pin 3 and I/O pin 5, add a DEBUG statement to display their state. Put a label like START: just before the first DO and a PAUSE 3000 : GOTO START at the end of the code and start it up.

    You should be able to move the BoeBot around on your table top by hand, checking to make sure the IR sensors work at the edges of the table as expected. If you put an object on the table, you should be able to move the BoeBot by hand around the object and see how the IR sensors and whiskers behave. Start making a table of sensor values and possible actions (if irdetectright = 1 and irdetectleft = 0, etc.), then check that against the code you've temporarily deleted. You should be able to create a more robust piece of code and have confidence that the sensors work.

    You should also calibrate the servos and try some simple test programs to see whether the BoeBot can go in a straight line and make reasonably clean turns to the left and right. It make take some adjustment to the pulse width values you're using for the PULSOUTs and the FOR loop values.
  • dragonmantwodragonmantwo Posts: 3
    edited 2012-03-21 04:46
    ok thx very much =)
Sign In or Register to comment.