![]() |
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; |
Re: Trig problems
Well, it might do some good to actually assign meh a value. Either that or printf angle, instead of meh. [/sarcasm]
|
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 :) |
Re: Trig problems
Quote:
Stupid me Code:
float angle;There, I think... |
Re: Trig problems
You're trying to print a float value as an integer (%d)
|
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.
|
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 |
Re: Trig problems
Quote:
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. |
Re: Trig problems
Quote:
Going off of Mark's code, this should work: Code:
#define ACCURACY 1000 //How many decimal places are important to you |
| All times are GMT -5. The time now is 01:37. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi