Shop OBEX P1 Docs P2 Docs Learn Events
Help! How to detect obstacles using ping))), and making the servos turn for avoidance — Parallax Forums

Help! How to detect obstacles using ping))), and making the servos turn for avoidance

kolaikolai Posts: 9
edited 2011-02-11 02:45 in Accessories
Hello everyone, I'm a newbie on obstacle sensing using the ping))) sensor. I'm trying to make obstacle sensing boe - bot w/ 3 sensors, namely 2 - IR emitter & Receiver and the ping))) sensor. I didn't attach the ping sensor to the servo because the purpose of the ping sensor is only to detect forward obstacles and the IRs for the left and right obstacles. I really just can't get it to work, I've used the 2 IRs and it went well. What I want next is to add a middle sensor('ping)))') to detect forward obstacles, but as I try to study the codes from 'Mini Projects', I get so confused on how to use it, and even the 'RoamingWithPing.bs2' gave me a headache.

Please Help. :blank:

Here is my code:confused:

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

DEBUG " Program Running! "

irDetectLeft VAR Bit
irDetectRight VAR Bit

cmConstant CON 2260
pulseLeft VAR Word
pulseRight VAR Word
distance VAR Byte
cmFinal VAR Byte

FREQOUT 4, 30, 5000

GOSUB Read_Ping
GOSUB Calc_Distance

DO

IF (cmFinal < 3) THEN
pulseLeft = 650
pulseRight = 850

FREQOUT 8, 1, 38500
irDetectRight = IN0

FREQOUT 9, 1, 38500
irDetectLeft = IN10


ELSEIF (irDetectRight = 0) AND (irDetectLeft = 1)THEN
pulseLeft = 650
pulseRight = 650
HIGH 1

ELSEIF (irDetectRight = 1) AND (irDetectLeft = 0)THEN
pulseLeft = 850
pulseRight = 850
HIGH 15

ELSE
pulseLeft = 850
pulseRight = 650
LOW 1
LOW 15

ENDIF

Read_Ping:
PULSOUT 3, 5 ' Start Ping)))
PULSIN 3, 1, distance ' Read echo time
RETURN

Calc_Distance:
cmFinal = cmConstant ** distance ' These are the whole measurements


PULSOUT 13, pulseLeft
PULSOUT 12, pulseRight
PAUSE 20

LOOP


Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-02-03 08:17
    "Roaming with PING" may give you a headache, but you have to understand how it works and how the IR Roaming program in the Robotics manual works.

    There are only a few conditions possible. The right IR detector can detect something (or not). The left IR detector can detect something (or not). The PING can detect something (or not). That's only 8 possibilities. First you have to define what you want your robot to do under those 8 combinations of conditions. It's simpler than that because some of the 8 possibilities are mirror images of each other (left vs. right) and, in some cases, there are "don't care" conditions. Work out those 8 combinations and the robot's actions associated with each one and let us know what you come up with.
  • kolaikolai Posts: 9
    edited 2011-02-03 15:07
    Thank you very much Mike, I'll work on it.
  • kolaikolai Posts: 9
    edited 2011-02-03 21:16
    sir mike, what would be its algorithm if your ging to use the 3 sensors for maze traversal.
    Plwase Help
  • kolaikolai Posts: 9
    edited 2011-02-11 02:45
    Trying to solve this kind of problem was really hard for me:
    and finally i got it.

    Its a prototype but it works;
    {$STAMP BS2}
    ' {$PBASIC 2.5}

    time VAR Word
    cm VAR Word
    in VAR Word
    ft VAR Word
    cmcons CON 2260
    incons CON 890
    ftcons CON 74

    counter VAR Byte
    irDetectLeft VAR Bit
    irDetectRight VAR Bit

    DO

    PULSOUT 15, 5
    PULSIN 15, 1, time


    cm = cmcons ** time
    in = incons ** time
    ft = ftcons ** time

    FREQOUT 9, 1, 38500 ' Check IR Detectors
    irDetectLeft = IN10

    FREQOUT 8, 1, 38500
    irDetectRight = IN0


    DEBUG HOME, "time = ", DEC5 time
    DEBUG CR, "cm = ", DEC3 cm, "cm"
    DEBUG CR, "in = ", DEC3 in, "in"
    DEBUG CR, "ft = ", DEC3 ft, "ft"

    IF (((in = 3) AND (cm = 8)) OR (in = 2) OR (in = 1) ) THEN 'distances which the ping will react
    FREQOUT 4, 200, 7000
    GOSUB Back_pulse
    GOSUB Right_pulse
    GOSUB Right_pulse
    GOSUB Right_pulse


    ELSEIF (irDetectLeft = 0) AND (irDetectRight = 0)THEN
    GOSUB Forward_pulse
    HIGH 1
    HIGH 11



    ELSEIF (irDetectLeft = 0)THEN
    GOSUB Back_pulse
    GOSUB Right_pulse
    HIGH 11


    ELSEIF (irDetectRight = 0) THEN
    GOSUB Back_pulse
    GOSUB Left_pulse
    HIGH 1

    ELSEIF (irDetectLeft = 1) AND (irDetectRight = 1)THEN
    GOSUB End_pulse
    LOW 1
    LOW 11

    ELSE
    LOW 1
    LOW 11
    PULSOUT 13, 850
    PULSOUT 12, 650
    PAUSE 15

    PAUSE 100


    ENDIF

    LOOP

    Forward_pulse:
    FOR counter = 0 TO 7
    PULSOUT 13, 850
    PULSOUT 12, 600
    PAUSE 20
    NEXT
    RETURN

    Right_pulse:
    FOR counter = 0 TO 3
    PULSOUT 13, 850
    PULSOUT 12, 850
    PAUSE 20
    NEXT
    RETURN

    Left_pulse:
    FOR counter = 0 TO 3
    PULSOUT 13, 650
    PULSOUT 12, 650
    PAUSE 20
    NEXT
    RETURN

    Back_pulse:

    PULSOUT 13, 650
    PULSOUT 12, 850
    PAUSE 15

    RETURN


    Stop_pulse:
    PULSOUT 13, 750
    PULSOUT 12, 750
    PAUSE 50
    RETURN

    End_pulse:
    FOR counter = 0 TO 5
    PULSOUT 13, 850
    PULSOUT 12, 600
    PAUSE 50
    NEXT

    RETURN

    Code:
Sign In or Register to comment.