Help need with Ping))) or IR object detection
Hi everyone,
I am designing my boe bot go race around a circuit. The circuit has borders on the outside and the inside so the boe bot can remain within those borders (using QTIs).
The main problem I am having is detecting and avoiding the objects. I'm using the Ping Dar (without the mounting bracket and servo) to detect and avoid the objects.
Since I do not have a mounting bracket and servo, I made the boe bot partially turn left then center then to the right to obtain the largest distance. However, when the
boe bot detects the object, it continuously goes left center , center - right and it never seems to go the direction with the longest distance.
My other alternative is to use the IR setup to detect and avoid the objects, but I know the other boe bots will use IR jammers to interfere with my bot's detection. I attempted
to incorporate the IR Roaming with IR sniffer provided in the Robotics book. However, the boe bot simply stops and makes a sound when it dectects IR interference, which is
not efficient enough for the race (The bot would be forever stopping )
Can anyone kindly help me with fixing the Ping Dar code or finding a method using IRs that cannot be easily disrupt by jammers?
Here is my code for the Ping Dar )))..I used the RoamingWithPING.bs2 as a guideline.
The code is not complete. I am trying to get the Ping Dar to work.
Your speedy and favorable response will be greatly appreciated.
Scorpio
I am designing my boe bot go race around a circuit. The circuit has borders on the outside and the inside so the boe bot can remain within those borders (using QTIs).
The main problem I am having is detecting and avoiding the objects. I'm using the Ping Dar (without the mounting bracket and servo) to detect and avoid the objects.
Since I do not have a mounting bracket and servo, I made the boe bot partially turn left then center then to the right to obtain the largest distance. However, when the
boe bot detects the object, it continuously goes left center , center - right and it never seems to go the direction with the longest distance.
My other alternative is to use the IR setup to detect and avoid the objects, but I know the other boe bots will use IR jammers to interfere with my bot's detection. I attempted
to incorporate the IR Roaming with IR sniffer provided in the Robotics book. However, the boe bot simply stops and makes a sound when it dectects IR interference, which is
not efficient enough for the race (The bot would be forever stopping )
Can anyone kindly help me with fixing the Ping Dar code or finding a method using IRs that cannot be easily disrupt by jammers?
Here is my code for the Ping Dar )))..I used the RoamingWithPING.bs2 as a guideline.
The code is not complete. I am trying to get the Ping Dar to work.
Your speedy and favorable response will be greatly appreciated.
Scorpio
' {$STAMP BS2} ' Target device = BASIC Stamp 2
' {$PBASIC 2.5} ' Language = PBASIC 2.5
' -----[ I/O Definitions & Constants ]-------------------------------------------------
Ping PIN 15 ' PING))) Sensor
Piezo PIN 3 ' Piezo Speaker
' -----[ Variables ]------------------------------------------------------------------------
pulseCount VAR Byte ' FOR..NEXT loop counter for turning
qtis VAR Nib ' QTI black/white states
LastMove VAR Nib 'Remembers the last move boe bot made
'LastMove: 2-forward, 6-forward and left, 3-forward and right
Turn VAR Nib ' Current Task
pulseLeft VAR Word
pulseRight VAR Word
distance VAR Word ' Current Distance Of Object
oldDistance VAR Word ' Old Distance Value
attempt VAR Word ' Keeps count of the number of attempts made
counter VAR Word ' PING))) Cycle Counter
' -----[ Initialization ]-------------------------------------------------------------------
OUTB = 11 ' Set OUTB bits to 1
FREQOUT Piezo, 1000, 2000 ' Battery Tester
LastMove = 2 'Forward
distance = 30
' -----[ Main Routine ]---------------------------------------------------------------------
'Main:
DO ' Main DO...LOOP
' Get QTI states
DIRB = 11 ' P7..P4 -> output
PAUSE 0 ' Delay = 230 us
DIRB = 00 ' P7..P4 -> input
PAUSE 0 ' Delay = 230 us
qtis = INB ' Store QTI outputs in INB
SELECT qtis
CASE 00
GOSUB Ping_Out ' PING)))-- Scan For objects in pathway
IF (distance > 30) THEN
GOSUB Forward ' If Yes Go Forward
ELSE
GOSUB Decide_Turn
ENDIF
ENDSELECT
PULSOUT 13,pulseLeft ' Apply the pulses.
PULSOUT 12,pulseRight
PAUSE 15
LOOP
' -----[ Subroutines - Turn_Check ]---------------------------------------------------------
Ping_Out: ' PING)))
LOW Ping ' Force PING))) Line Low
PULSOUT Ping, 5 ' Activate PING))) Pulse
PULSIN Ping, 1, distance ' Receive Return Pulse
distance = distance ** 2257 ' Calculate Distance In cm
RETURN
'NOTE: THE SUBROUTINES CONTAIN ALL POSSIBLE MANEUVERS FOR THE BOE BOT SERVOS
' SOME MAY NOT BE USED IN THE PARTICULAR PROGRAM
' -----[ Subroutines - Forward ]---------------------------------------------------------
Forward:
pulseLeft = 850
pulseRight = 663
RETURN
' -----[ Subroutines - Rotate_Left ]---------------------------------------------------------
Rotate_Left:
pulseLeft = 650
pulseRight = 650
RETURN
' -----[ Subroutines - Rotate_Right ]---------------------------------------------------------
Rotate_Right:
pulseLeft = 850
pulseRight = 850
RETURN
' -----[ Subroutines - Backup ]---------------------------------------------------------
Backup:
PULSOUT 13, 650 ' Left Servo Backup Pulse Value
PULSOUT 12, 850 ' Right Servo Backup Pulse Value
RETURN
Stop_Moving:
PULSOUT 13, 750
PULSOUT 12, 750
RETURN
Decide_Turn:
oldDistance = 30 ' Current Old Distance Values
Turn = 0
GOSUB Stop_Moving
FOR pulseCount = 0 TO 10
LOW Ping
PULSOUT 13,650 'Turns Boe Bot to the left
PULSOUT 12,650
PAUSE 20 ' Refresh Delay
NEXT
PULSOUT Ping, 5 ' Activate PING)))
PULSIN Ping, 1, distance ' Receive Distance Value
distance = distance ** 2257 ' Calculate Distance In cm
IF distance > oldDistance THEN ' Is distance > Last Clear Path
oldDistance = distance ' Update oldDistance Value
Turn = 0
ENDIF
FOR pulseCount = 0 TO 10
PULSOUT 13,850 'Turns Boe Bot to the right to return to center
PULSOUT 12,850
NEXT
FOR pulseCount = 0 TO 10
LOW Ping
PULSOUT 13,850 'Turns Boe Bot to the Right
PULSOUT 12,850
PAUSE 20 ' Refresh Delay
NEXT
PULSOUT Ping, 5 ' Activate PING)))
PULSIN Ping, 1, distance ' Receive Distance Value
distance = distance ** 2257 ' Calculate Distance In cm
IF distance > oldDistance THEN ' Is distance > Last Clear Path
oldDistance = distance ' Update oldDistance Value
Turn = 1
ENDIF
FOR pulseCount = 0 TO 10
PULSOUT 13,650 'Turns Boe Bot to the left to return to center
PULSOUT 12,650
NEXT
ON Turn GOSUB Task0, Task1
distance = 50
RETURN
Task0:
'Furthest distance dectected on the left
FOR pulseCount = 0 TO 10
PULSOUT 13,650 'Turns Boe Bot to the left to return to center
PULSOUT 12,650
NEXT
Task1:
'Furthest distance dectected on the left
FOR pulseCount = 0 TO 10
PULSOUT 13,850 'Turns Boe Bot to the left to return to center
PULSOUT 12,850
NEXT

Comments
Here is the updated source code.
' {$STAMP BS2} ' Target device = BASIC Stamp 2 ' {$PBASIC 2.5} ' Language = PBASIC 2.5 ' -----[ I/O Definitions & Constants ]------------------------------------------------- Ping PIN 15 ' PING))) Sensor Piezo PIN 3 ' Piezo Speaker ' -----[ Variables ]------------------------------------------------------------------------ pulseCount VAR Byte ' FOR..NEXT loop counter for turning qtis VAR Nib ' QTI black/white states LastMove VAR Nib 'Remembers the last move boe bot made 'LastMove: 2-forward, 6-forward and left, 3-forward and right Turn VAR Nib ' Current Task pulseLeft VAR Word pulseRight VAR Word distance VAR Word ' Current Distance Of Object oldDistance VAR Word ' Old Distance Value attempt VAR Word ' Keeps count of the number of attempts made counter VAR Word ' PING))) Cycle Counter ' -----[ Initialization ]------------------------------------------------------------------- OUTB = 11 ' Set OUTB bits to 1 FREQOUT Piezo, 1000, 2000 ' Battery Tester LastMove = 2 'Forward distance = 30 ' -----[ Main Routine ]--------------------------------------------------------------------- Main: DO ' Main DO...LOOP ' Get QTI states DIRB = 11 ' P7..P4 -> output PAUSE 0 ' Delay = 230 us DIRB = 00 ' P7..P4 -> input PAUSE 0 ' Delay = 230 us qtis = INB ' Store QTI outputs in INB SELECT qtis CASE 00 GOSUB Ping_Out ' PING)))-- Scan For objects in pathway IF (distance > 30) THEN GOSUB Forward ' If Yes Go Forward ELSE GOSUB Decide_Turn ENDIF ENDSELECT PULSOUT 13,pulseLeft ' Apply the pulses. PULSOUT 12,pulseRight PAUSE 17 LOOP ' -----[ Subroutines - Turn_Check ]--------------------------------------------------------- Ping_Out: ' PING))) LOW Ping ' Force PING))) Line Low PULSOUT Ping, 5 ' Activate PING))) Pulse PULSIN Ping, 1, distance ' Receive Return Pulse distance = distance ** 2257 ' Calculate Distance In cm RETURN ' -----[ Subroutines - Forward ]--------------------------------------------------------- Forward: pulseLeft = 850 pulseRight = 663 PAUSE 17 RETURN ' -----[ Subroutines - Rotate_Left ]--------------------------------------------------------- Rotate_Left: pulseLeft = 650 pulseRight = 650 PAUSE 17 RETURN ' -----[ Subroutines - Rotate_Right ]--------------------------------------------------------- Rotate_Right: pulseLeft = 850 pulseRight = 850 PAUSE 17 RETURN ' -----[ Subroutines - Backup ]--------------------------------------------------------- Backup: PULSOUT 13, 650 ' Left Servo Backup Pulse Value PULSOUT 12, 850 ' Right Servo Backup Pulse Value PAUSE 17 RETURN Stop_Moving: PULSOUT 13, 750 PULSOUT 12, 750 PAUSE 17 RETURN Decide_Turn: oldDistance = 30 ' Current Old Distance Values Turn = 0 GOSUB Stop_Moving FOR pulseCount = 0 TO 10 LOW Ping PULSOUT 13,650 'Turns Boe Bot to the left PULSOUT 12,650 PAUSE 17 ' Refresh Delay NEXT PULSOUT Ping, 5 ' Activate PING))) PULSIN Ping, 1, distance ' Receive Distance Value distance = distance ** 2257 ' Calculate Distance In cm IF distance > oldDistance THEN ' Is distance > Last Clear Path oldDistance = distance ' Update oldDistance Value Turn = 0 ENDIF FOR pulseCount = 0 TO 10 PULSOUT 13,850 'Turns Boe Bot to the right to return to center PULSOUT 12,850 PAUSE 17 NEXT FOR pulseCount = 0 TO 10 LOW Ping PULSOUT 13,850 'Turns Boe Bot to the Right PULSOUT 12,850 PAUSE 17 ' Refresh Delay NEXT PULSOUT Ping, 5 ' Activate PING))) PULSIN Ping, 1, distance ' Receive Distance Value distance = distance ** 2257 ' Calculate Distance In cm IF distance > oldDistance THEN ' Is distance > Last Clear Path oldDistance = distance ' Update oldDistance Value Turn = 1 ENDIF FOR pulseCount = 0 TO 10 PULSOUT 13,650 'Turns Boe Bot to the left to return to center PULSOUT 12,650 PAUSE 17 NEXT ON Turn GOSUB Task0, Task1 distance = 50 RETURN Task0: 'Furthest distance dectected on the left FOR pulseCount = 0 TO 10 PULSOUT 13,650 'Turns Boe Bot to the left to return to center PULSOUT 12,650 PAUSE 17 NEXT RETURN Task1: 'Furthest distance dectected on the left FOR pulseCount = 0 TO 10 PULSOUT 13,850 'Turns Boe Bot to the left to return to center PULSOUT 12,850 PAUSE 17 NEXT RETURNYou might consider getting a ServoPal which will take over the production of the servo pulses and relieve the tight timing constraints on your program.
I also have a BPW77NA Phototransistor http://www.vishay.com/docs/81527/bpw77n.pdf. Can this also be used to detect 36Khz or 40Khz IR signals?