Shop OBEX P1 Docs P2 Docs Learn Events
As long as we are all about math... — Parallax Forums

As long as we are all about math...

CannibalRoboticsCannibalRobotics Posts: 535
edited 2009-02-16 20:00 in Propeller 1
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.

Comments

  • TreeLabTreeLab Posts: 138
    edited 2009-02-16 16:54
    There is a set of routines called FloatMath that provide + - * / without a dedicated cog, along with the required conversion routines. From there you can construct your own power functions with repeat loops over the powers, since all of the exponents are positive integers in this power series.

    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
  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2009-02-16 17:40
    You know, I was taking a little break from the problem and I realized that I might really have over complicated it.
    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 HayesCarl Hayes Posts: 841
    edited 2009-02-16 18:23
    If you need only 5 degree accuracy, a lookup table would be only 73 longs. You can generate the values in an Excel spreadsheet and copy them into the Spin editor. I made a sine table that way a couple days ago.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2009-02-16 18:34
    It's really better than that. I need 18 (72 = 4 * 18) ratios and I can look at the sign of the data to determine quadrants!
    Thanks for the suggestion about the table though, quick and easy!
    Jim-

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Signature space for rent, only $1.
    Send cash and signature to CannibalRobotics.
  • SRLMSRLM Posts: 5,045
    edited 2009-02-16 20:00
Sign In or Register to comment.