View previous topic :: View next topic |
Author |
Message |
vert02
Joined: 23 Jan 2009 Posts: 8 Location: Kuala Lumpur, Malaysia
|
Distance conversion for ir |
Posted: Tue Mar 24, 2009 2:21 am |
|
|
Helloo..
i m currently doing my colledge project and i m required to convert the value of sharp's ir sensor into distance value..
i am using PIC16F877A and an ir sensor to determine the movement of motor
i know how to get input from the ir sensor but it is in raw adc value..
i want the adc value to be converted into distance so that i can used it for my motor
required help,thank u |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Mar 24, 2009 6:27 am |
|
|
I guess, you're using some GP2Dxxx sensor? Unfortunately you didn't tell.
Did you read the sensor data sheet? The sensor has a nonlinear and also type dependant output voltage. The datasheet suggests a method to approximate the sensor function by a linear function of 1/x, the additional parameters possibly need individual calibration. Alternatively, you can use an empirical look-up table to convert analog voltage to distance. |
|
|
vert02
Joined: 23 Jan 2009 Posts: 8 Location: Kuala Lumpur, Malaysia
|
|
Posted: Tue Mar 24, 2009 11:41 pm |
|
|
To fvm
Thanks for your reply. Yes I'm using that ir sensor.
Where can I find this empirical table?
Is it in the datasheet?
I read before but did not get the method of converting. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Mar 25, 2009 12:12 am |
|
|
Empirical in my understanding means, you have to find the values by calibration measrurements with your individual device. This would be the preferred method to achive maximum accuracy. A more suitable way is probably to use the 1/x function suggested by the datasheet. As a general form
Code: | distance = a + b/(ADC + c) |
The arithmetics should be performed in signed long or float, a,b,c can be determined from a 3 point calibration. Or, after calculating a from the typical characteristics in the datasheet, do 2 point calibration for b and c. Using a signed long, the distance can be scaled e. g. in mm or 0.1 mm.
Cause the transfer function is nonlinear, a direct calculation of coefficients requires some effort, a convenient solution is to let e.g. the Excel solver calculate them. It can also perform an optimal fit by using more calibration points and a least square error criterion. For higher accuracy requirements, a polynominal may be used in addition to the 1/X function.
The calibration points should be within the distance range, that is linear in 1/X, respectively the interval, that is utilized in your application. |
|
|
vert02
Joined: 23 Jan 2009 Posts: 8 Location: Kuala Lumpur, Malaysia
|
|
Posted: Thu Mar 26, 2009 1:30 am |
|
|
to fvm...
thanks again for your help..
i try use that method and report back to you.. |
|
|
vert02
Joined: 23 Jan 2009 Posts: 8 Location: Kuala Lumpur, Malaysia
|
|
Posted: Thu Mar 26, 2009 2:45 am |
|
|
hi fvm..
i have tried your solution but i m stuck again..
is the a,b and c is a fixed value which i can obtained from any point of the graph? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Mar 26, 2009 7:11 am |
|
|
They are arbitray constants (a and c may be possibly negative), that have to be choosen to make the transfer function fit your intended characteristic.
I made some detailed suggestions for calculation methods without further considering your level of mathematical knowledge, cause I'm generally used to similar techniques. I basically tried to elobaorate what's missing in the Sharp datasheet.
My assumption is, that a three point calibration, spread in a meaningful way over the distance range appearing linear in the datasheet, would give one unequivocal set of parameters a,b,c. |
|
|
|