Shop OBEX P1 Docs P2 Docs Learn Events
Ping Sensor — Parallax Forums

Ping Sensor

Tru CustomTru Custom Posts: 13
edited 2013-08-13 12:59 in BASIC Stamp
Hi All,
I am working with the BOE and Ping sensor, I am trying to get the piezo speaker to respond to a minimal distance detected.
The attached program works fine and displays in the DEBUG screen. I commented out my attempt to use an IF-THEN statement.
I am working as a student instructor for robot camp and we are developing some final projects that supports various disabilities.

The completed assembly will be attached to a cane and will respond to objects using a FREQOUT syntax. Once it is working, the goal becomes to vary the frequency based on the distance so the individual can navigate safely around obstacles.

Any help would be most appreciated.

Best regards, Tru

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-08-13 12:33
    I'd suggest figuring out what the distances and frequencies should be at your extremes and use the values for x1, y1 and x2, y2 in order to find the equation of a line which contain these endpoints. In you linear equation, "y" would be the frequency to play and "x" would be the distance.

    Rather than using the distance as "x" you could modify the original equation (the one which figures out the distance) and have it compute a frequency from the pulse time instead of distance. You need a value for "scale". You may need to rearrange the equation a bit if you want the frequency to decrease as the range increases.

    It would probably be simpler to use the distance in a second equation rather than modifying the original equation.

    The integer math limitation of the BS2 may require the equation you come up with to be rearranged in order to reduce the effects of rounding errors.

    What frequency range do you want to use? What rules to you want applied (i.e. are there limits you want placed on the frequency)?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-08-13 12:59
    I was guessing at some numbers. If you wanted a 5,000Hz tone at a distance of 250cm and a 200Hz tone at 25cm, you would multiply the value of "cm" by -21 (should be -21.3).

    Add a variable for "freq".
    freq            VAR     Word
    

    Then before the "LOOP" statement" add the following code.
    freq = (cm * -21) + 5533
       FREQOUT 6, freq, 250                      ' piezo attached to pin 6
       PAUSE 250
    


    I'm not sure if I have the syntax correct of not (I don't use Basic Stamps much) but hopefully if it's not right it will give you the general idea.

    Edit: I had forgot to add the intercept to the equation.
Sign In or Register to comment.