Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: santiagoe on March 24, 2007, 11:01:02 PM

Title: Sharp range finders
Post by: santiagoe on March 24, 2007, 11:01:02 PM
which Sharp GP2D range finder does Admin use on his fuzzy robot that uses 3 sharp sensors
is it :
sharp gpd120 ir sensor
gp2d12
gp2d15
gp2y0D02yk
gp2y0A02yk

i am using a basic stamp2 at the moment. i will soon move on to the ARM7 or AVR but right know i am trying to figure out how to work some of the sensors with my prototype. I build a 4 wheel drive mobile bot that's about 4' and 1/2 inches. I has 2 sonars, 4 hb25 motor controllers by parallax, 4 motors with their gears taken from those jeep electric cars they sale in walmart for kids up to 80 pounds. the 2 irled/detector pair doesn't work to good this is why I'm considering sharp range finder but i dont know witch one to use. i really need one that can detect 30" or more. i gave up on trying to connect two ultrasonic ping sonars because nobody could show me with a program in pbasic how to use two or more sonars so sadly I'm just using one. if anybody could post a working pbasic program for 2 or more ultrasonic ping sonars i would appreciated.

but if ya could please tell me which sharp to use.

thank you
Title: Re: Sharp range finders
Post by: dunk on March 25, 2007, 02:42:56 AM
there's a good summary of the sharp IR units here:
http://www.acroname.com/robotics/info/articles/sharp/sharp.html (http://www.acroname.com/robotics/info/articles/sharp/sharp.html)

as for getting more than one sonar sensor to work on your controller, it should be the same as getting one to work.
just remember you will need to leave a little time delay between taking the readings from the first one and the 2nd to allow any echos from the first "ping" to die down.

dunk.
Title: Re: Sharp range finders
Post by: Steve Joblin on March 25, 2007, 06:05:54 AM
I don't understand why you can't hook up two (or any amount) Ping))) sensors.  There are three wires coming out of each Ping... tie all the "ground" leads together (and to to Vss on the Stamp), tie all the "power" leads together (and to Vdd on the Stamp), and tie each of the "Signal" leads to a different I/O pin on the the stamp.

The attached program uses two Pings... the "signal" of one is tied to pin 14 and the "signal" of the other is tied to pin 15.
Title: Re: Sharp range finders
Post by: santiagoe on March 25, 2007, 04:26:36 PM
Hey i want to say thank you for the program it looks like it works. But how can i get the debug window to show the readings for Ping a and Ping b at the same time?

At the moment i cant really tell what the readings are for each one because its just one centimeter, inches, ect....

However i know it works because when i put my hand over each one the reading change even though they appear to be incorrect.

and when i modified the program to control two motors when either inchesA or inchesB (<24) to go either reverse or left when i put my hand over each one it responded accurately.

but the readings i think are off as far as on the debug windows because it is reading and posting the info for two.

Thus,  i ask if it is possible to display the info for two pings on the debug window such as PingA then its readings and next to it PingB and its readings. If yes how?

Here is the program you send me with the relevant changes:

' =========================================================================
'
'   File....... Ping_Demo.BS2
'   Purpose.... Demo Code for Parallax Ping Sonar Sensor
'   Author..... Jon Williams -- Parallax, Inc.
'   E-mail..... [email protected]
'   Started....
'   Updated.... 08 JUN 2005
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This program demonstrates the use of the Parallax Ping Sonar sensor and
' converting the raw measurement to English (inches) and Metric (cm) units.
'
' Sonar Math:
'
' At sea level sound travels through air at 1130 feet per second.  This
' equates to 1 inch in 73.746 uS, or 1 cm in 29.034 uS).
'
' Since the Ping sensor measures the time required for the sound wave to
' travel from the sensor and back.  The result -- after conversion to
' microseconds for the BASIC Stamp module in use -- is divided by two to
' remove the return portion of the echo pulse.  The final raw result is
' the duration from the front of the sensor to the target in microseconds.


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------
PingA            PIN     11
PingB            PIN     10
cHB25            PIN     14
dHB25            PIN     15
' -----[ Constants ]-------------------------------------------------------
Trigger         CON     5                       ' trigger pulse = 10 uS
Scale           CON     $200                    ' raw x 2.00 = uS

RawToIn         CON     889                     ' 1 / 73.746 (with **)
RawToCm         CON     2257                    ' 1 / 29.034 (with **)

IsHigh          CON     1                       ' for PULSOUT
IsLow           CON     0

' -----[ Variables ]-------------------------------------------------------
rawDistA         VAR     Word                    ' raw measurement
rawDistB         VAR     Word                    ' raw measurement
inchesA          VAR     Word
inchesB          VAR     Word
cmA              VAR     Word
cmB              VAR     Word

' -----[ EEPROM Data ]-----------------------------------------------------


' -----[ Initialization ]--------------------------------------------------

Reset:
  DEBUG CLS,                                    ' setup report screen
        "Parallax Ping Sonar  ", CR,
        "=====================", CR,
        CR,
        "Time (uS).....       ", CR,
        "Inches........       ", CR,
        "Centimeters.........       ",CR


' -----[ Program Code ]----------------------------------------------------

Main:
  DO
    GOSUB Get_Sonars                            ' get sensor value
    inchesA = rawDistA ** RawToIn                 ' convert to inches
    inchesB = rawDistB ** RawToIn                 ' convert to inches
    cmA = rawDistA ** RawToCm                     ' convert to centimeters
    cmB = rawDistB ** RawToCm                     ' convert to centimeters
    DEBUG CRSRXY, 11, 3,                        ' update report screen
          DEC rawDistA, CLREOL,
          DEC rawDistB, CLREOL,
          CRSRXY, 11, 4,
          DEC inchesA, CLREOL,
          DEC inchesB, CLREOL,
          CRSRXY, 11, 5,
          DEC cmA, CLREOL,
          DEC cmB, CLREOL
    PAUSE 100

IF (inchesA <24)  THEN

   'go left

PULSOUT cHB25,850
PULSOUT dHB25,850

ELSEIF (inchesB <24)  THEN

   'go reverse

PULSOUT cHB25, 850
PULSOUT dHB25, 650
ENDIF
  LOOP
  END


' -----[ Subroutines ]-----------------------------------------------------

' This subroutine triggers the Ping sonar sensor and measures
' the echo pulse.  The raw value from the sensor is converted to
' microseconds based on the Stamp module in use.  This value is
' divided by two to remove the return trip -- the result value is
' the distance from the sensor to the target in microseconds.

Get_Sonars:
  PingA = IsLow                                  ' make trigger 0-1-0
  PULSOUT PingA, Trigger                         ' activate sensor
  PULSIN  PingA, IsHigh, rawDistA                 ' measure echo pulse
  rawDistA = rawDistA */ Scale                    ' convert to uS
  rawDistA = rawDistA / 2                         ' remove return trip
  PAUSE 100                                        'pause between PingA and PingB so the sonar signals can dicipate.
  PingB = IsLow                                  ' make trigger 0-1-0
  PULSOUT PingB, Trigger                         ' activate sensor
  PULSIN  PingB, IsHigh, rawDistB                 ' measure echo pulse
  rawDistB = rawDistB */ Scale                    ' convert to uS
  rawDistB = rawDistB / 2                         ' remove return trip
RETURN