Ultrasonic Range Finder

My team recently bought these ultrasonic range finders. We are having a few problems wiring and programming them.

Attched is a diagram that shows how we wired them.
To program them we used:

	if (run_count<2){
		rc_dig_out13 = 1;
	} else if(run_count >= 40){
 		rc_dig_out13 = 0;
		run_count =0;
		Get_Encoder_1_persec = Get_Encoder_1_Count() - last_count;
		last_count = Get_Encoder_1_Count();
		//printf("Sensor: %d \r", (int)Get_Encoder_1_persec);
	
	}
	printf("Sensor: %d \r", Get_Analog_Value(rc_ana_in01));
	run_count++;

However when it outputs all we get is the number 11. Does anyone know what is wrong?

Sensor.jpg


Sensor.jpg

I believe that you must use 2 digital ports, no analog. How this thing works is you send a 10 microsecond (us) pulse to it, then you have to wait until you get an input pulse on your digital input port, and you have to measure the length of the pulse. This diagram from that site should help

http://www.robot-electronics.co.uk/images/timing.gif

from
http://www.robot-electronics.co.uk/htm/srf04tech.htm

For sending the output pulse you can simply do


rc_dig_out18 = 1;
for(x=0;x<10;x++);
rc_dig_out18 = 0;

or something similar.

To measure the pulse you have to set up an interrupt on whichever port you are using as an input (I would suggest port 1 or 2) and a timer. I ended up using timer3. I also wrote it to work with two sensors on 2 outputs and 1 input. I haven’t tested the second one yet, but it should work. The only problem I am having is converting my time to millimeters…

If you have any questions about that ask away. I believe there is code somewhere on these forums for this as well, or I can post up mine tomorrow when I get back to school.

Edit: Take a look at this:

Interesting code that you could try.

If you are unable to get the pulse-width measurement stuff working, the Maxbotics Ultrasonic sensors interface to an Analog In port and are much easier to program. Cheap, too.

http://www.maxbotix.com/

I strongly suggest the Parallax PING))) sensor. 1024 has used these for a while now with great success. You can use my driver for them if you’d like.

As a side note, about half way through this season I will be releasing the 2008 version of the PING))) driver which supports simultaneous, asynchronous measurement from four PING))) modules using a single hardware timer and four I/O pins, plus it has high efficiency interrupts and an easy to understand interface. Two encoders can still be operated in parallel with the four ultrasonic sensors.

-q

This is sort of a tangent question to the discussion above. We put the vex ultrasonic sensor on our bot for some tests, and the guys ( a generic term for males AND females in my vocabulary :slight_smile: ) returned with the statement that it absolutely would not detect curved objects (like the ball) unless it was absolutely directly under it. Now I understand angle of reflection and all that, but it seems that a sensor that can only detect objects lined up at exactly 90 degrees is not very effective in ANY situation. Is there another type sensor that
would work better, or is that just how these sensors work and we should try to detect the line on the floor instead?

Ann
Barstow Kuh-Nig-Its
Team 1939
(Gotta make a real signature one of these days)

From how far are you trying to find it? My sensor (parallax PING))) ) seems to pick up the ball fine. I still have a bit more testing after school to do, but it seems to be fine…

Well, we tried the vex ultrasonics once and never had a whole lot of success with them. As i mentioned above, and as is mentioned just above this post, the Parallax PING))) sensor is a very robust option.

Round (cylindrical, parabolic, spherical) objects can be viewed from any angle since the wave from the ultrasonic sensor (which is a section of a sphere in shape) can find a perfect tangent point from any angle to the round object. For example, if you wanted to… say… find a pipe… (have no idea why you want to do that :rolleyes: ) it looks the same from any side (since there aren’t really any sides to a circular surface).

What you say is true for flat objects. Within a narrow margin of off-axis, ultrasonics measure fine. But as you go off axis your measurements are distorted then soon disappear. That’s we use a number of different schemes of data processing/collection from multiple ultrasonic sensors depending on the situation to get reliable data (this lead to the development of the aforementioned quad-ultrasonic driver) As a hint, one of these incudes mounting the ultrasonic sensor on an airplane servo.

Questions, Post!

-q

Thanks for answering my question. I suspected that there must be a way. I ordered a Ping))) sensor for the team. Each year we slowly add a sensor or two to the robot. Someday we will be ready for that camera :slight_smile:

Ann