|
|
|
Supreme Being
      
Group: Forum Members
Last Login: Friday, April 22, 2011 6:18 PM
Posts: 153,
Visits: 547
|
|
hello Kyle,
you can and should do all the excercises for your Sharp sensor but I have already if you
read my reply and looked at my web site. To get you started try this snippet from
some of my development work. It is named panIr here as it is on a pan/tilt
mechanism for object (radar like) sensing. The value 4995.0 is a result of
the Linearized data done here.
http://robotics.djlewis.us/hardware/sensors/gp2y0a02yk.html
------------------------------------begin-------------------------------
// 01/09/2010
// added Sharp GP2Y0A02 IR, distance measuring range: 20 cm to 150 cm (8" to 60")
//
private AnalogSensor PanIr; // PanScan IR 8" - 60"
double panIrVoltage = 0; // PanIr raw voltage
double panIrRange = 0; // range from voltage
private void InitializeSerializer()
{
serializer = new Serializer();
serializer.BaudRate = 19200;
serializer.PortName = "COM1";
serializer.CommunicationStarted += new SerializerEventHandler(serializer_CommunicationStarted);
PanIr = new AnalogSensor(serializer);
PanIr.Pin = AnalogPinId.Pin3;
PanIr.UpdateFrequency = 200;
PanIr.ValueChangedThreshold = 1;
PanIr.ValueChanged += new SerializerComponentEventHandler(PanIR_ValueChanged);
//much more non Sharp GP2Y0A02 IR left out.....
}
// New PanIr uses Sharp GP2Y0A02 IR, note, read samples, convert and display
void PanIR_ValueChanged(SerializerComponent sender)
{
panIrVoltage = PanIr.Value; // Int to Double conversion
panIrRange = (4995.0 / panIrVoltage); // adjusted constant more accurate long range
// Console.WriteLine(panIrRange); // debug line
if (panIrRange < 4) { panIrRange = 4; } // stay within actual sensor range
if (panIrRange > 70) { panIrRange = 70; } // helps with random spikes/dips
// Do what you want with the data returned by panIrRange, I send it to a GUI here.
}
-----------------------------------------end--------------------------
Don Lewis
|
|
|
|
|
Supreme Being
      
Group: Administrators
Last Login: Monday, October 31, 2011 9:18 PM
Posts: 640,
Visits: 819
|
|
Thanks Don! This will be extremely useful to everyone! I meant to look at your link and forgot.  Yep, there you go Kyle! Since Don has peformed all of the hard work, I'll do the easy part and add the gp2y0a02yk class to the next .NET lib release. Best Regards,
Jason Summerour President, Summerour Robotics Corporation www.roboticsconnection.com
|
|
|
|
|
Supreme Being
      
Group: Administrators
Last Login: Monday, October 31, 2011 9:18 PM
Posts: 640,
Visits: 819
|
|
| Don, Actually, I realize that I should ask your permission to use your equation first! If you don't mind, I'll add the new Sharp gp2y0a02yk sensor, that uses your equation. Best Regards!
Jason Summerour President, Summerour Robotics Corporation www.roboticsconnection.com
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: Friday, April 22, 2011 6:18 PM
Posts: 153,
Visits: 547
|
|
Hi Jason,
I find the equation does ball park the readings well. I did
however, tweak it as I mentioned. I tested factor values of 4990.00
through 5010.80 and for my Sharp sensor the 4995.0 was a
good round average for the entire measurement range. I
find eliminating the equation and just using the result of the
equation saves some cpu cycles.
You are welcome to any of my results you find useful. You
are also welcome to improve on them as long as you share
your findings 
Don Lewis
|
|
|
|