Go to Post Think outside the bot. Find a different regional someplace you never considered before. There's plenty of them. - Koko Ed [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 19-02-2007, 20:56
Andrew Blair's Avatar
Andrew Blair Andrew Blair is offline
SAE Formula is FIRST with Gasoline.
FRC #0306 (CRT)
Team Role: Alumni
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Corry
Posts: 1,193
Andrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond reputeAndrew Blair has a reputation beyond repute
Send a message via AIM to Andrew Blair Send a message via Yahoo to Andrew Blair
Sonar Function Issue

I am using the Maxbotics sensor, obtaining data through the AD, and need to find the difference between two consecutive readings. In the following, I have a distance function that returns the distance to the target in inches, and I use that number in the following function delta_distance() to find the difference between consecutive readings.

The problem is, when I run the thing, my return is always the inverse of the actual distance reading, and the issue is, solved with a printf, that my temp variable is never changing. It remains at zero constantly.

Code:
/*******************************************************************************
* FUNCTION NAME: distance
* PURPOSE:       returns a realtime distance from sonar, in inches
* CALLED FROM:   This file
* ARGUMENTS:     
*     Argument       Type             IO   Description
*     --------       -------------    --   -----------
*    none
* RETURNS:       unsigned int
*******************************************************************************/

unsigned int distance(void)
{

             return (unsigned int) Get_Analog_Value(rc_ana_in01)/s;
}




/*******************************************************************************
* FUNCTION NAME: delta_distance
* PURPOSE:      returns difference in range readings between cycles
* CALLED FROM:   This file
* ARGUMENTS:     
*     Argument       Type             IO   Description
*     --------       -------------    --   -----------
*    none
* RETURNS:       signed int
*******************************************************************************/
int delta_distance(void)
{
    int temp;
    
    temp -= distance();

    return (int) temp;

    temp=distance;
}
As well, if anyone can quickly through up a workable averaging function I'd be much obliged. I've tried without success, typically ending up with a constantly incrementing distance value, or erratic jumping output.
Code:
/*******************************************************************************
* FUNCTION NAME: distance
* PURPOSE:       returns a realtime distance from sonar, in inches
* CALLED FROM:   This file
* ARGUMENTS:     
*     Argument       Type             IO   Description
*     --------       -------------    --   -----------
*    none
* RETURNS:       unsigned int
*******************************************************************************/

unsigned int distance(void)
{
 unsigned int temp;
 i++;
 unsigned int Distance;
 
 temp+= (Get_Analog_Value(rc_ana_in01)/2)

 if (i>=5)
    {
          Distance=temp/i;
          i=0;
          
    }         


             return (unsigned int)Distance;
}
Thanks!
__________________
Reading makes a full man, conference a ready man, and writing an exact man.
-Sir Francis Bacon

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
-Albert Einstein
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
SONAR Sensor Software Driver MikeDubreuil Programming 55 08-03-2008 11:03
Maxbotix Sonar Sensor DonRotolo Electrical 17 04-02-2007 12:27
VEX Sonar question Joohoo Programming 2 06-05-2006 01:18
Help with sonar sensor supertw Electrical 3 24-01-2006 23:41
FreeLibrary() Function Raven_Writer Programming 0 09-08-2003 15:39


All times are GMT -5. The time now is 04:52.

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