Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Ultrasonics / Sonar (http://www.chiefdelphi.com/forums/showthread.php?t=74507)

nekng 14-02-2009 22:08

Ultrasonics / Sonar
 
I have spent literally hours trying to figure this out, could someone post every single step involved in programming ultrasonic sensors using the interactive robot class?

wt200999 14-02-2009 23:43

Re: Ultrasonics / Sonar
 
You need to give more details....

What sensor are you using, and maybe a bit of the code you are trying to use?

nekng 15-02-2009 00:40

Re: Ultrasonics / Sonar
 
We are using vex ultrasonic sensors.

wt200999 15-02-2009 00:50

Re: Ultrasonics / Sonar
 
The code should work fine with that, have you looked at page 46 of the "C Programming Guide for FRC"? What kind of results do you get.

Shira 15-02-2009 01:34

Re: Ultrasonics / Sonar
 
Hey, I'm working with Nate (who started this thread) on the code and here's what happens:

In the class variables declaration:
Ultrasonic *m_ultra;
double range;
static const UINT32 pingChannel=1;
static const UINT32 echoChannel=2;


In the constructor:
m_ultra = new Ultrasonic(pingChannel, echoChannel);
m_ultra->SetAutomaticMode(true);
range = m_ultra->GetRangeInches();


But when I print out the range I get only zeros. Actually, I've gotten other values with that code occasionally (still not functional though, just random values that don't update often at all), but we tested so many sensors and configurations that I am not convinced it is a hardware problem.

Also, I can't get that sample code from the Programming Guide to work. I get compiler errors. I've tried a number of things, but unless i use that code with pointers, I can't get the code to compile.

So can anyone give some sample code, or detailed instructions, on how they set up their ultrasonic sensors?

Alan Anderson 15-02-2009 13:44

Re: Ultrasonics / Sonar
 
Quote:

Originally Posted by Shira (Post 821076)
Code:

double range;
 :
range = m_ultra->GetRangeInches();

But when I print out the range I get only zeros. Actually, I've gotten other values with that code occasionally...

How are you printing it? If your format specifier doesn't match the variable type, it won't work properly.

nekng 15-02-2009 16:35

Re: Ultrasonics / Sonar
 
Quote:

Originally Posted by Alan Anderson (Post 821299)
How are you printing it? If your format specifier doesn't match the variable type, it won't work properly.

We are using a %f to print it.

Alan Anderson 15-02-2009 20:11

Re: Ultrasonics / Sonar
 
Quote:

Originally Posted by Shira (Post 821076)
In the constructor:
Code:

m_ultra = new Ultrasonic(pingChannel, echoChannel);       
m_ultra->SetAutomaticMode(true);
range = m_ultra->GetRangeInches();

But when I print out the range I get only zeros.

Are you ever setting range anywhere else? The assignment in the constructor most likely occurs before any echoes have been received, so it won't be a valid value. I believe calling m_ultra->GetRangeInches() later should give you the current range.

Shira 15-02-2009 23:28

Re: Ultrasonics / Sonar
 
Quote:

Originally Posted by Alan Anderson (Post 821559)
Are you ever setting range anywhere else? The assignment in the constructor most likely occurs before any echoes have been received, so it won't be a valid value. I believe calling m_ultra->GetRangeInches() later should give you the current range.

We're calling it in Autonomous Periodic or Autonomous Continuous (I'm not sure where we're going to put our code yet but I think it is all going to go in autonomous continuous unless there is a good reason not to..)

There is no other setting of the range anywhere else. I declare the var in the class and then I set the range to the value returned by the get range function.

X-Istence 17-02-2009 14:03

Re: Ultrasonics / Sonar
 
Check to see if the Range is valid, using the function:

Code:

IsRangeValid()
It will return a boolean letting you know if the sensors have fired yet and some result has come back.


All times are GMT -5. The time now is 02:41.

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