OCCRA
Go to Post When I had "shop" back in High School they emphazied safety to the fullest extreme. I'm glad they did, I still have a full set of 7 fingers........ - Stillen [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Events   CD-Media   CD-Spy   FRC-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-21-2004, 05:51 PM
jweric jweric is offline
Registered User
#1322
 
Join Date: Jan 2004
Location: Fenton, MI
Posts: 6
jweric is an unknown quantity at this point
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   Spotlight this post!  
Unread 01-21-2004, 05:58 PM
SilverStar's Avatar
SilverStar SilverStar is offline
948 Alum
AKA: Advay Mengle
FRC #0948 (Newport Robotics Group)
Team Role: Leadership
 
Join Date: Mar 2002
Rookie Year: 2001
Location: USA
Posts: 368
SilverStar is just really niceSilverStar is just really niceSilverStar is just really niceSilverStar is just really nice
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?
__________________
-- Advay Mengle
NRG Team 948 Alum
2005 Pacific NW Seed 1 (and... waiting for finals...)
2005 Pacific NW Finalists with 1359 and 1569
2004 Pacific NW Semifinalists, Seed 4
2004 Pacific NW Quarterfinalists
2003 Pacific NW Team Spirit Award, Quarterfinalists, Seed 5
  #3   Spotlight this post!  
Unread 01-21-2004, 06:06 PM
jweric jweric is offline
Registered User
#1322
 
Join Date: Jan 2004
Location: Fenton, MI
Posts: 6
jweric is an unknown quantity at this point
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   Spotlight this post!  
Unread 01-21-2004, 06:14 PM
SilverStar's Avatar
SilverStar SilverStar is offline
948 Alum
AKA: Advay Mengle
FRC #0948 (Newport Robotics Group)
Team Role: Leadership
 
Join Date: Mar 2002
Rookie Year: 2001
Location: USA
Posts: 368
SilverStar is just really niceSilverStar is just really niceSilverStar is just really niceSilverStar is just really nice
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);
__________________
-- Advay Mengle
NRG Team 948 Alum
2005 Pacific NW Seed 1 (and... waiting for finals...)
2005 Pacific NW Finalists with 1359 and 1569
2004 Pacific NW Semifinalists, Seed 4
2004 Pacific NW Quarterfinalists
2003 Pacific NW Team Spirit Award, Quarterfinalists, Seed 5
  #5   Spotlight this post!  
Unread 01-21-2004, 06:17 PM
jweric jweric is offline
Registered User
#1322
 
Join Date: Jan 2004
Location: Fenton, MI
Posts: 6
jweric is an unknown quantity at this point
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 : 01-21-2004 at 06:37 PM.
  #6   Spotlight this post!  
Unread 01-21-2004, 07:21 PM
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Re: Needing A header file

Quote:
Originally Posted by jweric
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"
Try searching Google or Yahoo for a math.h (and a math.c) file. Or, if you know how the math functions you need actually work (like squareing is x * x), you can just program them yourself.

<< Edit >>: Is it legal/allowed to upload those files here? Like, the files from MSVS, or some other c/++ compiler?
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #7   Spotlight this post!  
Unread 01-21-2004, 07:24 PM
SilverStar's Avatar
SilverStar SilverStar is offline
948 Alum
AKA: Advay Mengle
FRC #0948 (Newport Robotics Group)
Team Role: Leadership
 
Join Date: Mar 2002
Rookie Year: 2001
Location: USA
Posts: 368
SilverStar is just really niceSilverStar is just really niceSilverStar is just really niceSilverStar is just really nice
Re: Needing A header file

Quote:
Originally Posted by Raven_Writer
Is it legal/allowed to upload those files here?
I highly doubt that. The example I gave above is not from someone else's source code. However, depending on whether the source has a GPL (license) on it, you might be able to put it in the White Papers section or attach it.
__________________
-- Advay Mengle
NRG Team 948 Alum
2005 Pacific NW Seed 1 (and... waiting for finals...)
2005 Pacific NW Finalists with 1359 and 1569
2004 Pacific NW Semifinalists, Seed 4
2004 Pacific NW Quarterfinalists
2003 Pacific NW Team Spirit Award, Quarterfinalists, Seed 5
  #8   Spotlight this post!  
Unread 01-21-2004, 07:30 PM
SilverStar's Avatar
SilverStar SilverStar is offline
948 Alum
AKA: Advay Mengle
FRC #0948 (Newport Robotics Group)
Team Role: Leadership
 
Join Date: Mar 2002
Rookie Year: 2001
Location: USA
Posts: 368
SilverStar is just really niceSilverStar is just really niceSilverStar is just really niceSilverStar is just really nice
Lookup Tables

Quote:
Originally Posted by jweric
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.
There is another way.

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).
__________________
-- Advay Mengle
NRG Team 948 Alum
2005 Pacific NW Seed 1 (and... waiting for finals...)
2005 Pacific NW Finalists with 1359 and 1569
2004 Pacific NW Semifinalists, Seed 4
2004 Pacific NW Quarterfinalists
2003 Pacific NW Team Spirit Award, Quarterfinalists, Seed 5
  #9   Spotlight this post!  
Unread 01-21-2004, 07:49 PM
jweric jweric is offline
Registered User
#1322
 
Join Date: Jan 2004
Location: Fenton, MI
Posts: 6
jweric is an unknown quantity at this point
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   Spotlight this post!  
Unread 01-21-2004, 07:54 PM
SilverStar's Avatar
SilverStar SilverStar is offline
948 Alum
AKA: Advay Mengle
FRC #0948 (Newport Robotics Group)
Team Role: Leadership
 
Join Date: Mar 2002
Rookie Year: 2001
Location: USA
Posts: 368
SilverStar is just really niceSilverStar is just really niceSilverStar is just really niceSilverStar is just really nice
Re: Needing A header file

Quote:
Originally Posted by jweric
Their is a problem with that. If I cant do an Inverse trig function, I cannot find the angle.
...
But the formula I would be using for one of the pwms is:

PWM = p1_y - sin(1.4172 * p1_x - 127)
You can use the approach I described above for inverse sine and sine.

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().
__________________
-- Advay Mengle
NRG Team 948 Alum
2005 Pacific NW Seed 1 (and... waiting for finals...)
2005 Pacific NW Finalists with 1359 and 1569
2004 Pacific NW Semifinalists, Seed 4
2004 Pacific NW Quarterfinalists
2003 Pacific NW Team Spirit Award, Quarterfinalists, Seed 5
  #11   Spotlight this post!  
Unread 01-21-2004, 07:55 PM
SilverStar's Avatar
SilverStar SilverStar is offline
948 Alum
AKA: Advay Mengle
FRC #0948 (Newport Robotics Group)
Team Role: Leadership
 
Join Date: Mar 2002
Rookie Year: 2001
Location: USA
Posts: 368
SilverStar is just really niceSilverStar is just really niceSilverStar is just really niceSilverStar is just really nice
Re: Needing A header file

Forgot, the full website for my trigtables code is:

http://nrg.chaosnet.org/resource/pro...ng/trigtables/
__________________
-- Advay Mengle
NRG Team 948 Alum
2005 Pacific NW Seed 1 (and... waiting for finals...)
2005 Pacific NW Finalists with 1359 and 1569
2004 Pacific NW Semifinalists, Seed 4
2004 Pacific NW Quarterfinalists
2003 Pacific NW Team Spirit Award, Quarterfinalists, Seed 5
  #12   Spotlight this post!  
Unread 01-21-2004, 08:15 PM
jweric jweric is offline
Registered User
#1322
 
Join Date: Jan 2004
Location: Fenton, MI
Posts: 6
jweric is an unknown quantity at this point
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   Spotlight this post!  
Unread 01-21-2004, 08:17 PM
SilverStar's Avatar
SilverStar SilverStar is offline
948 Alum
AKA: Advay Mengle
FRC #0948 (Newport Robotics Group)
Team Role: Leadership
 
Join Date: Mar 2002
Rookie Year: 2001
Location: USA
Posts: 368
SilverStar is just really niceSilverStar is just really niceSilverStar is just really niceSilverStar is just really nice
Re: Needing A header file

If you mean the trig functions on my site, the documentation is inside them.
__________________
-- Advay Mengle
NRG Team 948 Alum
2005 Pacific NW Seed 1 (and... waiting for finals...)
2005 Pacific NW Finalists with 1359 and 1569
2004 Pacific NW Semifinalists, Seed 4
2004 Pacific NW Quarterfinalists
2003 Pacific NW Team Spirit Award, Quarterfinalists, Seed 5
  #14   Spotlight this post!  
Unread 01-21-2004, 10:52 PM
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: 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
//      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;
}
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)

Last edited by deltacoder1020 : 01-21-2004 at 11:12 PM.
  #15   Spotlight this post!  
Unread 01-22-2004, 07:31 PM
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
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.
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
First Logo as a CAD file jrgrim12 Inventor 4 02-14-2003 11:42 AM
The need for File Maker Pro 5 Dev. Edition archiver 2000 1 06-23-2002 10:50 PM
Dashv2.ocx dependency file now available archiver 2000 0 06-23-2002 10:00 PM
Improving PBASIC: Request for Comments Greg Ross Programming 19 02-16-2002 10:14 PM


All times are GMT -5. The time now is 11:17 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi