Cartesian to polar conversion
Ray0665
Posts: 231
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.
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
·
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
Thank you for the info
is _theta scaled as well?
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.