Sharp GP2D12 Range Finder???


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Linearising the SHARP distance sensors

    I use the long range analog sensors to sense the ground and assist smooth landing on my RC aircraft. The only thing to watch is that the SAME voltage output occurs at TWO ranges, one very close and the other the real range. I check the altimeter to decide which one to use. The formula below varies with each SHARP model. Set up a spreadsheet and experiment and you will quickly find a simple formula that is accurate enough for most needs.

    The following was shamelessly lifted from the ACRONAME web site at

    http://www.acroname.com/robotics/inf.../irlinear.html

    I have bought Sharp sensors from Acroname before and they are fine to deal with - don't forget to buy the JST cable assemblies - they are very hard to work with otherwise.

    The graphs in the Acroname article will not reproduce here - go to the source to see them.

    The Linearizing Function

    According to page 10 of the Sharp Device Specification for Distance Measuring Sensor Model No. GP2D120, a plot of the following interpolated equation is demonstrated:

    V = 1 / ( R + 0.42 )
    Where V is voltage and R is range, the equation produces a very straight line. The division operation acts as a linearizing function that turns the ungainly curve into a linear plot. This observation is the key to finding a simple approximation function for a Sharp IR range finders.


    The constant in the linearization function depends on the sensor type and calibration data parameters. The value of 0.42, as shown above, works well for the GP2D120 and the calibration points in the Sharp document, but may not be suitable for other sensors. This constant will be represented as k since it may change. The first step in getting a good voltage-to-range function is to find a constant k that linearizes the data. The following plot shows how the GP2D12 response graph shown above can be linearized by defining the variable k = 4.0.


    The next step is to find a straight line approximation that relates the voltage to the linearizing function. This involves finding suitable m and b constants for the familiar line equation:

    y = m * x + b
    In this case, y is equal to the linearized range. Substituting the linearizing function from above for y and substituting V for x yields:

    1 / (R + k) = m * V + b
    Rearranging the equation terms gives range as a function of voltage:

    R = (1 / (m * V + b)) - k
    This is a useful result for languages that support floating point math, but it can be rearranged further to get:

    R = (m' / (V + b')) - k
    where m' = 1/m and b' = b/m . This extra step produces an equation that works nicely with integer math as will be shown below.

    The Constants

    Getting the constants takes a bit of work. The first step is to get some calibration data. This can be obtained experimentally or "eyeballed" from the voltage-to-range curve on the spec sheet. Create a table of voltage vs. range for a set of range values. Then create a table of voltage in controller units vs. linearized range. Some experimentation may be required to find a k constant that produces a linear plot. Do a linear regression on that data to find m and b and you're done.

    Contents
    The Results

    For a BrainStem GP 1.0 controller using 10-bit A2D measurements (integers ranging from 0 to 1023) successful interpolation yields the following formula for a GP2D12 sensor:

    R = (6787 / (V - 3)) - 4
    Where m'=6787, b'=3 and k=4. The user must check the input V to prevent divide-by-zero, checking that V is larger than b'. For this formula, V must be greater than 3. With 10-bit integers, voltage measurements from a GP2D12 are typically above 80 when something is in range. If nothing is in front of the sensor, the readings can drop to 0.


    This approach can also work for other Sharp sensors. After plugging in "eyeballed" calibration data for a GP2D120 and tweaking the k offset to get a straight line, the following formula can be derived for a GP2D120:

    R = (2914 / (V + 5)) - 1
    Because of the integer math, the units won't be exact centimeters but these functions will provide a range measurement that is more user-friendly than just using the raw A2D reading.

    Contents
    Summary

    These approximations work well for controllers that use integer math. For controllers that have floating point capabilities, the techniques will work even better. Successful implementation depends on the quality of the calibration data and a good choice of the k constant that straightens out the curve.

    HTH
    BrianT

  2. #2
    Join Date
    Dec 2007
    Location
    Toronto, Ontario
    Posts
    23


    Did you find this post helpful? Yes | No

    Smile

    Hey,

    Thanks alot Brian, that write up is quite good but I'm still not sure how to implement the formula into pbp based on my current program setup. For example, the formula has a 'v' volts variable--is that the a to d voltage reading; and if so I guess that I have to to that conversion first, then plug in the v value??
    BTW, I bought a 'Brainstem' a few years ago and never used it because I found programming a litttle difficult. Can it be programmed in basic?

    Thanks.
    John

Similar Threads

  1. Questions on ultrasonic distance finder
    By lilimike in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 20th April 2010, 22:19
  2. using a pot to control a time range
    By glkosec in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th June 2008, 20:59
  3. Sharp GP2D12 8bit
    By Argo in forum mel PIC BASIC
    Replies: 0
    Last Post: - 26th October 2007, 00:40
  4. sharp GP2D12 interface pic16f676
    By jojokatada in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th April 2006, 18:26
  5. SRF04 Range Finder 16F628 R18iXL Board
    By Spindle in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th June 2005, 03:08

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts