

If poker is a sport, robotics is definitely a sport.  EricH [more] 



Thread Tools  Rate Thread  Display Modes 
#1




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. 
#2




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? 
#3




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

#4




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); double asin(double x); double atan(double x); double atan2(double y, double x); double cos(double x); double cosh(double x); double sin(double x); double sinh(double x); double tan(double x); double tanh(double x); 
#5




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" Last edited by jweric : 01212004 at 05:37 PM. 
#6




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? 
#7




Re: Needing A header file
Quote:

#8




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). 
#9




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. 
#10




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 floatingpoint calculation). I'd suggest sticking with an integer value (maybe in degrees) for the argument to sin(). 
#11




Re: Needing A header file
Forgot, the full website for my trigtables code is:
http://nrg.chaosnet.org/resource/pro...ng/trigtables/ 
#12




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. 
#13




Re: Needing A header file
If you mean the trig functions on my site, the documentation is inside them.

#14




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 floatingpoint 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 // TRIG LOOKUP TABLE IMPLEMENTATION //  // CREATED BY DAV YUST FOR 2004 FIRST ROBOTICS COMPETITION // RELEASED FOR PUBLIC USE UNDER FOLLOWING CONDITIONS: // 1. PLEASE RELEASE ANY CHANGES YOU MAKE // 2. PLEASE GIVE ME CREDIT (somewhere... anywhere) // 3. LEAVE THIS NOTICE IN THE CODE UNCHANGED EXCEPT FOR // NOTICE OF UPDATES // This is a lookup table for the sin() function. // It accepts a degree value between 0 and 89, and // returns a char that is normal sin value multiplied // by 255 and rounded. unsigned char SIN_LOOKUP[90] = { 0, 4, 9, 13, 18, 22, 27, 31, 35, 40, 44, 49, 53, 57, 62, 66, 70, 75, 79, 83, 87, 91, 96, 100,104,108,112,116,120,124, 128,131,135,139,142,146,150,153,157,160, 164,167,171,174,177,180,183,186,190,192, 195,198,201,204,206,209,211,214,216,219, 221,223,225,227,229,231,233,235,236,238, 240,241,243,244,245,246,247,248,249,250, 251,252,253,253,254,254,254,255,255,255 }; ////////////////////////////////////// // MACROS FOR SIN FUNCTION // ////////////////////////////////////// //returns the standard float value from 1 to 1 //accuracy is approximately two digits #define sin(x) ( ((x) < 90 ? (float)SIN_LOOKUP[(x)] : ( (x) < 180 ? (float)SIN_LOOKUP[179(x)] : ( (x) < 270 ? 1.0 * (float)SIN_LOOKUP[(x)180] : 1.0 * (float)SIN_LOOKUP[359(x)]))) / 255.0) //returns a signed char value from 128 to 127 //we have to divide by two here because a signed char //can only go from 128 to 127. #define sin_char(x) ( ((x) < 90 ? SIN_LOOKUP[(x)] : ( (x) < 180 ? SIN_LOOKUP[179(x)] : ( (x) < 270 ? 1 * SIN_LOOKUP[(x)180] : 1 * SIN_LOOKUP[359(x)]))) >> 1) //because cos is handily equal to sin(x  90) (or sin(x+270) #define cos(x) sin( ((x) + 270) % 360 ) #define cos_char(x) sin_char( ((x) + 270) % 360 ) //////////////////////////////////////////////////////////////////////////////// // ALL CODE BELOW FOR TESTING PURPOSES ONLY //////////////////////////////////////////////////////////////////////////////// #include <stdio.h> int main(int argc, char* argv[]) { printf("Testing SIN lookup table:\n"); printf(" angle (deg) sin() sin_char() cos() cos_char()\n"); int x; for(x = 0; x < 360; x += 15) { printf("%15i%15f%15i%15f%15i\n", x, sin(x), sin_char(x), cos(x), cos_char(x)); } return 0; } Last edited by deltacoder1020 : 01212004 at 10:12 PM. 
#15




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. 
Thread Tools  
Display Modes  Rate This Thread 


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
First Logo as a CAD file  jrgrim12  Inventor  4  02142003 10:42 AM 
The need for File Maker Pro 5 Dev. Edition  archiver  2000  1  06232002 09:50 PM 
Dashv2.ocx dependency file now available  archiver  2000  0  06232002 09:00 PM 
Improving PBASIC: Request for Comments  Greg Ross  Programming  19  02162002 09:14 PM 