Shop OBEX P1 Docs P2 Docs Learn Events
Object Avoidance with the Ultrasonic Ping Sensor — Parallax Forums

Object Avoidance with the Ultrasonic Ping Sensor

lobolobo Posts: 100
edited 2007-03-10 00:26 in BASIC Stamp
Let me first set the scene:

I·build a mobilebot that has the following features:
  • 4 hb25 motor controllers
  • 4 motors with gears (they were taken out of those jeep electric toys that Walmart sales. My kids rode on them so they can handle up to 80-90 pounds)
  • 12 volts at 9.5 Amps an hour
  • 4 Vex bumpers or switches(2 bumpers and 2 switches).
  • 2 Ping Ultrasonic Sensor

This is basically my setup as of know. I will add later.

I'am not to good at Pbasic.Although I am a novice C++ programmer.

I dont want to use the roaming with ping right know. I find it to crowded.

I need something simple, such as:

If (Blank > 12) Then

PULSOUT aHB25, 650

PULSOUT bHB25, 650

PULSOUT cHB25, 750

PULSOUT dHB25, 750

But how do i get the info from the Ultrasonic Sensor· to make this program work.

Blank would have to be the name of the function or name of the variable that gets this done right?

I need something simple. I'm not asking nobody to write me a complete program--no no. I just need the command or short·formula to get the info from the sensor and put that in the IF (Blank > 12) .

Bottom line how is it done. Just a simple little formula.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-10 00:16
    Look at this article on measuring distance with the PING: www.parallax.com/dl/docs/prod/audiovis/Distance28015.pdf.

    It's from the PING product page. It shows you how to trigger the PING and get a number back from it (time to echo). The PING documentation (linked from the same product page) shows you how to convert this to centimeters or inches or whatever units you want which you could use in your IF statement. You will need to do this measurement periodically.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-10 00:19
    Hello,

    Right in the code for the PING))) Demo is the key to what you need to do…Stuff the code to read the PING))) and set the inches/cm variables and you’re set. When it returns you can do conditionals based on the values returned.
    GOSUB Get_Sonar                             ' get sensor value
    ' Make decisions here...
     
     
     
     
     
     
     
    Get_Sonar:
      Ping = IsLow                                  ' make trigger 0-1-0
      PULSOUT Ping, Trigger                         ' activate sensor
      PULSIN  Ping, IsHigh, rawDist                 ' measure echo pulse
      rawDist = rawDist */ Scale                    ' convert to uS
      rawDist = rawDist / 2                         ' remove return trip
      inches = rawDist ** RawToIn                   ' convert to inches
      cm = rawDist ** RawToCm                       ' convert to centimeters
      RETURN
    
     
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • lobolobo Posts: 100
    edited 2007-03-10 00:26
    thanks
Sign In or Register to comment.