Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
Non-Linear OuputThe Sharp IR has a non-linear output. This means that as the distance increases linearly (by set increments), the analog output increases/decreases non-linearly. The image above is a typical expected output from your range finder. Notice the strange kink in the beginning of the graph. This is because the range finder is not capable of detecting very short distances. Refer to the particular range finder you are using to determine the range that your range finder is capable of.Sharp IR Range Finder CalibrationTo effectively use your Sharp IR Range Finder, you must have a voltage output versus distance chart to reference from. The manuals now come with a 'typical response curve' graph for you to use, but you should check just to make sure it is accurate. If you do not have a chart, or you would like to verify the chart, run an experiment that measures distance versus the output analog value. To do this, place an object in front of your sensor, measure the distance, then look at the printf output reading. Graph your data. I recommend reading my article on advanced sensor interpretation to help you make better sense of the data. Typically people either create a lookup table or create a representative equation of the distance function.To minimize any noise, do this experiment in the environment you wish your robot to operate in. For example, if you want your robot to operate on a factory floor, run this experiment on a factory floor - this will make sure all ambient conditions are the same for highest accuracy. This should be a good rule of thumb for calibrating any sensor.
//Sharp GP2D12 IR Range Sensor#define irRawMin 16 // Min valid raw reading (approx 36")#define irRawMax 130 // Max valid raw reading (approx 4" )int sensorsGetIrDistance(int pin) { unsigned int raw=a2dConvert8bit(pin); if (raw<irRawMin || raw>irRawMax) { return 0; } else { return 600/raw-1; }}
//Sharp GP2D12 IR Range Sensor - claims 10cm to 80cm (I got 8cm to 150cm)int sharp_IR_interpret_GP2D12(int value) { return 1384.4*pow(value,-.9988); }
#define distX(deg,dist) doTrig(deg,dist,0)#define distY(deg,dist) doTrig(deg,dist,1)#define trigAngleResolution 5 // only works in 5 degree incrementssigned int trigVals[73]={100,100,98,97,94,91,87,82,77,71,64,57,50,42,34,26,17,9, 0,-9,-17,-26,-34,-42,-50,-57,-64,-71,-77,-82,-87,-91,-94,-97,-98,-100, -100,-100,-98,-97,-94,-91,-87,-82,-77,-71,-64,-57,-50,-42,-34,-26,-17,-9, 0,9,17,26,34,42,50,57,64,71,77,82,87,91,94,97,98,100,100};signed int doTrig(signed int deg, unsigned int dist, int cos) { signed long int result=dist; if (! cos) { deg-=90; // Phase shift -90 deg } while(deg<0) {deg+=360; } // Normalize to 0 - 360 while(deg>360) {deg-=360; } // Normalize to 0 - 360 result*=trigVals[deg/trigAngleResolution]; // Mult by sin/cos * 100 result/=100; // Divide out 100 from above return (result);}
I've used this option already. But! How do you generate a formula from the sensor data?I got up to the point of building a graph and that's it.
BTW, how's the weather in Thailand?