Somebody said...
Since the calibration calculation only involves two constants, one can figure out what those are using two measurements from the unit. For details on how I got these formulas, see Derivation Of GP2D02 linearization formulas.
For the linearization formula
D = Kg/(X-Ko)
Kg is the gain, or overall shape of the curve described by Kg/X
Ko is an offset, shifting the curve up or down.
Let D and X be the distance and output, respectively of your first measurement.
Let D' and X' be the distance and output, respectively, of the second measurement.
Kg = (X'-X) D'D/(D-D')
Ko = (D'X' - DX)/(D' - D)
any help converting this to BS2 code would be much appreciated
This is c code but if you google for the device you will find more (possibly basic). Remember the minimum distance is 10cm and you must not read below that if you want correct results.
See if this is as helpful as I think it may be, even though it's a different Sharp I/R distance sensor, I suspect the linearization curve is the same, or nearly the same:
I suppose if worse turns to worst, you can always build some tables, and use a lookup to determine the appropriate distance from the data obtained from the sensor. Not "pretty" by any means, but it should work reasonably well.
val02 = val02 - 60 ' /* remove basic sensor offset */
IF (val02 < 1)THEN val02 = 1 ' /* avoid divide by zero */
ircm= 1500 / val02' /* hyperbolic conversion TO (rough) centimeters*/
Here is the code bit placed into the GP2D02 full code ( from acroname) with a dual reading from a Ping))). Let me know if you have or can tighten up the readings from the GP2D02..
Thanks to all.
' {$STAMP BS2}
' {$PBASIC 2.5}
'--------------------------------------------------------
Ping PIN 14
'-------[noparse][[/noparse]VARIABLES]-------------------------------
pingdist VAR Word 'Value where ping reading is stored
rawDist VAR Word ' raw measurement
ircm VAR Word 'gp2d02 distanc in centimeters
val02 VAR Byte ' value where reading is stored
'-------[noparse][[/noparse]CONSTANTS]-------------------------------
RawToCm CON $08D1 ' 1 / 29.034
Sdat CON 15 ' PSC Module
Trigger CON 5 ' trigger pulse = 10 uS
Scale CON $200 ' raw x 2.00 = uS
cl CON 4 ' pin 4 is output (clock)
dt CON 5 ' pin 5 is the input (data)
'--------------------------------------------------------
' I/O pin setup for detector
INPUT dt ' make pin 15 the input
HIGH cl ' make pin 14 output and high
'-------[noparse][[/noparse]MAIN CODE]-------------------------------
DEBUG CLS, ' setup report screen '|
"SENSORS VALUES", CR, '|
"-------------------", CR, '|
CR, '|
"raw IR", CR, '---------------------------------------------|line 3
"cm IR", CR, '--------------------------------------------|line 4
"ping", CR, '--------------------------------------------|line 5
CR
DO
GOSUB read02 ' call IR measurement routine
GOSUB Get_Sonar ' call sonar measurement routine
GOSUB readings ' call display routine
LOOP
END ' stop Stamp when done
'-------[noparse][[/noparse]SUBROUTINES]-----------------------------
'--------------------------------------------------------
' subroutine read02
'
' This subroutine takes a reading from the connected
' GP2D02 detector and stores the value in "val02".
' Any two pins can be used. Set "dt" to the data line
' of the GP2D02 (pin 4 on JST connector, yellow wire).
' Set cl to the clock line of the GP2D02 (pin 2 on the
' JST connector, green wire).
Get_Sonar:
PULSOUT Ping, Trigger ' activate sensor
PULSIN Ping, 1, rawDist ' measure ec:o pulse
rawDist = rawDist */ Scale ' convert to uS
rawDist = rawDist / 2 ' remove return trip
pingdist = rawDist ** RawToCm ' convert to centimeters
RETURN
read02:
LOW cl ' turn on detector for reading
rl:
IF IN5 = 0 THEN rl ' wait for input high
SHIFTIN dt, cl, MSBPOST, [noparse][[/noparse]val02]
HIGH cl ' turn detector off
val02 = val02 - 60 ' /* remove basic sensor offset */
IF (val02 < 1)THEN val02 = 1 ' /* avoid divide by zero */
ircm= 1500 / val02' /* hyperbolic conversion TO (rough) centimeters*/
RETURN
readings:
DEBUG CRSRXY, 15, 3,
DEC val02, CLREOL
DEBUG CRSRXY, 15, 4,
DEC ircm, CLREOL
DEBUG CRSRXY, 15, 5,
DEC pingdist, CLREOL
RETURN
If you look at the datasheet, it provides a linear function (1/(R+4)) Vs V where R is the range and V is the value from the ADC. You can use that to calculate the distance,
instead of using the Range Vs V. which is non linear.
Given that you can use the following formulae to get the distance:
R = (m' / (V + b')) - K
(m') and (b') are values you will need to determine by trial and error, as they depend on the sensor and the ADC you are using. (K) is equal to 4 for the GPD12
I am using a 10bit ADC and my m'=5930 and b'=3
You can try this by placing an object at a known distance from the sensor (preferably between 10 and 80cm) and reading the returned value (R) from the formulae. You can then adjust your m' and b' values, according to the expected distance. This is an empirical approach, but works very well.
The range here is in inch..but it is easy to convert this in cm.
I guess your question was about the GP2D02 which I beleive is no longer manufactured. The range is similar to the GP2D12. So the formulae above should work the same.
Used some of that code you wrote and added some from the other equation, I came up with this
read02:
LOW cl ' turn on detector for reading
rl:
IF IN5 = 0 THEN rl 'wait for input high
SHIFTIN dt, cl, MSBPOST, [noparse][[/noparse]IRCNT]
HIGH cl 'turn detector off
X =(((2251/(IRCNT-60))-4))
X =(((2251/(IRCNT-60))-4))
this code does the conversion into CM
IRCN is the readout from the GP2D02. it works ok but it is not spot on. still want a tighter reading.
if anyone can help tune up this equation please post.
thanks
I don't suppose you're going to like this answer, but be that as it may. The GP2D02 is now an obsolete sensor from what I understand. One of the reasons is certainly the difficulty that you're experiencing right now.
There are a number of other similar Sharp sensors, even some with digital output, which might ease this pain substantially. I've attached a Sharp Sensor Guide, although it is a few years out of date. Hope that is helpful.
Comments
http://www.parallax.com/dl/docs/cols/nv/vol5/col/nv114.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
255 being the dection of a very close item.
http://www.barello.net/Papers/GP2D02/index.htm
I just do not know how to turn it into bs2 code
any help converting this to BS2 code would be much appreciated
http://www.seattlerobotics.org/encoder/200112/gp2d02.html
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
See if this is as helpful as I think it may be, even though it's a different Sharp I/R distance sensor, I suspect the linearization curve is the same, or nearly the same:
http://www.acroname.com/robotics/info/articles/irlinear/irlinear.html
I suppose if worse turns to worst, you can always build some tables, and use a lookup to determine the appropriate distance from the data obtained from the sensor. Not "pretty" by any means, but it should work reasonably well.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
madlabs.info/gp2d12/sharp_gp2d12.shtml
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
home.twmi.rr.com/brouillette/gp2d02/GP2D02_convert3.xls
it converts the GP2D02 output into a Centimeter form, but it uses decimals and the BS2 can not handle that. can anyone see a way to convert this into BS2 code.
also this code
www.ottawarobotics.org/articles/gp2d02/gp2d02.html
www.cs.montana.edu/harkin/courses/cs445/topics/10-ir/lectures/slideset1.pdf
Post Edited (Special_K) : 8/11/2006 9:19:07 PM GMT
got the code from this site.
www.schoeldgen.de/robot/getdist.c
Here is the code bit placed into the GP2D02 full code ( from acroname) with a dual reading from a Ping))). Let me know if you have or can tighten up the readings from the GP2D02..
Thanks to all.
instead of using the Range Vs V. which is non linear.
See the datasheet http://www.acroname.com/robotics/parts/GP2D120_SS.pdf
Given that you can use the following formulae to get the distance:
R = (m' / (V + b')) - K
(m') and (b') are values you will need to determine by trial and error, as they depend on the sensor and the ADC you are using. (K) is equal to 4 for the GPD12
I am using a 10bit ADC and my m'=5930 and b'=3
You can try this by placing an object at a known distance from the sensor (preferably between 10 and 80cm) and reading the returned value (R) from the formulae. You can then adjust your m' and b' values, according to the expected distance. This is an empirical approach, but works very well.
The range here is in inch..but it is easy to convert this in cm.
X =(((2251/(IRCNT-60))-4))
this code does the conversion into CM
IRCN is the readout from the GP2D02. it works ok but it is not spot on. still want a tighter reading.
if anyone can help tune up this equation please post.
thanks
I don't suppose you're going to like this answer, but be that as it may. The GP2D02 is now an obsolete sensor from what I understand. One of the reasons is certainly the difficulty that you're experiencing right now.
There are a number of other similar Sharp sensors, even some with digital output, which might ease this pain substantially. I've attached a Sharp Sensor Guide, although it is a few years out of date. Hope that is helpful.
Regards,
Bruce Bates