Let's Make Robots!

Using Frisls "Clean navigation" with a Sharp GP2D120 IR Sensor?

Greetings from Finland.

1) Is it possible to use frisls "clean navigation"- code with a sharp GP2D120 IR sensor? I know after looking at his code that the distanse readings are backwards (on a sharp closer distanses are greater), but if I changed them would I be able to use his brilliant code as a base? 

2) what is the differenses on SRF05 and sharp GP2D120 other than one is a
ultra sonic and the other is a infrared.Idon't meen number of conections but speed as in using themto almost constantly return the range



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

The two biggest differences I see in sonar vs. IR ranging are the range and the cone of detection. 

We'll discuss the cone of detection first. An IR ranging sensor like the GP2D** family uses  triangulation with an IR beam and a what is effectively a small 1D camera. The IR beam basically projects a 1/4" dot on the wall, the 1D camera sees how far it's shifted. Thus, an IR ranger has a very narrow beam of detection (you can't find a chair leg without panning the sensor, or happening to be looking directly at it). A sonar ranger on the hand uses sound, which disperses. You can visualize this as a cone projecting from the sensor. Thus, sonar sensors detect things like chair legs, but have a tough time telling where an object may be (it'll just tell you that something is within X distance, inside the 45 degree cone projecting from the sensor). Also, because of all those crazy wave reflection patterns, you may miss objects that are at wide angles from the sensor.

As for range, the IR sensors are available in several ranges: GP2D12 (4-30in), GP2D120 (1-12in), and an 8-60" module. Most sonar sensors work over a range of 6"->15 feet or so. HOWEVER, because the sonar cone spreads out, it may return hits from the floor, limiting the range. 

Understanding what the sensor is actually returning really helps in debugging a robot's behavior. I've written a tutorial on sensors over on TRC. See page 2 of the tutorial for a more in-depth discussion of sonar vs. IR ranging.


The most important differences (in terms of object avoidance):


Ultrasonic is accurate to about 5 feet, while IR will be lucky to return 1 foot. (Sorry, Calculon doesn't process centimeters)

Method of Finding Range:

The ultrasonic returns a value by measuring the time it takes the pulsout sound to bounce off an object. Thus, the number increases with further range. This number can potentially be larger than 255, so you want to use a WORD variable to store it.

IR, on the other hand, measures the amount of voltage returned by the object. The closer the object, the more light is returned, the higher the number. Because this is returned by the analog-to-digital converter, it will be between 0 and 255, so you will use a BYTE variable to store it.


The difference between them is negligible. Ultrasonic will theoretically take longer, but it's a matter of microseconds. An ultrasonic sensor also uses 3 lines of code compared to 1, but that's not a big deal if it's a subroutine.


Sonar can easily miss soft surfaces and surfaces that angle away from the unit. Carpet can also interfere greatly with a sensor close to the ground.

IR: Many types of plastic surfaces are invisible to IR, while light from TV's, Monitors, and the Sun are TOO visible.


If you want to swap in an IR sensor for the sonar, simply replace the "get_range" (or whatever it's called) subroutine with this:

readadc IRpin, b0 

where IRpin is your analog sensor, and b0 is the variable you are storing it to.

Thanks for your answer! It was just the things I needed to know! seriously! you made my day. I didn't even had time to reply at once as I was testing to build a navigation code for my robot. It is still pretty dumb, especially in corners...

 Thanks again!