Go to Post Okay, who's willing to admit they treat their robot as a pet? - Bill Moore [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-01-2013, 11:37
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
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!
Reply With Quote
  #2   Spotlight this post!  
Unread 11-01-2013, 16:16
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 12-01-2013, 22:13
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 12-01-2013, 22:45
DonRotolo's Avatar
DonRotolo DonRotolo is offline
Back to humble
FRC #0832
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Atlanta GA
Posts: 7,011
DonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond repute
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.
__________________

I am N2IRZ - What's your callsign?
Reply With Quote
  #5   Spotlight this post!  
Unread 13-01-2013, 16:40
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
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?
Reply With Quote
  #6   Spotlight this post!  
Unread 13-01-2013, 20:24
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
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.
Reply With Quote
  #7   Spotlight this post!  
Unread 13-01-2013, 22:26
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
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.
Reply With Quote
  #8   Spotlight this post!  
Unread 14-01-2013, 10:26
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 284
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
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).
Reply With Quote
  #9   Spotlight this post!  
Unread 14-01-2013, 11:36
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
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;
}
?
Reply With Quote
  #10   Spotlight this post!  
Unread 14-01-2013, 11:51
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Programming ultrasonic rangefinders

Quote:
Originally Posted by ekapalka View Post
Thanks! How would I call the functions from the main robot cpp file? Is it just
Code:
//schnip
?
Don't use that code. It's simple, obvious, and wrong. You don't want to keep instantiating a new AnalogChannel every time you need to read the distance.

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.
Reply With Quote
  #11   Spotlight this post!  
Unread 14-01-2013, 13:55
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
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!
Reply With Quote
  #12   Spotlight this post!  
Unread 14-01-2013, 14:31
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 284
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
Re: Programming ultrasonic rangefinders

You would instance it much like you would a jaguar, or any other device.

Code:
#include "AnalogRangeFinder.h"

#define ANALOG_CHANNEL_FOR_SONAR 1

class Robot2012 : public IterativeRobot
{
   AnalogRangeFinder sonar;
   public:
   Robot2012(void):sonar(ANALOG_CHANNEL_FOR_SONAR)
   {
   }

   void AutonomousPeriodic(void)
   {
       float distance = sonar.GetRangeInches();
   }
}

START_ROBOT_CLASS(Robot2012);
Reply With Quote
  #13   Spotlight this post!  
Unread 15-01-2013, 17:53
mrklempae mrklempae is offline
Registered User
no team
 
Join Date: Jan 2013
Location: Montana
Posts: 19
mrklempae is an unknown quantity at this point
Re: Programming ultrasonic rangefinders

am I the only person who can't seem to get this to work? I'm not completely sure how to do this, but one of the other programmers (better than myself) tried to get it working to no avail...
Reply With Quote
  #14   Spotlight this post!  
Unread 16-01-2013, 10:50
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 284
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
Re: Programming ultrasonic rangefinders

Quote:
Originally Posted by mrklempae View Post
am I the only person who can't seem to get this to work? I'm not completely sure how to do this, but one of the other programmers (better than myself) tried to get it working to no avail...
The way the sensor is wired is also important, the code I provided is for operating in analog mode (not PWM mode), and the wiring must account for that.

For debugging the sensor itself you can put a multimeter probe on the analog line and see what value it is sending to the cRio (a voltage level that should change the closer the sensor is to something).

Once you see values on the multimeter that correspond to distance, then you debug code. If you need more help, please post actual details on what you've done and what you see.
Reply With Quote
  #15   Spotlight this post!  
Unread 16-01-2013, 15:16
ScottW of MaxBo ScottW of MaxBo is offline
Registered User
no team
 
Join Date: Feb 2008
Location: Brainerd, MN
Posts: 17
ScottW of MaxBo is a glorious beacon of lightScottW of MaxBo is a glorious beacon of lightScottW of MaxBo is a glorious beacon of lightScottW of MaxBo is a glorious beacon of lightScottW of MaxBo is a glorious beacon of lightScottW of MaxBo is a glorious beacon of light
Re: Programming ultrasonic rangefinders

Good day! This is Tom Bonar from MaxBotix Inc.

I was looking through the Chief Delphi forum, and I have noticed that you were having difficulty getting the sensor connected to the cRio. You may wish to consider looking at the quick-start guide (http://maxbotix.com/articles/016.htm) that we created last year. This guide has a walk through on connecting MaxSonar sensors to control devices. The fundamentals are the same for all MaxSonar sensors, with the big difference for connection purposes being the scaling factor of the Analog Voltage output. For calculating this output please view our Analog Voltage article (http://maxbotix.com/articles/032.htm). We have examples for all of our sensors, as well as integrating directly with a 10 bit Analog Digital converter.

We have also kept the notes from last year's FIRST competition on our Facebook page (link to the 3 links from first email)

https://www.facebook.com/photo.php?f...type=3&theater
https://www.facebook.com/notes/maxbo...77662868954588
https://www.facebook.com/notes/maxbo...45549128832627

Please let me know if you have any questions by emailing frc@maxbotix.com.

On behalf of MaxBotix Inc., I wish all the teams a successful build season.

Best regards,

Tom Bonar
Technical Support
of MaxBotix Inc.
Phone: (218) 454-0766
Fax: (218) 454-0768
Email: frc@maxbotix.com
Web: www.maxbotix.com
Follow us on Facebook at: http://www.facebook.com/pages/MaxBot...25159384204938

Technical support and sales are subject to
the terms and conditions listed on our
website at http://www.maxbotix.com/ MaxBotix,
MaxSonar,EZ0, EZ1, EZ2, EZ3, EZ4, AE0, AE1,
AE2, AE3, AE4, WR1, WRA1, and WRLA1 are
trademarks of MaxBotix Inc.
__________________
Best regards,

Scott Wielenberg
Technical Support & Sales
of MaxBotix Inc.
Phone: (218) 764-2489 Ext. 2
Fax: (218) 764-2194
Email: scott@maxbotix.com
Web: www.maxbotix.com
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 03:30.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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