DPRG List  

[DPRG] SHARP IR Range Detector Calibration and Conversion

Subject: [DPRG] SHARP IR Range Detector Calibration and Conversion
From: David Anderson davida at smu.edu
Date: Fri Mar 7 13:40:44 CST 2014

Hello DPRG Robot Builders,

I was asked last week about the calibration and conversion technique for 
SHARP IR range detectors, like the GP2Y0A02Y and its brothers. For those 
unfamiliar, these are analog devices which use parallax measurements to 
return an analog voltage, usually read with an A/D converter, that 
corresponds to distances out to about 20 inches (more for the higher 
power units).

The calibration and conversion math for all the units is the same. 
Essentially you calibrate by taking measurements at two different 
distances, and plug those into the following equations to get a gain 
(Kg) and an offset (Ko).  Those values are then used in turn to convert 
the analog signal to distance in inches, or whatever units you prefer.  
I use 1/10th inches, but that's arbitrary.

The conversion equation is:

         distance = Kg(X/Ko)

         Where X is the analog valued returned by the A/D converter, Kg 
is gain, and Ko offset.

The calibration equation is:

         Kg = (X'-X)* D'D/(D-D')
         Ko = (D'X' - DX)/(D' - D)

         Where X is the measurement at distance D, and
         and X' is the second measurement at distance  D'

For the GP2Y0A02Y, I usually take a measurement of X where D = 5 inches, 
and a second measurement of X' where D' = 15 inches.

Here is an example from the Left Sharp Sensor on the nBot robot:

         D = 5"          X = 108
         D' = 15"        X' = 40

         Kg = (40-108)*((5*15)/(5-15))
         Kg = 510.0 = 5100 for 1/10th inches

         Ko = ((15*40) - (5*108))/(15-5)
         Ko = 6.0

Then in the robot code that uses the left SHARP ranger:

         sharp_left_distance = 5100/(sharp_left-6)

         where sharp_left is the instantaneous reading of the 8 bit A/D 
channel connected to the left SHARP sensor,
         and sharp_left_distance is the distance of the detection in 
10th inches.

By way of comparison, for the supposedly identical SHARP right sensor on 
nBot, Kg = 4425 and Ko = 12.

All of the sensors are slightly different, even from the same batch.   
This calibration and conversion not only gives the output in useful 
real-world units, but allows sensors to be swapped and replaced without 
having to change the control code that uses the readings.

Hope this is helpful,

More information about the DPRG mailing list