Thread: Trig problems
View Single Post
  #9   Spotlight this post!  
Unread 19-02-2006, 01:09
teh_r4v3 teh_r4v3 is offline
Registered User
AKA: Rajeev Sharma
FRC #1511 (Rolling Thunder)
Team Role: Student
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Penfield, NY
Posts: 15
teh_r4v3 is on a distinguished road
Send a message via AIM to teh_r4v3
Re: Trig problems

Quote:
Originally Posted by revolution1737
I wish I had taken a class so I knew C. Could you write it so it takes the value in degrees from get_gyro_angle() and uses it in a sin function. I have spen 9 hours (seriously) and I still cannot get the right value. Any help is greatly appreciated.
First off, remember that the sin function is not part of the standard library, so you'll have to add it in yourself. Also, it takes radians, not degrees. On top of that, the PIC processor the IFI RC uses doesn't have a FPU (floating point unit), so it has to emulate one in software. (In other words, doing anything with decimals is reeealy slow.) So what I'm going to write isn't exactly the most optimized code in the world.

Going off of Mark's code, this should work:

Code:
#define ACCURACY 1000 //How many decimal places are important to you
#define PI 3.14 //Pi to however many digits you want
float f;
int i, i2; // Might need to be longs if you have a lot of significant digits
f = sin((float) get_gyro_angle() / (2.0 * PI));
/* Print float value *
i = (int) f;
i2 = (int) ((f-i)*ACCURACY);
printf("f = %d.%03d \r", i, i2); //e.g., f = 245.559
__________________
Rajeev Sharma

Team 1511 Rolling Thunder

hoojamomma?