Shop OBEX P1 Docs P2 Docs Learn Events
Need help with odd behavior from Ping code — Parallax Forums

Need help with odd behavior from Ping code

puckvegapuckvega Posts: 2
edited 2008-01-27 23:26 in Robotics
I recently started playing around with a Boe Bot and am running into trouble with my Ping sensor.· I have searche dthrough all the documentation and posts I could find but can't find anything that explains the behavior I am getting.· Here is the situation -

The code below always results in a ping_dist of 0

· IF (avoid_timer // 66 = 0) THEN
··· LOW PING
··· PULSOUT PING, 5
··· PULSIN· PING, 1, ping_dist
· ENDIF

The section of·code runs roughly every 3-3.5 seconds as timed by debug statements and a stopwatch.

If I modify the code (shown below) by adding a pause of 15 or more, ping_dist is populated just fine

· IF (avoid_timer // 66 = 0) THEN
··· PAUSE 15
··· LOW PING
··· PULSOUT PING, 5
··· PULSIN· PING, 1, ping_dist
· ENDIF

There are no other sections of code that send a pulse out or read a pulse in from the Ping.· I feel like I must be missing something very obvious but I can't understand why·this is happening.· Any thoughts or help would be greatly appreciated.·

Comments

  • puckvegapuckvega Posts: 2
    edited 2008-01-27 23:23
    Nevermind ... I knew it was something obvious.· Replaced the batteries and·the first piece of code works perfectly.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-01-27 23:26
    The maximum pulse time for the PING is around 20ms. If this section of code is called rapidly in succession, the PING may not be ready to do the next ranging pulse and will not provide an input pulse for the PULSIN and ping_dist will be zero.

    1) If you're calling this section of code multiple times, you'll need the PAUSE and it probably should actually be at least 18ms.

    2) If you're only calling it once every few seconds, something is odd because it's behaving as if you're calling it rapidly at least twice.
Sign In or Register to comment.