Precision problems with Sharp GP2Y0A710K0F

Hello,

I have a project which utilizes a distance measurement sensor, namely the Sharp GP2Y0A710K0F. I need several meters of range and I found ultrasonic sensors to be unreliable. In the first version of my project, I used an Arduino Mega2560 to process the data. After I calibrated the sensor, it worked pretty well (the sensor has a poor documentation, so I measured the raw ADC data between 1-5m with 20cm gaps and made a 10th degree polynom to calculate the range). But then I ported the project to a standalone Atmega328P-PU and used a MAX11644 12bit ADC for better resolution. Or so I thought. Now it has a very large scattering and generally bad precision (usually 50-70 cm off, sometimes even 1-2 m). Longer distance has worse precision.

What I do with the data:
I read 10 values from the ADC, sort them with bubble sort and drop the items which differ much from the median value, then average the rest. This is the test code. The final code had another sort-drop-average round with 25 of these values.
This used to work fairly well on the Mega. When I started using the MAX11644, I simply mapped down the raw value from the 0-4095 range to 0-1023 and used the method as before.

I'm not sure if it's a lack of signal conditioning or it's the sensor, but I measured the sensor's output with a multimeter and sometimes it's in the 0.3-1.5V range, other times it's in the 1-3V range which looks better to me. I have 4 sensors, I tried putting a 100uF cap on one of the sensors' supply line but I don't see much difference with the stock sensors.

I also tried feeding the signal to the MAX11644 and the Atmega328's ADC at the same time to see if there a difference. The Atmega's measurement seems more stable, but still can't measure longer distances than 2,5m precisely.

Has anyone used these sensors or the MAX11644 before? Or have you experienced anything similar?

I can post some code or something if you want, but it's pretty long, so maybe we can find an explanation first without time consuming code digging (and I don't think it's code related).

made a 10th degree polynom to calculate the range

It is hard to imagine that this is justified, or will even work. Post the data and the coefficients of the polynomial that you used to fit it.

How will you account for changes in room illumination and different reflective surfaces?

Typical sensor response, from the device data sheet:

Obviously, for distances greater than about 2 m, the range becomes poorly determined.

If you want better accuracy, use one of the new LIDAR sensors, like the TFMini.

jremington:
It is hard to imagine that this is justified, or will even work. Post a plot of the data and the coefficients of the polynomial that you used to fit it. How do you account for changes in room illumination and different reflective surfaces?

Typical sensor response, from the device data sheet:

Obviously, for distances greater than about 200 mm, the range becomes poorly determined.

If you want better accuracy, use one of the new LIDAR sensors, like the TFMini.

You may have a point about illumination. My previous tests were carried out in a room with mostly artificial lightning and I’m testing the new setup outside. I’ll test it inside as well. I don’t really know what could be done about it, because I’ll use it outside. I don’t think surface reflaction should be a factor as the beam is pretty narrow and the sensor is fixed. It should result in a more or less constant error which is not the case.

My reading were similar to the factory data during calibration. See attached.

10th degree approximation may be an overkill, but why not. I used this:

double v10=6.369;
  double v9=-42.9;
  double v8=86.93;
  double v7=4.477;
  double v6=-202.5;
  double v5=152.1;
  double v4=114.2;
  double v3=-171.8;
  double v2=93.7;
  double v1=-123.3;
  double v0=200.6;

x=(x-381.2)/96.75;

return int(v10*pow(x,10)+v9*pow(x,9)+v8*pow(x,8)+v7*pow(x,7)+v6*pow(x,6)+v5*pow(x,5)+v4*pow(x,4)+v3*pow(x,3)+v2*pow(x,2)+v1*x+v0);

Where x is the raw ADC value (scaled to 0-1023 with the MAX11644).

Unfortunately Lidars are out of my budget.

I also attached a serial plot of a reading over time where I placed an obstacle in front of a sensor and waited (the red plot). It’s not processed at all, it’s the value out of the MAX11644. Note the quick change between different reading ranges which I also experienced with the multimeter.

balazs:
a 10th degree polynom

A lookup table makes much more sense for this. 10-20 values and linear interpolations will be good enough.

ToF sensors will do a lot better for your required distance - but note all such sensors will be affected by ambient IR (which can come from many sources, e.g. light bulbs, candles or the sun).

Looking at that curve indeed not likely you get good accuracy at distances >2.5m.

10th degree approximation may be an overkill, but why not

There are entire book chapters dedicated to answering the question "why not" -- numerical instability, blowups and overfitting artifacts being the primary reasons "why not". Below is a plot of that polynomial, for a range of possible ADC values.

I don't think surface reflaction should be a factor as the beam is pretty narrow and the sensor is fixed. It should result in a more or less constant error which is not the case.

You should test that very dubious assumption.

pol10.png

pol10.png