Loading ...
Sorry, an error occurred while loading the content.

Error in GP2D02 Article

Expand Messages
  • Brian Short
    http://www.ottaw arobotics.org/articles/gp2d02/gp2d02.html The formula cited for linearizing the
    Message 1 of 4 , Jan 3, 2002
    • 0 Attachment
      <http://www.ottawarobotics.org/articles/gp2d02/gp2d02.html>http://www.ottaw
      arobotics.org/articles/gp2d02/gp2d02.html


      The formula cited for linearizing the GP2D02 data is
      not correct. I derived the formula and arrived at the
      following:

      output = K1 * atan( K2 / distance ) + K3

      so,

      distance = K2 / tan( (output-K3) / K1 )

      substituting typical values (different for individual GP2D02's)

      distance = 1.9 / tan( (output - 25) / 1000 )

      I'd be interested in other's comments and experiences with this
      sensor.

      Thanks, Brian
    • Jon Hylands
      ... I took the forumla that they provided, and wrote a little piece of code on my laptop to produce all the valid range values in a table for each A/D 8-bit
      Message 2 of 4 , Jan 3, 2002
      • 0 Attachment
        On Thu, 03 Jan 2002 17:56:05 +0000, Brian Short <k7on@...> wrote:

        > I'd be interested in other's comments and experiences with this
        > sensor.

        I took the forumla that they provided, and wrote a little piece of code on
        my laptop to produce all the valid range values in a table for each A/D
        8-bit value.

        I took the result values, made a constant table, which ended up in the PIC
        program space, and wrote a simple function that returned 0 if the input
        value was out of range, or did the table lookup otherwise.

        It saved having to import the math library, which cut down on the size of
        the HEX file produced from 18 KB to 6 KB...

        It also saves on having to convert everything to floating point, and of
        course it runs a huge amount faster.

        In general, I find the sensors work extremely well. I use two of them on
        each of my mini-sumos... (www.huv.com/miniSumo)

        Later,
        Jon

        --------------------------------------------------------------
        Jon Hylands Jon@... http://www.huv.com/jon

        Project: Micro Seeker (Micro Autonomous Underwater Vehicle)
        http://www.huv.com
      • Aaron
        You are right Brian! When I converted the formula to a single line for the web, I totally screwed it all up. I turned a - into a * and had some wacky
        Message 3 of 4 , Jan 3, 2002
        • 0 Attachment
          You are right Brian! When I converted the formula to a single line for the web, I totally screwed it all up. I turned a '-' into a '*' and had some wacky brackets going on. Nice catch. When I fixed it on the website, I also included a link to Sean Breheny's website, if you are interested. It's at http://www.hobbyrobot.com/info/gp2d02/index.html

          Aaron


          On Thu, 03 Jan 2002 17:56:05 +0000 Brian Short <k7on@...> wrote:
          > <http://www.ottawarobotics.org/articles/gp2d02/gp2d02.html>http://www.ottaw
          > arobotics.org/articles/gp2d02/gp2d02.html
          >
          >
          > The formula cited for linearizing the GP2D02 data is
          > not correct. I derived the formula and arrived at the
          > following:
          >
          > output = K1 * atan( K2 / distance ) + K3
          >
          > so,
          >
          > distance = K2 / tan( (output-K3) / K1 )
          >
          > substituting typical values (different for individual GP2D02's)
          >
          > distance = 1.9 / tan( (output - 25) / 1000 )
          >
          > I'd be interested in other's comments and experiences with this
          > sensor.
          >
          > Thanks, Brian
        • Brian Short
          Below you will find some working code for the NetMedia Basic-X 24. Feel free to use as you wish. I plan to put it on a web page soon. My existing web pages
          Message 4 of 4 , Jan 3, 2002
          • 0 Attachment
            Below you will find some working code for the NetMedia
            Basic-X 24. Feel free to use as you wish. I plan to put
            it on a web page soon.

            My existing web pages can be found at:

            <http://www.qsl.net/k7on>http://www.qsl.net/k7on/

            Things are a bit out of date, however.

            Thanks, Brian

            At 04:45 PM 1/3/02 -0500, you wrote:
            >You are right Brian! When I converted the formula to a single line for the
            web, I totally screwed it all up. I turned a '-' into a '*' and had some wacky
            brackets going on. Nice catch. When I fixed it on the website, I also included
            a link to Sean Breheny's website, if you are interested. It's at
            <http://www.hobbyrobot.com/info/gp2d02/index.html>http://www.hobbyrobot.com
            /info/gp2d02/index.html


            '
            ' This file contains Basic-X 24 source code for
            ' interfacing with the Sharp GP2D02 sensor module.
            '
            ' The GP2D02 is a compact, high sensitivity distance
            ' measuring sensor which is impervious to color and
            ' reflectivity differences and povides a precision
            ' digital distance measurement output.
            '
            ' (c)2002 Brian K. Short k7on@...
            '

            ' Define the Basic-X 24 interface pins
            '
            Const irVin As Byte = 11
            Const irVout As Byte = 12

            ' Define GP2D02 Distance Calibration Constants
            '
            Const K1 As Single = 1000.0
            Const K2 As Single = 1.9
            Const K3 As Single = 25.0


            ' Initialize the Basic-X 24 interface pins
            '
            Public Sub gp2d02Init()
            Call PutPin( irVout, bxInputTristate )
            Call PutPin( irVin, 1 )
            End Sub


            ' Measure distance to object and return raw
            ' integer value
            '
            Public Function gp2d02Raw() As Integer
            Dim Data As Integer
            Dim Bit As Integer
            Dim I As Integer

            Call PutPin( irVin, 1 )
            Sleep( 30 )

            Call PutPin( irVin, 0 )
            Data = 0
            Bit = 128

            irWait:
            If ( GetPin( irVout ) = 0 ) Then
            GoTo irWait
            End If
            For I = 1 To 8
            Call PutPin( irVin, 1 )
            Call PutPin( irVin, 0 )
            If ( GetPin( irVout ) = 1 ) Then
            Data = Data Or Bit
            End If
            Bit = Bit \ 2
            Next
            Call PutPin( irVin, 1 )
            gp2d02Raw = Data
            End Function


            ' Convert raw sensor reading to actual distance units
            ' (the most useful aspect of this is "linearizing" the data)
            '
            Public Function gp2D02Actual( Raw As Integer ) As Single

            gp2d02Actual = K2 / tan( ( CSng( Raw ) - K3 ) / K1 )

            End Function
          Your message has been successfully submitted and would be delivered to recipients shortly.