![]() |
Needing A header file
Ok, I am geting flustered since I can't perform trigonometric functions with the tools FIRST provides.
So I was wondering if anyone has a header file that can perform trigonometric functions in the programing. The reason why I need it is for our teams drive system. |
Re: Needing A header file
You want a header file?
Or do you want actual coded implementation? Then wouldn't you want a .c file, as well? |
Re: Needing A header file
all I need is the .h so I can implement it into my coding, unless I need a .c file along with it
|
Re: Needing A header file
You code either find a C version of "math.h". I just wrote a smaller version with only basic trig functions declared:
Code:
double acos(double x); |
Re: Needing A header file
So I would just put in the var declorations in the user_routine.c?
I am still sort of new to the world of C. If you did put it in the var declorations, then somthing isn't working. Because I am geting "The 'sin' symbol is not reconized" |
Re: Needing A header file
Quote:
<< Edit >>: Is it legal/allowed to upload those files here? Like, the files from MSVS, or some other c/++ compiler? |
Re: Needing A header file
Quote:
|
Lookup Tables
Quote:
You can generate lookup tables. Store these in arrays. Then a sin() function, for example, would simply look up the closest value of sin. There is almost no where you would need (and could practically use) more accurate values for trig functions. If I have time, I'll write some code to do that for sine. Check this site: http://nrg.chaosnet.org/uploads/resources for updates. P.S: Cosine and tangent can be calculated for sine because cos(angle)=sin(angle+90 degrees) and tan=sin(angle)/sin(angle+90 degrees). |
Re: Needing A header file
Their is a problem with that. If I cant do an Inverse trig function, I cannot find the angle.
You see, this is going to used in our drive system this year. The way our drive system works this year is you point the joystick any direction you want and it will go in that direction. The problem I am having is that when I reach certain values (mainly by the corners) you would overflow the PWMs and would cause the motors to go in the wrong direction. I would provide a drawing of this but they are at my school, and unreachable. But the formula I would be using for one of the pwms is: PWM = p1_y - sin(1.4172 * p1_x - 127) Their is a way to do it with mutiple formulas but that will take a lot of programing and I am only one person that does the programing. Not to mention I do the 3ds MAX and Designing. I just dont have that kind of time to need to figure out all the equations for all four PWMs. With this route I only need 2. If you want this diagram then I can post it tomorrow. P. S. - I did a google search and I turned up one that required multiple other header files which wernt provided. |
Re: Needing A header file
Quote:
Anyway, why are you using floating point? Are you sure you want to do that? It slows the processor down, and if you'll be using "true" trig functions, you'll slow it down even more. (That's another point where lookup tables help. They're moderately fast, b/c pointer arithmatic is much faster than floating-point calculation). I'd suggest sticking with an integer value (maybe in degrees) for the argument to sin(). |
Re: Needing A header file
Forgot, the full website for my trigtables code is:
http://nrg.chaosnet.org/resource/pro...ng/trigtables/ |
Re: Needing A header file
the reason why I must use a float point is because I need to have correct values, saddly I cant do it any other way.
Well the only other way of doing it is by breaking it into four equations and I am not sure how It could work. You know what I need over here is a mathmetition that knows C. The only thing I have close to that is myself. Also how do I use these functions? I dont have a tutorial that details this. |
Re: Needing A header file
If you mean the trig functions on my site, the documentation is inside them.
|
Re: Needing A header file
I've coded from scratch a basic sin lookup table and associated macros to fetch the correct values for sin() and cos(), either in float or char (float * 127, rounded) form. Note that using the sin_char() and cos_char() macros requires no floating-point arithmetic, if speed is your goal, those functions are for you. If you need more than approx. 2 digits accuracy for floating point values, feel free to replace the array of unsigned chars with unsigned ints, and modify the macros accordingly. Code is below.
Code:
// LOOKUP.C |
Re: Needing A header file
A good approximation for any trig function (or any other function, for that matter) is called the MacLaurin series. check out this website:
http://mathworld.wolfram.com/MaclaurinSeries.html Anyway, this only works in radians and from -pi/2 to pi/2. It also requires some floating point math. |
Re: Needing A header file
Quote:
An example variable declaration could be: integer max_v; // 2FX12 (0x1000 = 1 foot/sec) In the above example, the resolution of the variable for maximum velocity is 0.003 inches per second and the variable ranges from + +7.99975 to -7.99975 feet per second. Choose your number system with care and beware of overflowing variables in your calculations. Also realize that 0x8000 (negative zero) is not a number! I assure you that the 2004 Bobcat has no floating-point variables and, sensor accuracy notwithstanding, the mathematical accuracy of our position is less than a tenth of an inch. Best of luck, |
Re: Needing A header file
Can you give me a tutorial or example where I can learn more about this? ALl i've learned so far for decimal points is floating point data types. APpreciate any info.
|
Re: Needing A header file
Quote:
Unfortunately, everything I have is in books. You might try to google it. |
Floating Point Tutorial
Quote:
Most important thing about floating point: DO NOT use unless absolutely neccessary. Any computation with floating-point data (like floats or doubles) is much slower than the same operation with integers (like chars, ints, and longs).Floating-point data is different than other data because the number that the data itself represents is not directly stored. Instead, a mantissa, sign, and exponent are stored. This is sort of like scientific notation where you know the exponent which for the base 10 and the multiplier. In floating-point, you store every number as: [sign] [mantissa] x 2 ^ ([exponent]) The 2 is not stored because it is the same for every number. Sign is 0 if the number is positive, and 1 if the number is negative (only one bit stored). Exponents must account for both negative and positive exponents, hence the exponent has a bias. This means that a positive number is added to all exponents in order to make every possible exponent positive. Mantissas, get information here: http://research.microsoft.com/~holla...ieeefloat.html Hope this helps! |
Re: Needing A header file
Quote:
It should get you started... |
| All times are GMT -5. The time now is 09:28. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi