Shop OBEX P1 Docs P2 Docs Learn Events
Cartesian to polar conversion — Parallax Forums

Cartesian to polar conversion

Ray0665Ray0665 Posts: 231
edited 2008-07-15 23:00 in Propeller 1
Hi All
Does anyone have a cartesian to polar conversion routine. I want it for my robot navigate to waypoint routine. The input will be in wheel encoder pulses (approx 0.5 in per pulse, max value would fit in one word variable) I found what I thought would work in the memsic 2125 driver by Beau Schwabe but I don't understand the cordic routine and can't get any numbers that make sense out of it.

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2008-07-14 18:01
    Ray0665,
    ·
    That's the routine that you want to use...· the cordic routine returns a 32 bit angle, and in the memsic 2125 demo I am scaling it to a 13 bit angle by shifting the 32 bit·value right 19 times so that the returned value·is from 0 to 8192.· Why scale it to a 13-bit angle?· So it matches the current Sine/Cosine ROM table which is pre-calculated·out to·13-bits.· The scaling also makes it easier to convert to Degrees or Radians.
    ·
    To convert the returned value into Degrees:
    ·
    Multiply the returned value by 360 and divide by 8192.
    ·
    So for example if our returned value is 1252 after scaling it to a 13-bit value
    ·
    1252 * 360 = 450720
    ·
    450720 / 8192 = 55 Degrees
    ·
    Suppose you wanted hundredths·of a degree.· Instead of multiplying by 360, multiply by 36000
    ·
    1252 * 36000 = 45072000
    ·
    45072000 / 8192 = 5501 Degrees ... Just remember to move the decimal two places to the left = 55.01 Degrees
    ·
    ·
    ·
    To convert the returned value to Radians:
    ·
    Multiply the returned value by·62832 and divide by 8192.
    ·
    So again, suppose our returned value is 1252 after scaling it to a 13-bit value
    ·
    1252 * 62832 = 78665664
    ·
    78665664 / 8192 = 9602 ... In this case move the decimal 4 places to the left = .9602 Radians
    ·



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 7/14/2008 6:12:31 PM GMT
  • Ray0665Ray0665 Posts: 231
    edited 2008-07-14 20:48
    Beau
    Thank you for the info
    is _theta scaled as well?
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2008-07-14 23:39
    Ray0665,

    Theta is the 32-bit angle.... The thing is, if you don't scale it down, you don't have any headroom to convert it by multiplying a numerator, and then dividing by a denominator.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2008-07-15 23:00
    beau, your first conversion factors to *45, /1024. Similiarly, the second could be *3927, /512. Should be faster to calculate.
Sign In or Register to comment.