Shop OBEX P1 Docs P2 Docs Learn Events
RoamingWithIr.bs2 -- Detecting objects from too far away? — Parallax Forums

RoamingWithIr.bs2 -- Detecting objects from too far away?

eMarston15eMarston15 Posts: 3
edited 2014-04-09 15:37 in Accessories
Hey, guys. I was working on RoamingWithIr.bs2 (below), and I noticed that instead of detecting objects when it reaches them, the Boe-Bot is detecting and turning in response to objects that are 2-3 feet away. Could someone take a look at the script and see if there's something that can be changed to fix this, or if it's a wiring problem?

'
[ Title ]
' Robotics with the Boe-Bot - RoamingWithIr.bs2
' Adapt RoamingWithWhiskers.bs2 for use with IR object detectors.
' {$STAMP BS2}
' {$PBASIC 2.5}

'
[ Variables ]

irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseCount VAR Byte

'
[ Initialization ]

FREQOUT 4, 2000, 3000

'
[ Main Routine ]

DO
FREQOUT 8, 1, 38500 'Store IR detection values in
irDetectLeft = IN9 'bit variables

FREQOUT 2, 1, 38500
irDetectRight = IN0

IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (irDetectLeft = 0) THEN
GOSUB Back_Up
GOSUB Turn_Right
ELSEIF (irDetectRight = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
ELSE
GOSUB Forward_Pulse
ENDIF
LOOP

'
[ Subroutines ]

Forward_Pulse:
PULSOUT 13,837
PULSOUT 12,678
PAUSE 20
RETURN

Turn_Left:
FOR pulseCount = 0 TO 20
PULSOUT 13,678
PULSOUT 12,678
PAUSE 20
NEXT
RETURN

Turn_Right:
FOR pulseCount = 0 TO 20
PULSOUT 13,837
PULSOUT 12,837
PAUSE 20
NEXT
RETURN

Back_Up:
FOR pulseCount = 0 TO 40
PULSOUT 13,678
PULSOUT 12,837
PAUSE 20
NEXT
RETURN

—————————————————————————————————————

Thanks, guys!

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-04-09 15:37
    If the detection distance is the issue this doesn't sound code related, but rather hardware related. Assuming you have the correct resistors on the IR LEDs I would run the IR Test program again and adjust the orientation of the LEDs and Detectors.
Sign In or Register to comment.