Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Function for a curve?


  • Please log in to reply
3 replies to this topic

#1 Frode

Frode

    Advanced Member

  • Members
  • PipPipPip
  • 202 posts
  • LocationNorway

Posted 21 October 2014 - 07:16 PM

Hi guys, 

I've bought the new Pololu IR sensor GP2Y0A60SZLF, and want to use it with my Netduino.

 

Other sensors I've used before use a linear scale for determining distance. So from the sensor output you could basically just multiply it with a simple value to get the distance.

 

For this sensor the output varies like this;

 

mathCurve.PNG

 

I'm using the 5V version, by the way.

 

Here the output voltage doesn't have a linear relationship with the distance.

 

I need to figure out a formula, or maybe create a method where I can input a few known values, and interpolate values based on that. I don't know.

 

Maybe someone in the NetMF/Netduino community have any experiences calculating these sort of graphs? 



#2 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 22 October 2014 - 01:36 AM

I have a Sharp GP2Y0A02YK0F 20-150 cm Distance Sensor. I get good results with the attached function relative to a known distance. I am sorry I don't have the attribution for the curve fit. I think it comes from the Arduino forum. If you search for "Sharp ir distance sensor curve fit", other fits will turn up others with varying degrees of approximation. The functional relationship accurately describes the curve. Your sensor may yield different constants. Just pick some points off of the curve and do a curve fit for the constants  in Excel. You might also want to do some smoothing on the measurements because they are noisy with this sensor.

'enable Sharp Analog GP2Y0A02YK0F 20-150 cm Distance Sensor
Friend SharpSensor As AnalogInput = New AnalogInput(Cpu.AnalogChannel.ANALOG_0) 'Netduino Plus 1 analog pin 0

SensorVal = distance(SharpSensor.Read() * 3.3) 'in inches

Public Function distance(Volts As Double) As Double
        Dim result As Double
        Dim A As Double = 0.008271
        Dim B As Double = 939.6
        Dim C As Double = -3.398
        Dim D As Double = 17.339
        Dim one As Double = 1.0
        result = (A + B * Volts) / (one + C * Volts + D * Volts * Volts)
        Return result / 2.54 'inches
    End Function



#3 Frode

Frode

    Advanced Member

  • Members
  • PipPipPip
  • 202 posts
  • LocationNorway

Posted 22 October 2014 - 07:13 AM

Perfect, this looks like a good start!

 

Here is an interresting article: http://www.acroname....arp-ranger.html. Googleling 'sharp ir sensor distance equation' gave other good results as well, so hopefully I'll be able to create a good method out of all of this.



#4 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 22 October 2014 - 07:15 PM

Here is a nice sequential mean and variance estimator,
http://www.johndcook..._deviation.html

Just sample the analog input or distance for X ms and you have the mean value together with the error estimate.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.