Shop OBEX P1 Docs P2 Docs Learn Events
Degree calcuration for rotational cooridate? — Parallax Forums

Degree calcuration for rotational cooridate?

ArchiverArchiver Posts: 46,084
edited 2004-03-29 22:13 in General Discussion
I got values of X and Y for each x axis and y axis, but I don't know
how to write basic stamp code to calculate degree of rotation. If
anybody know, please let me share the code.
Bless you all!

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-03-25 06:13
    --- In basicstamps@yahoogroups.com, "sogilo" <sogilo@y...> wrote:
    > I got values of X and Y for each x axis and y axis, but I don't know
    > how to write basic stamp code to calculate degree of rotation.

    If I understand your question, the short answer is theta = atan(y /
    x). Now the trick, of course, is to compute the arctangent and do it
    without floating point, too. If you're committed to using the Basic
    Stamp, you might investigate the CORDIC algorithm. You should be
    able to achieve the desired result that way using fixed point
    arithmetic.

    At the risk of being heretical, you might also consider using the BX-
    24 which is pin compatible with the Basic Stamp, costs the same or
    less, runs faster, has more RAM, more ROM, floating point and an atan
    library function.
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-25 15:34
    At 05:27 AM 3/25/04 +0000, you wrote:
    >I got values of X and Y for each x axis and y axis, but I don't know
    >how to write basic stamp code to calculate degree of rotation. If
    >anybody know, please let me share the code.
    >Bless you all!

    You will probably need a lookup table for this, but the general formula is...

    Angle = TAN-1(Y/X)

    or

    Angle = ATN(Y/X)

    You will still need to monitor the sign of X and Y to determine which
    quadrant the angle returned is relevant to.


    ....Didn't I see something in a fairly recent (smaller size magazine)
    'Nuts & Volts' article about an undocumented TAN function for the BSII
    that briefly touched this subject?

    ...I'll try to find it at the house.


    -Beau Schwabe
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-25 16:48
    The Stamp does have arctangent and magnitude operators, that have
    been there all along, but undocumented until recently (See online
    help file with STAMPW).

    X VAR Word
    Y VAR Word
    angle VAR Word
    magnitude VAR Word

    X=100
    Y=-100
    angle = (X ATN Y) */ 360 ' order of X and Y matters. arctan (Y/X)
    ' */360 converts from brads to degrees
    magnitude = X HYP Y ' the order of X and Y does not matter for HYP
    debug ?angle,?magnitude

    It helps to understand how the Stamp measures angles, in brads,
    units of 1/256 of a circle. Here is more discussion at this URL:

    http://www.emesystems.com/BS2math3.htm#ATN_HYP



    -- Tracy


    >I got values of X and Y for each x axis and y axis, but I don't know
    >how to write basic stamp code to calculate degree of rotation. If
    >anybody know, please let me share the code.
    >Bless you all!
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-26 06:01
    Dear Tracy Allen;
    I appreciate your help^^
    Have a nice one!

    _____________________________________________________________________
    ¿¹»Û ÆíÁöÁö¿¡ ¸ÞÀÏÀ» º¸³»¼¼¿ä - ¾ßÈÄ! ¸ÞÀÏ
    http://mail.yahoo.co.kr
    ½ÅÂ÷,Áß°íÂ÷,Á÷°Å·¡ ¸Å¹°ÀÌ ÇÑÀÚ¸®¿¡ - ¾ßÈÄ! ÀÚµ¿Â÷
    http://autos.yahoo.co.kr/autos/
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-29 22:13
    Given points (X1, Y1) and (X2, Y2), the angle between the two points is:

    Theta = ArcTan ( (X1 - X2) / (Y1 - Y2))

    Since this is difficult to do in a Basic Stamp, perhaps you could look
    into using a floating point coprecessor. Go the
    <http://al_williams.com/> and check out the PAK modules. PAC XII is
    very easy to use and includes the ATAN function.

    Oh, yes, you also have to know the robot's current bearing. Then you
    need to determin how many degrees to rotate in what direction in order
    to point the robot to the new position.

    Good luck, and keep us informed!

    Russ


    --- In basicstamps@yahoogroups.com, "sogilo" <sogilo@y...> wrote:
    > I got values of X and Y for each x axis and y axis, but I don't know
    > how to write basic stamp code to calculate degree of rotation. If
    > anybody know, please let me share the code.
    > Bless you all!
Sign In or Register to comment.