|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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! |
|
#2
|
||||
|
||||
|
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. Last edited by slavik262 : 23-01-2008 at 18:24. |
|
#3
|
|||
|
|||
|
Re: Ultrasonic rangefinder code
What if I don't use EasyC? Will the code still work?
Thanks! |
|
#4
|
|||
|
|||
|
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.
|
|
#5
|
||||
|
||||
|
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).
|
|
#6
|
||||
|
||||
|
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; Last edited by Phalanx : 23-01-2008 at 21:24. |
|
#7
|
|||
|
|||
|
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.
|
|
#8
|
||||
|
||||
|
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. |
|
#9
|
||||
|
||||
|
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. |
|
#10
|
|||||
|
|||||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SRF04 Ultrasonic Rangefinder Unresponsive | the401tauntaun | Programming | 10 | 20-01-2008 12:39 |
| Ultrasonic will not work with another Ultrasonic plz help | Jackel148 | Programming | 10 | 10-05-2006 15:31 |
| Ultrasonic Distances | irishninja | FIRST Tech Challenge | 1 | 30-04-2006 20:25 |
| Programming Parallax Ultrasonic Rangefinder | edman | Programming | 2 | 17-02-2006 08:35 |
| Ultrasonic Rangefinder Operating On I2C Bus | CapnBFG | Electrical | 10 | 04-06-2005 01:31 |