CNCzone.com-The Largest Machinist Community on the net!



Home Page Mark Forums Read Today's Posts My Replies Classifieds Reviews Photo Gallery Web Links Share Files Advertise With Us Ad List
Go Back   CNCzone.com-The Largest Machinist Community on the net! > Electronics > PIC Programing / Design


PIC Programing / Design Discuss programing of PIC chips here and design of electronics using PIC chips.


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 11-25-2006, 07:36 AM
 
Join Date: Nov 2006
Location: Slovakia
Age: 24
Posts: 15
Tracid is on a distinguished road
XY positioning algorithm needed

Hi everybody!
My project doesnt involves a CNC project but a part of it needs some solution which i think is related to CNC.
So, i would like to develop an intelligent lighting effect( the type name is
Scanner )
I dont know if you know them or no so i describe the problem-part mechanics of it.
The light comes out through optics and a small mirror reflects the beam the
direction the motors move.
So i have two motors,one rotates the second and the mirror is attached on
the second motor.That way X and Y axis rotation is achieved.First motor
rotates X axis and the second Y axis.
(i found a picture on the net so i attached for better understanding)

And here comes the problem:

the full range of X axis is about 180degrees, the full range of Y axis is
90degrees. (the degrees are implemented as number of maximum steps from one
edge/limit to the other edge/limit)

I am using a microcontroller with 8 bit registers ( PIC ) so i can break down each
range(X and Y) into 256 positions.At the system reset the motors find their
zero positions (0,0) and all the following desired positions are searched
relatively to the actual position.

You can imagine as my application have to draw fine lines from point A to
point B.So with a fast uCPU the motion should look smooth.
Since i am not an experienced hobbyst yet,i asked you for a solution.
I found on the web a method called linear interpolation,circular
interpolation.The problem is that i found only one document covering both
with minimal extension.

What i think:
linear interpolation means that only one motor moves at a time and one motor
moves smaller lenghts while the other moves bigger lenghts(assuming the
destinations are not the same distance) and the move ´enable´ is switched
between each other.(like in paint: line from point A to B consists of longer lines-shorter lines)
I think this way if the motors are moving at very low speed i can see the
inaccuracy in moving and instead of the pretty (ideal) straight line i see
´stairs´ (stairway, stairy moving - sorry my English)
This is the right way i think?

What i need:
i thought about using two separate Timer modules for both motors and
instead of switching the move between them , rotate both at the same time
and for the same time but with different speed.So if X motor have to move
100 positions and Y motor have to move only 50 positions that means X have
to do two times more and thus it have to move two times faster if i want
them to arrive at the destination at the same time.(so timer interrupts move the motors some steps)
I also have to place into account that theres a desired avarage(or
reference) speed at which one motor moves and the second motors speed is
referenced to this value.

So this is the description of my problem.
Since you are familiar with CNCs i thought maybe you can recommend me some ideas.
My application is very time-sensitive so i must avoid mathematical
calculations which steal a lot of processing time.

Every idea is welcome!

Thanks!
Attached Thumbnails
Click image for larger version

Name:	184.jpg‎
Views:	169
Size:	65.6 KB
ID:	26128  
Tweet this Post!Share on Facebook
Reply With Quote

  #2   Ban this user!
Old 11-25-2006, 07:31 PM
DR-Motion's Avatar  
Join Date: Mar 2004
Location: Ontario,Canada
Posts: 120
DR-Motion is on a distinguished road
Lightbulb

Originally Posted by Tracid View Post

<snip>


I am using a microcontroller with 8 bit registers ( PIC ) so i can break down each
range(X and Y) into 256 positions.At the system reset the motors find their
zero positions (0,0) and all the following desired positions are searched
relatively to the actual position.



What i need:
i thought about using two separate Timer modules for both motors and
instead of switching the move between them , rotate both at the same time
and for the same time but with different speed.So if X motor have to move
100 positions and Y motor have to move only 50 positions that means X have
to do two times more and thus it have to move two times faster if i want
them to arrive at the destination at the same time.(so timer interrupts move the motors some steps)
I also have to place into account that theres a desired avarage(or
reference) speed at which one motor moves and the second motors speed is
referenced to this value.

So this is the description of my problem.
Since you are familiar with CNCs i thought maybe you can recommend me some ideas.
My application is very time-sensitive so i must avoid mathematical
calculations which steal a lot of processing time.

<snip>

!
Yes, this is good thinking.

Do a search on phase accumulators for the background but basically...

if you have a finite sized accumulator (i.e. adder register) and add a smaller or same sized value to it at regular intervals it will overflow at a frequency equal to the ratio of 2 raised to the power of the register size, to the addend. The overflow (carry out) can be used as a step signal for your axis.

For example, using an 8 bit accumulator, add 3 to the accumulating sum once every millisecond and the carry out from the accumulator will occur every 256/3 milliseconds.

similarily by adding 256 every millisecond you will have a step every 256/256=1 millisecond.

Note that the frequency resolution is 1 bit :-)

The computational overhead involves a load register, an add, a branch if carry set, and an output bit.... very fast ;-)
<edit added>
Also note that the vector velocity(below) is only calculated once before the relatively long (time) move.

So to succesfully interpolate your two axes:

1. select a maximum velocity and use as the frequency of your interrupt timer.

2. calculate the vector velocity = feedrate / sqrt((dist X * dist X) + (dist Y * dist Y)).

so that feed X = dist X * vector velocity
and feed Y = dist Y * vector velocity

3. use an X and a Y accumulator in your interrupt routine to sum feed X and feed Y

4. track your distance travelled to end motion with a zero velocity input.
The motion will complete approximately simultaneously within the tolerances of your arithmetic.
__________________
embrace enthusiasm to accomplish the task
Gary Davies... www.durhamrobotics.com

Last edited by DR-Motion; 11-25-2006 at 07:34 PM. Reason: add info
Tweet this Post!Share on Facebook
Reply With Quote

  #3   Ban this user!
Old 11-25-2006, 07:33 PM
 
Join Date: Aug 2004
Location: US
Posts: 2,782
ViperTX is on a distinguished road

Bresenham Alogrithm
Tweet this Post!Share on Facebook
Reply With Quote

  #4   Ban this user!
Old 11-26-2006, 04:33 AM
 
Join Date: Nov 2006
Location: Slovakia
Age: 24
Posts: 15
Tracid is on a distinguished road

Thanks DR-Motion!
I think this is what i really want(the result)!
But one wrong thing is with this idea(for me!) : it uses sqrt and division and this is what i cant afford.
I saw a project somewhere which have to accomplish the same jobs as mine and the CPU runs at only 16MHz and mine will at 20MHz.But this is still slow for such calculations.
So theres another way.

Lets say i will use lookup tables since there is a little finite of combinations of distance differences ( total of 256 ) between X and Y.
I calculate the values with my calculator or Excel for a specified speed.Yes,then i can use it to jump to the location in the lookup table according to the distance difference.for example if no difference between them then add zero to the PCL and read the value then store it as speed for the first motor.The second motors speed is constant.

But a problem takes place when i want to use different speeds.I mean the DMX controller console tells my equipment the speed(the reference or avarage speed).It would last till silvester 2007 to create lookup tables for all the 256 possible speed levels.And its absolutely meaningless to use such a big memory place.
Since i am using integer numbers only(so i round up and down in calculations) there will be some offset errors(caused by rounding) if using only one lookup table and use only additions to get the correct speed offset from the original.
I hope you understand what i mean! how to compensate for it?
Tweet this Post!Share on Facebook
Reply With Quote

  #5   Ban this user!
Old 11-28-2006, 11:26 AM
 
Join Date: Nov 2006
Location: Slovakia
Age: 24
Posts: 15
Tracid is on a distinguished road

I understand your algorithm Dr Motion,and yes,its the one i need.

You wrote its very fast- could you please explain me how do you mean that?

My uCPU is running at 40MHz and has a multiplication instruction only(no division,sqrt)

Could you please explain me deeper how to do it fast?
Approximate cycles?

Thanks!
Tweet this Post!Share on Facebook
Reply With Quote

Sponsored Links
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -5. The time now is 05:40 AM.





Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO
Template-Modifications by TMS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353