Go to Post Coaxial swerve modules with a suspension and differential aren't normal. But on Winnovation they are. - Andrew Schreiber [more]
Home
Go Back   Chief Delphi > ChiefDelphi.com Website > Extra Discussion
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-03-2004, 06:54
CD47-Bot CD47-Bot is offline
Registered User
FRC #0047 (Chief Delphi)
 
Join Date: Dec 2002
Location: Pontiac, MI
Posts: 1,616
CD47-Bot has a reputation beyond reputeCD47-Bot has a reputation beyond reputeCD47-Bot has a reputation beyond reputeCD47-Bot has a reputation beyond reputeCD47-Bot has a reputation beyond reputeCD47-Bot has a reputation beyond reputeCD47-Bot has a reputation beyond reputeCD47-Bot has a reputation beyond reputeCD47-Bot has a reputation beyond reputeCD47-Bot has a reputation beyond reputeCD47-Bot has a reputation beyond repute
White Paper Discuss: 296's CORDIC Math Library

Thread created automatically to discuss a document in the White Papers.

296's CORDIC Math Library by Pat Fairbank

Last edited by Brandon Martus : 30-10-2004 at 12:22.
Reply With Quote
  #2   Spotlight this post!  
Unread 11-03-2004, 06:58
Pat Fairbank's Avatar
Pat Fairbank Pat Fairbank is offline
Circuit Breaker
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2001
Location: San Jose, CA
Posts: 2,132
Pat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond repute
Send a message via MSN to Pat Fairbank
Re: White Paper Discuss: 296's CORDIC Math Library

Hello all,

We at 296 decided to share our student-developed math library with the CD community. We needed trig functions for our robot positioning system, so we wrote our own using the CORDIC algorithm. The library includes integer sine, cosine, and arctangent, all accurate to +- 1/16777216, as well as a few other useful functions.

I hope this comes in useful for those of you who need accurate trig functions.
__________________
Patrick Fairbank
Team 254 | Mentor (2012-)
Team 1503 | Mentor (2007-2011)
Team 296 | Alumnus (2001-2004) | Mentor (2005-2006)

patfairbank.com
Reply With Quote
  #3   Spotlight this post!  
Unread 12-03-2004, 13:55
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: White Paper Discuss: 296's CORDIC Math Library

A "Short Long"? Isn't this contradictive? or just an oxymoron? I thought there were short ints and long ints.
Reply With Quote
  #4   Spotlight this post!  
Unread 12-03-2004, 17:55
Pat Fairbank's Avatar
Pat Fairbank Pat Fairbank is offline
Circuit Breaker
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2001
Location: San Jose, CA
Posts: 2,132
Pat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond repute
Send a message via MSN to Pat Fairbank
Re: White Paper Discuss: 296's CORDIC Math Library

Well, short ints are 16 bit, long ints are 32, and I guess that they needed a name for a 24 bit int, so they called it a short long.
__________________
Patrick Fairbank
Team 254 | Mentor (2012-)
Team 1503 | Mentor (2007-2011)
Team 296 | Alumnus (2001-2004) | Mentor (2005-2006)

patfairbank.com
Reply With Quote
  #5   Spotlight this post!  
Unread 27-04-2004, 21:51
mtrawls's Avatar
mtrawls mtrawls is offline
I am JVN! (John von Neumann)
#0122 (NASA Knights)
Team Role: Programmer
 
Join Date: Mar 2003
Location: Hampton, VA
Posts: 295
mtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to behold
Send a message via AIM to mtrawls
Re: White Paper Discuss: 296's CORDIC Math Library

We didn't use trig in our final implementation ... but in testing we did consider it, and also decided on the CORDIC algorithm. There is an added advantage of CORDIC that your library currently doesn't utilize -- it can compute both the sin and cosine at the same time (which you do, but then you throw one of them away). For our trig needs, anyway, we needed the sin and cos of the same angles.

Implementing this in a math library (admittedly more general than our custom implementation), would be interesting conceptually. Maybe create a structure called angle.
Code:
struct angle {
  short long angle;
  short long sin, cos;
  ...
};
...
short long Sin (angle ang) {
  ...
  ang.cos = blah;
  ang.sin = more blah;
  return ang.sin;
}
This function in addition to the normal sin function (i.e., that doesn't take a struct as an argument). Maybe this is too much for something that is too specific, whereas this is a general library. But then again, maybe other teams had the same need as we did, and could stand to benefit from not doing extraneous processing. Note that all this is off the top of my head without thinking about it as often as I ought to (which for some reason is why I end up with bugs in my code ... go figure). I can imagine other implementations, equally or more valid than this -- this suggestion is more conceptual than offering actual code implementation.
Reply With Quote
  #6   Spotlight this post!  
Unread 28-04-2004, 20:01
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: White Paper Discuss: 296's CORDIC Math Library

Quote:
Originally Posted by mtrawls
We didn't use trig in our final implementation ... but in testing we did consider it, and also decided on the CORDIC algorithm. There is an added advantage of CORDIC that your library currently doesn't utilize -- it can compute both the sin and cosine at the same time (which you do, but then you throw one of them away). For our trig needs, anyway, we needed the sin and cos of the same angles.

Implementing this in a math library (admittedly more general than our custom implementation), would be interesting conceptually. Maybe create a structure called angle....
I have not really looked into CORDIC before. It's interesting that it computes both sine and cosine at the same time. And I like your idea of making them both available. I think I would probably choose an approach where I just save both values, and then the next time a sine or cosine is called for, check to see if the angle is the same as last time. If it is, then I could just return the previous value. Granted there is something to to say for your idea of the struct, because it would be simple that way, to save the trig functions for a few commonly used angles.

Be that as it may, here's my suggestion of an implementation:
Code:
typedef enum {wantsSin, wantsCos} WhichFunc;

short long cordic(short long theAngle, WhichFunc theRequestedFunction)
{
	static char firstTime = 1;
	static short long prevAngle;
	static short long prevSin;
	static short long prevCos;

	unsigned char i;
	short long X = K, Y = 0, t = theAngle;
	short long dx, dy;

	// If this is the first time the function has been called, or if the
	// requested angle is different than the last time, then go ahead and
	// calculate the sine and cosine, otherwise we can skip the calculations,
	// and just return the value calculated last time.
		
	if (firstTime || (theAngle != prevAngle)) {
		if ((long) abs((long)theAngle) > 4194304)
			t = (short long) sgn((long) theAngle) * (8388608 - (short long) abs(theAngle));

		for (i = 0; i < 23; i++) {
			dx = sgn((long) X) * ((unsigned short long) abs((long) X) >> i);
			dy = sgn((long) Y) * ((unsigned short long) abs((long) Y) >> i);
			X -= (t > 0) ? dy : -dy;
			Y += (t > 0) ? dx : -dx;
			t -= (t > 0) ? e[i] : -e[i];
		} // for

		if (abs((long) theAngle) > 4194304) X = -X;

		firstTime = 0;
		prevAngle = theAngle;
		prevSin = Y;
		prevCos = X;
	} // if (firstTime ...

	if (theRequestedFunction == wantsSin)
		return prevSin;
	else
		return prevCos;
}

short long sin(short long theAngle)
{
	return cordic(theAngle, wantsSin);
}

short long cos(short long theAngle)
{
	return cordic(theAngle, wantsCos);
}
Note I took some liberties with team 296's code to suit my own personal preferences. You can take it or leave it:
  • I unrolled the nested ::gasp:: ternary operators in the return statement to make it more readable.
  • I changed the name of the "ang" parameter to theAngle, so that someone unfamiliar with the code won't have to stop and think "Ang? What's that? Anger? Angst? Angstrom? Automatic Number Generator?" (Yeah, I know it's FAIRLY obvious from the context, but I prfr rdg fl wrds nstd f abbrvs. cn u dg it?)
  • I changed the name of the second parameter of the cordic() routine (again so it's more obvious what the parameter is used for) and I made it an enum so that you never have to wonder whether 0 or 1 means sine or cosine.
  • I added a couple of end brace comments so it's easier to match up opening and closing braces.
  • I moved the cordic() function in front of sin() and cos(), so I wouldn't need a prototype for cordic().
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me

Last edited by Greg Ross : 28-04-2004 at 21:24.
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
White Paper Discuss: All I Ever Needed to Know I learned in FIRST poster CD47-Bot Extra Discussion 5 28-03-2005 15:44
White Paper Discuss: Interrupts for Dummies CD47-Bot Extra Discussion 5 29-01-2005 03:24
White Paper Discuss: Team 810's 2004 Dashboard Backend CD47-Bot Extra Discussion 1 07-03-2004 10:32
White Paper Discuss: Controller Circuit- Infrared Emitters CD47-Bot Extra Discussion 1 13-02-2004 17:48
Some code in C that we may need if we are in trouble Andrew Rudolph Chit-Chat 16 07-10-2003 21:34


All times are GMT -5. The time now is 10:28.

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