|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Programming ultrasonic rangefinders
Hello CD! I have a pretty good targeting method for launching Frisbees figured out, but there's one thing I need to know wow to do first. How to program ultrasonic rangefinders. Basically, I need to get the range and put it into an equation, either in real time or at the push of a button. How do I get it to return the distance (in inches)? I've looked through CD, and found some examples that are pretty elaborate for doing something similar, but not quite what I was looking for. Is there any easy way to do this? Thanks!
|
|
#2
|
|||||
|
|||||
|
Re: Programming ultrasonic rangefinders
What specific sensor are you planning to use, and what kind of signal does it provide to the control system? Some have an analog voltage which is proportional to the range. Others have a PWM signal that varies depending on the range. Still others are a serial (e.g. SPI or I2C) connection that encodes a number.
Whatever you get, it's almost certainly going to be a simple matter of multiplying the value by an appropriate constant to turn it into a distance in whatever units you want. |
|
#3
|
||||
|
||||
|
Re: Programming ultrasonic rangefinders
We intend to use one Maxbotix MB1010 LV-MaxSonar-EZ1 (from the kit of parts last year (?)) and one Maxbotix MB1361 XL-MaxSonar-AEL0. They both support 3 sensor outputs: Analog Voltage, Serial, ands Pulse Width. I'll keep researching. If it's as simple as multiplication, I may try to find out how to return metres as well.
|
|
#4
|
|||||
|
|||||
|
Re: Programming ultrasonic rangefinders
The Maxbotix sensor analog signal provides 0.01 V per inch. That means that 1.2 V is 120 inches. Just read in the analog voltage and the math is pretty straightforward.
Of course you can use the PWM or digital outputs, but I can't help you there. |
|
#5
|
||||
|
||||
|
Re: Programming ultrasonic rangefinders
Thank you very much for the information. As it turns out, somebody <.< soldered our rangefinder for pulse width. Nothing I can't fix in a day or two once I acquire a soldering iron. In the meantime, is there an easy way to get input from the pulse width?
|
|
#6
|
|||||
|
|||||
|
Re: Programming ultrasonic rangefinders
Getting input from a PWM signal is one thing that I've never found a good way to handle using the available hardware and software of an FRC robot. You can play around with using a filter circuit to turn the signal into an analog voltage and read it that way, but it would take a lot less time to move the output wire to the voltage pin of the sensor.
|
|
#7
|
||||
|
||||
|
Re: Programming ultrasonic rangefinders
Hypothetically, if we did have the sensor wired properly, is it categorized with the WPI class for rangefinders, or would it just be a digitalinput? I've been looking through the WPI documentation and it says that the Ultrasonic class specifically supports the Devantech SRF04 and Vex ultrasonic sensors. I'm not sure if that means it ONLY supports those two, or if those were just examples.
|
|
#8
|
|||
|
|||
|
Re: Programming ultrasonic rangefinders
You may find this helpful (be sure to grab from my second posting):
http://www.chiefdelphi.com/forums/sh...d.php?t=103028 I posted this last year, it did work, however I wasn't very happy with the sensor itself since it's very easily confused. Another good method for determining range is to roughly compute it from a known target (such as the 3pt goal). |
|
#9
|
||||
|
||||
|
Re: Programming ultrasonic rangefinders
Thanks! How would I call the functions from the main robot cpp file? Is it just
Code:
void GetDistance()
{
AnalogChannel *range;
range = new AnalogChannel(1,1);
float volt;
volt = range->GetVoltage();
float inches; //float meters;
inches = volt * 100; //meters = volt * ???;
return inches;
}
|
|
#10
|
|||||
|
|||||
|
Re: Programming ultrasonic rangefinders
Quote:
You can use the fancier .h file from the thread where you got that code, but that might be more than you're ready to handle. Joe ("DjScribbles") is right here and can help you understand how to use it. Or you can define the AnalogChannel object once at the beginning of your program and leave out the pair of lines that create it every time in the code you copied. |
|
#11
|
||||
|
||||
|
Re: Programming ultrasonic rangefinders
Sorry about that! I knew exactly what you meant, but copied/pasted the pseudo-code from that page assuming that AnalogChannel was the name of the .h file (Having not noticed it at the bottom of the post and not being familiar with the actual AnalogChannel WPI class. Additionally, I'm at school, and the router prohibits me from downloading it for some reason). What I meant was, if I'm using the .h file, how would I make references to it in my own code. Thanks!
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|