Go to Post Yes, in human nature we like to get rewarded/recognized for things we do; however, you should not have to rely on this to be "successful". Remember the purpose of FIRST - To change our culture. - tim-tim [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-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 17-02-2006, 21:50
revolution1737 revolution1737 is offline
Robot Overlord
FRC #1691 (Revolution1737)
 
Join Date: Feb 2006
Rookie Year: 2004
Location: Sidney
Posts: 9
revolution1737 will become famous soon enough
Trig problems

I have tried Kevin Watson's trig code with the eeprom, a cordic approach (team 226's code i think), and the default sin function in math.h and every time I come out with a wrong value when I print. I usually get 16512 or 0. I have tried switching from radians to degrees. Am I just getting unlucky or is there something I'm missing?
Code:
float meh;
angle = sin(3.14);
printf("the angle is = %d\r\n",meh );
  #2   Spotlight this post!  
Unread 17-02-2006, 21:53
Jake M Jake M is offline
void* Jake;
FRC #1178 (DURT)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Missouri
Posts: 118
Jake M has a spectacular aura aboutJake M has a spectacular aura about
Re: Trig problems

Well, it might do some good to actually assign meh a value. Either that or printf angle, instead of meh. [/sarcasm]
__________________
Code:
void function(void)
 {
  function();
 }
  #3   Spotlight this post!  
Unread 17-02-2006, 21:54
steven114 steven114 is offline
Programming Wizard and Team Captain
AKA: Steven Schlansker
FRC #0114 (Eaglestrike)
Team Role: Programmer
 
Join Date: Feb 2004
Location: Los Altos, CA
Posts: 335
steven114 is a jewel in the roughsteven114 is a jewel in the roughsteven114 is a jewel in the rough
Send a message via AIM to steven114
Re: Trig problems

I can't vouch for the specific code you're using, but make sure that your sin() function actually wants an angle in floating point radians. Many take integers, as floating point is many times slower...

If this isn't the problem, posting the code you're using will help greatly
__________________
Shift to the left, shift to the right!
Pop up, push down, byte, byte, byte!
  #4   Spotlight this post!  
Unread 17-02-2006, 21:57
revolution1737 revolution1737 is offline
Robot Overlord
FRC #1691 (Revolution1737)
 
Join Date: Feb 2006
Rookie Year: 2004
Location: Sidney
Posts: 9
revolution1737 will become famous soon enough
Re: Trig problems

Quote:
Originally Posted by revolution1737
I have tried Kevin Watson's trig code with the eeprom, a cordic approach (team 226's code i think), and the default sin function in math.h and every time I come out with a wrong value when I print. I usually get 16512 or 0. I have tried switching from radians to degrees. Am I just getting unlucky or is there something I'm missing?
Code:
float meh;
angle = sin(3.14);
printf("the angle is = %d\r\n",meh );

Stupid me

Code:
float angle;
angle = sin(3.14);
printf("the angle is = %d\r\n",angle );
[/quote]

There, I think...
  #5   Spotlight this post!  
Unread 18-02-2006, 00:01
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,906
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Trig problems

You're trying to print a float value as an integer (%d)
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
  #6   Spotlight this post!  
Unread 18-02-2006, 00:07
steven114 steven114 is offline
Programming Wizard and Team Captain
AKA: Steven Schlansker
FRC #0114 (Eaglestrike)
Team Role: Programmer
 
Join Date: Feb 2004
Location: Los Altos, CA
Posts: 335
steven114 is a jewel in the roughsteven114 is a jewel in the roughsteven114 is a jewel in the rough
Send a message via AIM to steven114
Re: Trig problems

Speaking of that, the printf doesn't even support floating point (%f). You'll have to do something like multiply your result by 1000, cast to int, and print that.
__________________
Shift to the left, shift to the right!
Pop up, push down, byte, byte, byte!
  #7   Spotlight this post!  
Unread 18-02-2006, 00:31
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,906
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Trig problems

Yea, you can always manipulate the value to print it.
E.g.,

Code:
#define ACCURACY 1000 //How many decimal places are important to you
float f;
int i, i2; // Might need to be longs if you have a lot of significant digits
 
f = 245.56;
 
/* Print float value */ 
i = (int) f;
i2 = (int) ((f-i)*ACCURACY);
printf("f = %d.%03d \r", i, i2); //e.g., f = 245.559
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
  #8   Spotlight this post!  
Unread 18-02-2006, 01:23
revolution1737 revolution1737 is offline
Robot Overlord
FRC #1691 (Revolution1737)
 
Join Date: Feb 2006
Rookie Year: 2004
Location: Sidney
Posts: 9
revolution1737 will become famous soon enough
Re: Trig problems

Quote:
Originally Posted by Mark McLeod
Yea, you can always manipulate the value to print it.
E.g.,

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

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.
  #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?
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
speed of math.h trig functions? Jared Russell Programming 4 07-02-2006 07:13
Anyone Else Having Problems with Q&A on FIRST? Windwarrior General Forum 6 25-01-2006 10:54
Do you all have problems with.... Munkaboo Website Design/Showcase 19 03-03-2003 19:51
Radio problems -- not archiver 2000 1 23-06-2002 22:23


All times are GMT -5. The time now is 01:23.

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


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