![]() |
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. |
| All times are GMT -5. The time now is 11:01 PM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi