This is an Arduino library for interfacing Sharp IR range finders.
Currently there are three models supported,
GP2D120XJ00F,
GP2Y0A21YK,
GP2Y0A02YK0F.
Their transfer functions have been extracted from the datasheets,
by fitting a model on a series of datapoints. These collections of data
are present for reference in the curve_fitting folder.
Apparently, not all units have the same response characteristic. So, I have also implemented a process to extract such a characteristic for your own sensor.
In the curve_fitting folder:
- There is a Python script
data_acquisition.py, accompanied by an Arduino sketchCurveFitting, so as those two together, and with a little bit of your help, they are going to take some measurements, do a bit of processing, and put the data in a filedatapoints.csv. - Next, there is a Python script
curve_fitting.pyand a MATLAB scriptcurve_fitting.m, and you can use either one (it's up to you which one), to fit a model to the data, evaluate the results, and compare the estimated model with the one from the datasheet. You can find more details on the headers of the corresponding files.
It's not neccessary to execute this process, it might be that your sensor is already working pretty well. But if you think you need that extra accuracy for your project, now you can have it out of the box.
- Set a model of your choice for the sensor (Sum of exponentials, 5th order polynomial).
- Get values from the sensor in
rawform, involts, and in units of length (cm,in). - Set/Reset the voltage reference for the sensor's output measurement.
- Take multiple measurements that are averaged, in order to cancel out some of the sensor's output fluctuation.
- Set a point of reference for the sensor's measurements. You can measure the distance of an object from a point (on the same axis) other than the sensor's position.
- Operate the sensor in discrete mode by providing a threshold for the distances of objects.
There is one sketch for the curve fitting process, CurveFitting, and two additional example sketches, DistanceFromObject and StayAway, that expose some of the interface and functionality of the library.
