As long as we are all about math...
CannibalRobotics
Posts: 535
I'm using the parallax compass. I've got the data coming off of it nicely but I'm out of cogs. I need to do an ArcTangent function from within Spin in the 'main' program.
I've looked at the infinite series calculation and it's easy enough but it needs to raise numbers between 0 and 1·to to powers.
Any ideas?
Jim-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent, only $1.
Send cash and signature to CannibalRobotics.
I've looked at the infinite series calculation and it's easy enough but it needs to raise numbers between 0 and 1·to to powers.
Any ideas?
Jim-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent, only $1.
Send cash and signature to CannibalRobotics.
Comments
for example, if value is already in std floating point format, something like this will do
pub power( value, exponent ) : result | i
result := value
repeat i from 2 to exponent
result := fp.fmul( value,result )
*** although since the power series uses many of the values (all with odd powers), you will want to optimize your code somewhat so that it does not have to continually recalculate x^n as part of the x^(n+2) calculation. Filling an array with the odd powers as you calculate the highest power required would work well
Do you know how many terms you need to get adequate precision from the series expansion? You may find that a look-up table a workable solution, and the speed advantage is unbeatable.
Cheers!
Paul Rowntree
Post Edited (TreeLab) : 2/16/2009 5:07:23 PM GMT
I'm thinking that 5 degree accuracy is plenty and I'm more concerned with directional variation from the starting point than I am with magnetic north. So, that works out to just 72 data points all the way around. Numerically it gets easier as there are only 18 X-Y ratios that I care about because the quadrant is a function of the sines of the X-Y data coming off of the compass (pos/neg, not sin/cos).
So, I thought I'd pull the compass module off of the bot, put it on the proto board and "give it a spin" to collect some data. Seems like all I have to do is to bound these ratios then establish a lookup table. I might be hopelessly flying off a cliff in my reasoning here but it seems sound enough.
Jim-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent, only $1.
Send cash and signature to CannibalRobotics.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i@arrl.net
Thanks for the suggestion about the table though, quick and easy!
Jim-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent, only $1.
Send cash and signature to CannibalRobotics.
http://forums.parallax.com/showthread.php?p=767169