CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Distance conversion for ir

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vert02



Joined: 23 Jan 2009
Posts: 8
Location: Kuala Lumpur, Malaysia

View user's profile Send private message Send e-mail

Distance conversion for ir
PostPosted: Tue Mar 24, 2009 2:21 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 24, 2009 6:27 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Tue Mar 24, 2009 11:41 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 25, 2009 12:12 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 26, 2009 1:30 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 26, 2009 2:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 26, 2009 7:11 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group