Go Down

Topic: SHARP IR Distance Sensor - GP2D120XJ00F (Read 6 times) previous topic - next topic

cpixip

actually, reading of the sensor value should occur at a precise time after you trigger the measurement. See the datasheet on how the voltage varies over time, there's a diagram somewhere. That time is the 38 msec robtillaart mentioned. You should not have any jitter in that timing. And yes, sampling with a higher frequency does not make too much sense, provided your powersupply is clean.

Blue_Boy

#21
Jul 03, 2011, 04:56 pm Last Edit: Jul 03, 2011, 04:58 pm by Blue_Boy Reason: 1
Could you explain what you mean by "triggering the measurement"?
There's only a power, ground and "voltage to read" line coming out of this sensor.

Maybe the problem is still my power line, though.
I put the capacitors right next to the Arduino, and then wired all my sensors "behind" that.
(IR Rangers and Flex sensors)

cpixip

oops... - sorry, I mixed up the Sharp IR distance sensors with the Sharp IR dust sensor (the GP2Y1010AU0F for example). The later is being triggered and has to be read out at a specific time after the trigger. Sorry for this confusion....

The Sharp IR distance sensors are indeed outputting the data continously, but that reading does change only at discrete time points.

Back to the issue of power line spikes: I would try to place the capacitors as close as possible to the sensor, not the Arduino. If you google, you will find people soldering a condensator directly to the pins of the IR sensor (for example: http://www.robotfreak.de/blog/en/robotics/how-to-improve-sharp-ir-sensors/450).

You might also try to power sensor and Arduino with different voltage supplies for a test (batteries for example).

Basically, if the power is not stable enough, the noise spikes created by the sensor kick through to the Arduino, especially the Aref voltage which the DAC uses to digitize the analog voltages. If that happens, the readings of the sensor will get noisy, even so the voltage the sensor is delivering is constant.

Time averaging will stabilize the readings, in any case.

Blue_Boy

#23
Jul 04, 2011, 04:02 pm Last Edit: Jul 04, 2011, 04:09 pm by Blue_Boy Reason: 1
Hey,
When I just check the RAW values from the sensors,
jitter seems pretty minimal now.
I added an extra capacitor, adding  even more
does not seem to improve the situation.

The sensor response is still not ideal however.
I do a time-averaged read of the sensors,
but improvements are possible.

I guess some smarter filtering could help.

(Analog pin 0 and 1 are connected to the IR rangers)
(The flex sensors a quite stable now)

Code: [Select]

/* PuppetMaster V5 Code                                */
/* Jim Bollansée | jim@jimboproductions.be   */
/* Creative Commons Attribution ShareAlike    */
/* GameHUB 2011                                           */

unsigned long previousMillis;
unsigned long currentMillis;

int numberOfSteps = 0;
int sensorValue[6];
long sensorValueTotal[6];

float tempFloat;

// Set calibrate to 255 to disable calibration
int calibrate = 255;
int sensorTop[] =    {25500, 27000, 510, 530, 530, 480};
int sensorBottom[] = {3500, 3500, 610, 650, 630, 600};

byte dataStart = 0xFF;

void setup()
 {
 Serial.begin(9600);
 }

void loop()
 {
 numberOfSteps ++;
 currentMillis = millis();
 
 for (int i = 0; i < 6; i++)
   {
   sensorValueTotal[i] = sensorValueTotal[i] + analogRead(i);
   }
 
 if (currentMillis - previousMillis > 40)
   {
   if (calibrate == 255) Serial.print(dataStart);
   
   for (int i = 0; i < 6; i++)
     {
     tempFloat = (float) sensorValueTotal[i];
     tempFloat = tempFloat / numberOfSteps;
     
     sensorValue[i] = (int) tempFloat;
     sensorValueTotal[i] = 0;
     
     // IR Ranger specifics
     if (i < 2)
       {
       tempFloat = (float) sensorValue[i];
       tempFloat = (2914 / (tempFloat + 5)) - 1;
       tempFloat = tempFloat  * 1000;
       sensorValue[i] = (int) tempFloat;
       }
     
     if (calibrate == i) Serial.println(sensorValue[i]);
     if (calibrate == 255)
       {
       /// Only map to 254 because 255 is start byte!
       sensorValue[i] = map(sensorValue[i], sensorBottom[i], sensorTop[i], 0, 254);
       sensorValue[i] = constrain(sensorValue[i], 0, 254);
       Serial.print((byte)sensorValue[i]);
       }
     }
   
   numberOfSteps = 0;
   previousMillis = millis();
   }
 }

ahtih

FYI, in my case adding just the capacitor onto the sensor power pins (directly on the sensor, not Arduino) did not reduce the spikes in measured distance readings much. But adding a 10ohm resistor between Arduino +5V power and the capacitor improved things a lot. Here are the standard deviations of measured distance (about 10cm from sensor, measured every 7ms):

plain sensor connected to Arduino +5V/GND: 0.27cm standard deviation, mainly consisting of ca 1cm spikes occuring ca 20 times per sec

with 100uF cap on sensor power pins: 0.15cm

with 100uF cap+10ohm resistor: 0.03cm

Go Up