Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Ultrasonic rangefinder code (http://www.chiefdelphi.com/forums/showthread.php?t=62371)

windell747 23-01-2008 18:04

Ultrasonic rangefinder code
 
Hi, I'm looking for code that might already be written to obtain a distance from an ultrasonic rangefinder. The one in specific that I have is at the following link.

http://www.acroname.com/robotics/parts/R271-SRF05.html

I could write the code myself, but I would rather see what is already out there so that I don't need to make the same mistakes that others have gone through.

Thanks much!

slavik262 23-01-2008 18:20

Re: Ultrasonic rangefinder code
 
WPI Lib has very good sensor code, including code for ultrasonic sensors. For details, look at the WPI Lib documentation.

WPI Lib is basically an extended version of the library used in EasyC.

windell747 23-01-2008 18:29

Re: Ultrasonic rangefinder code
 
What if I don't use EasyC? Will the code still work?

Thanks!

JonathanLKS 23-01-2008 20:14

Re: Ultrasonic rangefinder code
 
WPILib will work without EasyC, though I don't think it'll work with any of Kevin's code if your using that as well.

lukevanoort 23-01-2008 20:23

Re: Ultrasonic rangefinder code
 
If you are willing to try a different ultrasonic, the MaxBotix one requires practically no coding at all; it can output distance as an analog signal, which requires no interrupts, and all you need to do is read from an analog input. The two ultrasonics cost about the same too ($0.45 difference).

Phalanx 23-01-2008 21:22

Re: Ultrasonic rangefinder code
 
We aren't using EasyC or WPILIB, but we have used the Maxbotic sensor using analog with good results. The current models use a 9.8mV to an inch scaling.

The code was simple as well.
Here's a sample for it that I just typed from memory using analog port 1:

Code:

unsigned int sonic;
unsigned int mV;
unsigned int inches;
sonic = Get_Analog_Value(rc_ana_01);
mV =( (sonic * 5000) / 1024 );
inches = mV * 10 / 98;


Andy Goetz 24-01-2008 18:19

Re: Ultrasonic rangefinder code
 
If you do the algebra, with the Maxsonar, you can just divide the incoming value by two to get the distance in inches.

Tom Line 24-01-2008 18:53

Re: Ultrasonic rangefinder code
 
Andy, that depends on a lot of things and isn't necessarily true.

On ours, using Kevin's ADC code, we have to devide by 3.933, or multiple by 100/393 to get inches.

Phalanx 24-01-2008 21:07

Re: Ultrasonic rangefinder code
 
Quote:

Originally Posted by Andy Goetz (Post 685149)
If you do the algebra, with the Maxsonar, you can just divide the incoming value by two to get the distance in inches.

Well you can do that, if you don't mind the small error that is introduced from it, and that the version of the sensor uses 10mV per inch scaling. All the newer models use 9.8mV per inch scaling so your range readings will be off even more.

For example a reading of 512 would be 2.5mV which is very close the 2.55mV maximum range that this device uses. So dividing by 2 would give you 256, which is close to 250 inches the device is reporting, but 6 inches off at that range(using 10mV inch). As you get closer it becomes less of an issue.

It all depends on the level of precision you need or want.

Alan Anderson 25-01-2008 00:37

Re: Ultrasonic rangefinder code
 
There's no particular reason for the software to deal with distance in inches, or centimeters, or any "engineering" unit. We've usually done all the navigation using the equivalent of raw encoder or analog input counts.

For something like autonomous scripting we typically convert in the other direction, to turn familiar units like inches into the values the program likes.


All times are GMT -5. The time now is 21:50.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi