|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
I need to use some trig functions in some code that I'm writing for our kiwi drive train. Does anyone know where to find C libraries (specifically the math.h)? I've found the GNU C library but didn't think it would work because it said that it only ran on GNU systems. All I need is simple sin cos and tan funcs.
peace. bill |
|
#2
|
|||||
|
|||||
|
Re: math.h library
Hi.
I recall that Mike Betts and Dr. Joe had some good comments on trig functions in this thread: http://www.chiefdelphi.com/forums/sh...highlight=trig (named "Edurobot and arrays" from November, in this forum) For just sin, cos and tan, you might want to make a linear table lookup. I've downloaded the cmath library from www.netlib.org/cephes, but I haven't tried it out on the edu rc Eric |
|
#3
|
|||||
|
|||||
|
Re: math.h library
thanks alot. i'll check it out. although i did find that math.h does in fact come with the compiler after doing a search on my comp.
|
|
#4
|
|||||
|
|||||
|
Re: math.h library
whats a linear table lookup?
|
|
#5
|
|||
|
|||
|
Re: math.h library
Quote:
You can use an approximation called the Maclaurin series for Sine, Cosine, and Tangent. The formulas are listed below. The angle, x, is in radians. There are 2*Pi radians in a circle, so 360 degrees = 2*Pi radians. These formulas match the actual Sine, Cosine, and Tangent to three decimal points. Sine(x) = x - x^3/3! + x^5/5! Cosine(x) = 1 - x^2/2! + x^4/4! Tangent(x) = x + 2x^3/3! + 16x^5/5! This is a special case of the Taylor series, which I'll leave to you look up. The Taylor series would allow you to reduce the number of terms you're calculating by using know values of Sin/Cos/Tan near the angle you're looking for. The ! is the factorial operator and just means to take the number and multiple it by every number between it and 0. 3! = 3*2*1 = 6 4! = 4*3*2*1 = 24 |
|
#6
|
||||
|
||||
|
Re: math.h library
A Taylor Series expansion solution for sine and cosine would look like this (if you are doing floating point arithmetic) with angle in radians:
angle_pow_2 = angle * angle; sin_angle = -0.0001984127 + (angle_pow_2 * 0.0000027557); sin_angle = 0.0083333333 + (angle_pow_2 * sin_angle); sin_angle = -0.1666666667 + (angle_pow_2 * sin_angle); sin_angle = 1.0 + (angle_pow_2 * sin_angle); sin_angle = angle * sin_angle; cos_angle = -0.0013888889 + (angle_pow_2 * 0.0000248016); cos_angle = 0.0416666667 + (angle_pow_2 * cos_angle); cos_angle = -0.5000000000 + (angle_pow_2 * cos_angle); cos_angle = 1.0 + (angle_pow_2 * cos_angle); 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. Note that only sine from 0 to 90 degrees is required as the function is symmetrical. Both cosine and tangent can be mathematically generated from the sine. The problem with math.h is that it returns a double and you really do not want to do floating point on your 'bot. The nice thing about a table lookup is that you control the format of the stored (returned) variable. In our case, an integer in 2FX14 format. Hope this helps. |
|
#7
|
|||||
|
|||||
|
Re: math.h library
sweeeeetness. this rocks. i've got a few questions.
do you suggest reading all of the values from 0-90 (in fact you'd only need 0-45 because sin (46-90) = 1 - sin (0-45)) into a matrix or actually calculating them? I'm also confused as to the difference between ROM and RAM space. I know what the acronyms stand for but thats about it. why no floating points? is it too much for it to handle? are there any other things i should stay away from calculation/variable wise? |
|
#8
|
||||
|
||||
|
Re: math.h library
Quote:
-Kevin |
|
#9
|
|||||
|
|||||
|
Re: math.h library
whoa.. that CORDIC is rather confusing stuff. I'm going to play with it and see if i can figure it out a little more.
so you are saying that I should stay away from dividing two numbers? (the question sounds dumb but i'm very surprised that it would be so tough) I remember reading that it can handle addition VERY well but doesn't do much else as quick. thanks for the quick reply. |
|
#10
|
||||
|
||||
|
Re: math.h library
Quote:
.Quote:
-Kevin |
|
#11
|
||||
|
||||
|
Re: math.h library
Quote:
-Kevin |
|
#12
|
||||
|
||||
|
Re: math.h library
Quote:
|
|
#13
|
||||
|
||||
|
Re: math.h library
Quote:
|
|
#14
|
||||
|
||||
|
Re: math.h library
Quote:
Quote:
Quote:
|
|
#15
|
|||||
|
|||||
|
Re: math.h library
Quote:
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 |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |