Go to Post I come to Chief Delphi to get away from the mundane, everyday news. It's part of what makes the forum appealing to me. If I want to read world news, I'll go to digg. - Ryan Dognaux [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
  #16   Spotlight this post!  
Unread 03-01-2004, 11:05
Rickertsen2 Rickertsen2 is offline
Umm Errr...
None #1139 (Chamblee Gear Grinders)
Team Role: Alumni
 
Join Date: Dec 2002
Rookie Year: 2002
Location: ATL
Posts: 1,421
Rickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant future
Send a message via AIM to Rickertsen2 Send a message via Yahoo to Rickertsen2
Re: math.h library

We have a floating point trig lib, but its not exactly as optimized as we would like. we can post it if you want though. Later versions will be MUCH better. The final version will have floating point trig as well as 16-bit brad trig(Which should be about at least 20 times faster than their floatign point counterparts). If there is demand, i will post out math libs under the condition that any work derived from our libraries be posted as well.
__________________
1139 Alumni

Last edited by Rickertsen2 : 03-01-2004 at 11:11.
  #17   Spotlight this post!  
Unread 03-01-2004, 18:49
EricS-Team180's Avatar
EricS-Team180 EricS-Team180 is offline
SPAM, the lunchmeat of superheroes!
AKA: Eric Schreffler
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Apr 2002
Rookie Year: 2001
Location: Stuart, Florida
Posts: 561
EricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond repute
Re: math.h library

Quote:
Originally Posted by Mike Betts
In our case, an integer in 2FX14 format.

ummm...that's a new one me or maybe I'm just missing something obvious...

just what is an FX format? I typically think of x has hex and f as floating point???

Thanks,
Eric
__________________

Don't PANIC!
S. P. A. M.
  #18   Spotlight this post!  
Unread 03-01-2004, 19:36
Joe Johnson's Avatar Unsung FIRST Hero
Joe Johnson Joe Johnson is offline
Engineer at Medrobotics
AKA: Dr. Joe
FRC #0088 (TJ2)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Raynham, MA
Posts: 2,648
Joe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond repute
Re: math.h library

Quote:
Originally Posted by EricS-Team180
ummm...that's a new one me or maybe I'm just missing something obvious...

just what is an FX format? I typically think of x has hex and f as floating point???

Thanks,
Eric

I am not sure of the notation, but if I were writing the sin & cos routines, I would return 16 bit signed number that would be be 2^15 (a.k.a 32768) times the "true" value of the functions. For example, while -1<= Sin <= 1, I would have -32768 <= DrJoeSin <= 32768. Where DrJoeSin = 32768 * Sin

As to Tan this is trickier. My first thought would be to just to just use the definition of tan = sin/cos which would mean tan = DrJoeSin/DrJoeCos. In principle this is okay, but in integer math this is pretty aweful...

...Tan has another problem in that cos can equal zero (or tan can equal infinity). If we are going to return a 16 bit answer, infinity, in this case, is going to have to be 2^15 I suppose.

That still leaves us with a problem. If we are going to use the same basic trick of defining DrJoeTan = ScaleFactor * Tan.

The practical problem is that you don't know where the user of the tan function is going to want his/her function to be accurate. If ScaleFactor is 32768 as in sin and cos, then whenever tan is greater than 1 (that is, whenever abs(theta) > pi/4), DrJoeTan is going to return 32768 (a.k.a. infinity)... ...not exactly a very good result. But then again, in the range that it works (whenever abs(theta) < pi/4), it returns the most data you can expect from a 16 bit number.

Is this a case were we would like to have a modified floating point number format? Perhaps something where we return an exponent and a mantissa? Perhaps it would be even better to have a combined Tan/Sec function that returns a flag telling you if it is returning Sec or Tan and then it returns a 16 bit value for either Tan or Sec depending on which one is less than "infinity"? <-- a crazy idea, but it could be made to work I suppose.

I suppose that this is all a solved problem but I'll be dag nabbed if I have worked it all out already... ...and kickoff is less than a week away...

As another exercise for the user, I have been using radians as my argument for sin, cos, tan, etc. but of course this is non-sense in interger land. Should we define a 16 bit equivalent to PBasic's Brads (all funtions are defined from -32767 to 32768 where 32768 = pi and -32768 = -pi)?

Just more grist for the mill...

Joe J.

P.S. Do you think FIRST really thought all this through for us when the made the leap to C? I suppose not. This is going to be a tough year for folks to learn on. Buckle your seatbelts, it is going to be a bumpy ride...

Last edited by Joe Johnson : 03-01-2004 at 19:44.
  #19   Spotlight this post!  
Unread 07-01-2004, 00:16
Anthony Kesich's Avatar
Anthony Kesich Anthony Kesich is offline
Programmer Turned Engineer
AKA: SonKenshin
#1097 (Site 3 Engineernig)
Team Role: Leadership
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Sacramento, CA
Posts: 186
Anthony Kesich has a spectacular aura aboutAnthony Kesich has a spectacular aura about
Send a message via AIM to Anthony Kesich
inverse trig functions

i found another point of the taylor series to give arcsin.

arcsin(x)= x + (1/2)(x^3/3)+(1/2)(3/4)(x^5/5)+(1/2)(3/4)(5/6)(x^7/7)...

from this we can then derive both arc cos and arctan.

for arccos, use the first and most basic trig Identity:

sin^2(x)+cos^2(x)=1
sin^2(x)=1-cos^2(x)
sin(x)=sqrt(1-cos^2(x))

so just plug the cos value (now called c) into sqrt(1-c^2) then evaluate arcsin using taylor series with the value you pulled out of sqrt(1-c^2).

so arccos(x)=c+(1/2)(c^3/3)+(1/2)(3/4)(c^5/5)+(1/2)(3/4)(5/6)(c^7/7) where c=sqrt(1-cos^2(x)).

now for arctan. I used a triangle.

/|C
/ |
/ |
sqrt(x^2+1) / |
/ | x
/ |
/ |
/ |
A -------B
1

(if the triangle displays correctly, good for you, but if it doesn't, it is set up such that Leg AB is 1, Leg BC is x, angle B is 90 degrees, and hypotenuse AC is sqrt(x^2+1).)

therefore sin(A)=x/sqrt(x^2+1) and tan(A)=x/1=x
so then A=arcsin(x/sqrt(x^2+1)) and A=arctan(x)
therefore arctan(x)=arcsin(x/sqrt(x^2+1))

hope you have fun with this
-Kesich
__________________
C is screwing up my English--I'm ending all my sentences in semi-colons;

Horray for most things! -George Carlin

"Sure, I'll play rugby. Besides, I have a lot of experience running from really big guys who want to cream me." -Me, Freshman year
  #20   Spotlight this post!  
Unread 15-01-2004, 12:42
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: math.h library

Quote:
Originally Posted by Kevin Watson
Well, I shouldn't have made such a generalization. Integer division by powers of two is very fast (if the compiler is designed for such an optimization) because you only need to do a binary right shift to divide a number by two (multiplication works by shifting left). Division of two eighty-bit IEEE floating-point numbers on an eight-bit microcontroller is very painful.
you could always hardcode the bitshift for the division to make sure that the optimization is in, even if the compiler doesn't automatically do it - just replace "x / 16" with "x >> 4"
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #21   Spotlight this post!  
Unread 15-01-2004, 15:37
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: math.h library

Quote:
Originally Posted by deltacoder1020
you could always hardcode the bitshift for the division to make sure that the optimization is in, even if the compiler doesn't automatically do it - just replace "x / 16" with "x >> 4"
"x / 16" with "x >> 3"
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #22   Spotlight this post!  
Unread 15-01-2004, 16:10
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: math.h library

Quote:
Originally Posted by Mike Betts
"x / 16" with "x >> 3"
Oops, Mike. 4 is the right answer.

x >> 0 == x / 1
x >> 1 == x / 2
x >> 2 == x / 4
x >> 3 == x / 8
x >> 4 == x / 16
__________________
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
  #23   Spotlight this post!  
Unread 15-01-2004, 16:17
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: math.h library

Quote:
Originally Posted by gwross
Oops, Mike. 4 is the right answer
I stand corrected...
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #24   Spotlight this post!  
Unread 15-01-2004, 21:16
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: math.h library

also, if you use bitshift to do multiplication by powers of two, make sure you check bounds first, lest you lose significant bits in an overflow.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #25   Spotlight this post!  
Unread 17-01-2004, 13:10
ShadowKnight's Avatar
ShadowKnight ShadowKnight is offline
Registered User
FRC #1719 (Umbrella Corporation)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2003
Location: Alexandria, VA
Posts: 142
ShadowKnight has a spectacular aura aboutShadowKnight has a spectacular aura about
Question Re: math.h library

Quote:
Originally Posted by Mike Betts
Since our team will be using integer arithmetic exclusively on the PIC, we generated a table using Excel (saved as a CSV file) and imported into the PIC code as a table of constants existing in ROM space.

How do you imprt into the ROM space ? I didn't see anything in the reference guide about that.
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
The New and Improved FIRST CAD Library Ed Sparks General Forum 22 03-02-2007 18:03
Pneumatic Valves Posed in First Cad Library Ed Sparks Inventor 0 19-01-2003 17:33
Gear Box Parts Posted on First Cad Library Ed Sparks Inventor 1 10-01-2003 01:54
CAD Library Updated ..... Ed Sparks General Forum 0 21-01-2002 18:19
HELP NEEDED using CAD library ahecht Inventor 9 21-01-2002 11:50


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

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