Go to Post Our job as mentors isn't to teach them how to make a robot...It's to teach them that there is value in technology and being among the people who create it. - Andy A. [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 04-03-2004, 19:16
bludstayne's Avatar
bludstayne bludstayne is offline
Registered User
#0547
 
Join Date: Nov 2003
Location: Fayetteville, TN
Posts: 10
bludstayne has a little shameless behaviour in the past
Send a message via AIM to bludstayne Send a message via Yahoo to bludstayne
Distance timing out

I have a problem. Whenever I try to find distance between two points the robot controller times out due to the square root calculations. We have a coordinate system of approximately 768x1280 units. Do you think a lookup table would be too large?
__________________
I hate signatures. I wouldn't even consider having one.
  #2   Spotlight this post!  
Unread 04-03-2004, 19:21
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: Distance timing out

square root calculations are the worst

can you leave the number squared and work with it that way?
  #3   Spotlight this post!  
Unread 04-03-2004, 19:29
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Distance timing out

How about having it go to, say, 1 decimal point? with such a large system, you don't need it that precise. And the field is 24' by 48'.
  #4   Spotlight this post!  
Unread 05-03-2004, 11:16
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,567
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Distance timing out

Yes, that would be to big for a standard lookup table. That would be almost a megabyte, if you only looked up a single byte. If you were doing it with floats, it would be even bigger.
  #5   Spotlight this post!  
Unread 05-03-2004, 12:04
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
Re: Distance timing out

Here you go. This based on an algorithm I found on Microchip's web site. It is supposedly optimized for the PIC series chips and will always loop 9 times.

Code:
//return the square root of an unsigned 16 bit integer
//based on sample from microchip.com
unsigned int Sqrt16(unsigned int val)
{
	unsigned int mask = 0x100;
	unsigned int result = 0x80;
	
	while (mask > 0)
	{
		if ((result * result) > val)
		{
			result &= ~mask;
		}
		mask >>= 1;
		result |= mask;
	}
	return result;
}
<edit>
Sorry, I wasn't paying attention. You need a 32-bit version:
Code:
//Return the square root of value x where x is an integer. This
//is based on the fast square root algorithm from microchip.com. 
unsigned long sqrt32(unsigned long x)
{	
	unsigned long mask = 0x1000;
	unsigned long result = 0x800;

	while (mask > 0)
	{
		if ((result * result) > x)
		{
			result &= (~mask);
		}
		mask >>= 1;
		result |= mask;
	}
	return result;
}
</edit>

Last edited by seanwitte : 05-03-2004 at 12:58.
  #6   Spotlight this post!  
Unread 05-03-2004, 13:47
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: Distance timing out

Quote:
Originally Posted by bludstayne
I have a problem. Whenever I try to find distance between two points the robot controller times out due to the square root calculations...
Do you actually need to compute the square root, or can you do what you need to with the square of the distance? For instance, if you're comparing the distance to a constant value, you can change the constant to be the square of what it would otherwise be.
Closed Thread


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
Timing of nats for next year Ian W. Championship Event 13 03-03-2003 18:28
optimum sensing distance for sensors DaveG702 Electrical 3 31-01-2003 22:06
what is or isn't a timing belt? archiver 2001 6 23-06-2002 23:26
two sided timing belt archiver 2001 3 23-06-2002 22:34
Dual Sided Timing Belts Lachuck894 Technical Discussion 9 14-01-2002 10:10


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

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