![]() |
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! |
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. |
Re: Ultrasonic rangefinder code
What if I don't use EasyC? Will the code still work?
Thanks! |
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.
|
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).
|
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; |
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.
|
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. |
Re: Ultrasonic rangefinder code
Quote:
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. |
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