Shop OBEX P1 Docs P2 Docs Learn Events
Hepl with PING)) — Parallax Forums

Hepl with PING))

LAZachLAZach Posts: 3
edited 2012-06-25 14:21 in Accessories
I bought a Boe-Bot with a Rev J chip and I've had the hardest time getting the PING)) programs to work properly. First, the program to run the PING)) with encoders wouldn't work properly until I changed the advanceForward subroutine by adding a pause 30. Now I am trying to run the RoamingWithPing program with my IR sensors and it wont got forward, it just turns either the right or left. I need help please!!!!

Comments

  • FranklinFranklin Posts: 4,747
    edited 2012-05-18 21:50
    I've had the hardest time getting the PING)) programs to work properly
    have you tried any of the PING))) demo code (without any other code to corrupt the results? Have you checked to see what the PING))) is sending to the debug terminal? Have you tried the IR sensors alone? Let us know.
  • xanaduxanadu Posts: 3,347
    edited 2012-05-19 13:21
    Copy and paste code here.
    
    
  • LAZachLAZach Posts: 3
    edited 2012-05-24 16:50
    Here is the code that I used, when I run the program my robot wont go forward, just turns back and forth.

    ' RoamingWithPING.bs2
    ' Roam And Scan Using PING))) Mounting Bracket

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

    '
    [ I/O Definitions ]

    Piezo PIN 4
    RightServo PIN 12
    LeftServo PIN 13
    PingServo PIN 14
    Ping PIN 15

    '
    [ Variables ]

    irDetectLeft VAR Bit
    irDetectRight VAR Bit
    pulseCount VAR Byte
    distance VAR Word
    oldDistance VAR Word
    counter VAR Word
    task VAR Nib

    '
    [ Initialization ]

    FREQOUT Piezo, 2000, 3000

    '
    [ Program Code ]

    Main:
    DO

    FREQOUT 8, 1, 38500
    irDetectLeft = IN9

    FREQOUT 2, 1, 38500
    irDetectRight = IN0

    IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
    GOSUB Ping_Around
    ELSEIF (irDetectLeft = 0) THEN
    GOSUB Ping_Around
    ELSEIF (irDetectRight = 0) THEN
    GOSUB Ping_Around
    ENDIF

    counter = counter + 1

    IF counter > 10 THEN
    GOSUB Ping_Out
    ENDIF

    IF (distance > 30) THEN
    GOSUB Forward_Pulse
    ELSE
    GOSUB Ping_Around
    ENDIF

    LOOP

    '
    [ Subroutines ]

    Forward_Pulse:
    PULSOUT PingServo, 750
    PULSOUT LeftServo, 850
    PULSOUT RightServo, 650
    PAUSE 20
    RETURN

    Turn_Left:
    FOR pulseCount = 0 TO 7
    PULSOUT PingServo, 750
    PULSOUT LeftServo, 650
    PULSOUT RightServo, 650
    PAUSE 20
    NEXT
    RETURN

    Turn_Right:
    FOR pulseCount = 0 TO 7
    PULSOUT PingServo, 750
    PULSOUT LeftServo, 850
    PULSOUT RightServo, 850
    PAUSE 20
    NEXT
    RETURN

    Back_Up:
    FOR pulseCount = 0 TO 40
    PULSOUT PingServo, 750
    PULSOUT LeftServo, 650
    PULSOUT RightServo, 850
    PAUSE 20
    NEXT
    RETURN

    Ping_Out:
    counter = 0
    LOW Ping
    PULSOUT Ping, 5
    PULSIN Ping, 1, distance
    distance = distance ** 2257
    RETURN

    Ping_Around:
    counter = 0
    oldDistance = 30
    task = 0

    FOR pulseCount = 0 TO 20
    LOW Ping
    PULSOUT PingServo, 1085
    PULSOUT Ping, 5
    PULSIN Ping, 1, distance
    PAUSE 20
    NEXT

    distance = distance ** 2257
    IF distance > oldDistance THEN
    oldDistance = distance
    task = 1
    ENDIF

    FOR pulseCount = 0 TO 20
    LOW Ping
    PULSOUT PingServo, 850
    PULSOUT Ping, 5
    PULSIN Ping, 1, distance
    PAUSE 20
    NEXT

    distance = distance ** 2257
    IF distance > oldDistance THEN
    oldDistance = distance
    task = 2
    ENDIF

    FOR pulseCount = 0 TO 20
    LOW Ping
    PULSOUT PingServo, 400
    PULSOUT Ping, 5
    PULSIN Ping, 1, distance
    PAUSE 20
    NEXT

    distance = distance ** 2257
    IF distance > oldDistance THEN
    oldDistance = distance
    task = 3
    ENDIF

    FOR pulseCount = 0 TO 20
    LOW Ping
    PULSOUT PingServo, 225
    PULSOUT Ping, 5
    PULSIN Ping, 1, distance
    PAUSE 20
    NEXT

    distance = distance ** 2257
    IF distance > oldDistance THEN
    oldDistance = distance
    task = 4
    ENDIF

    ON task GOSUB Task0, Task1, Task2, Task3, Task4

    distance = 50

    RETURN

    Task0:
    GOSUB Turn_Right
    GOSUB Turn_Right
    GOSUB Turn_Right
    GOSUB Turn_Right
    RETURN

    Task1:
    GOSUB Turn_Left
    GOSUB Turn_Left
    RETURN

    Task2:
    GOSUB Turn_Left
    RETURN

    Task3:
    GOSUB Turn_Right
    RETURN

    Task4:
    GOSUB Turn_Right
    GOSUB Turn_Right
    RETURN
  • Nick ErnstNick Ernst Posts: 138
    edited 2012-05-25 10:28
    LAzach,
    That code has some issues, I tried running it on one of my bots just to see if it would work, and no joy! Run this code, and you will be roaming around your house in no time!

    http://www.parallax.com/Portals/0/Downloads/src/prod/RoamingWithPING-Simple-V1.0.zip


    -Nick
  • LAZachLAZach Posts: 3
    edited 2012-06-25 14:21
    Nick,
    Thank you that program worked great!!!!!

    LAZach
Sign In or Register to comment.