Shop OBEX P1 Docs P2 Docs Learn Events
Cnc mill cutting a circle and wondering if prop can handle negative numbers — Parallax Forums

Cnc mill cutting a circle and wondering if prop can handle negative numbers

science_geekscience_geek Posts: 247
edited 2009-05-23 14:01 in Propeller 1
i have recently built a 3 axis cnc mill, i can get it to draw squares like theres no tomorrow. i am using 3 easy step v3 stepper motor controllers from sparkfun so that it only requires a pulse to move it. i was wondering if anyone knew of an algorithm to get the prop to plot a cirlce, also is it possible for the prop to understand and use a negative value,·or if anyone has done something like this any help/advice is VERY welcome.

Comments

  • LeonLeon Posts: 7,620
    edited 2009-05-22 20:00
    The equation of a circle centred on the origin is x^2 + y^2 = r^2

    The Propeller can deal with negative numbers, as can every other MCU. See the manual.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • virtuPICvirtuPIC Posts: 193
    edited 2009-05-22 20:06
    Leon said...
    x^2 + y^2 = r^2
    Yeah, but this is only a formula. Look at the last section of this page to find a performant algorithm without multiplication and without square roots.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Airspace V - international hangar flying!
    www.airspace-v.com/ggadgets for tools & toys
  • TubularTubular Posts: 4,706
    edited 2009-05-22 20:09
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-05-22 20:16
    In the german wikipedia there is a good article, so I'd guess in the english version there is one as well ... search for Bresenham-Algorithm.
    The original one is for drawing lines, but there is also one for drawing circles.
    In general the Bresenham algorithms are based on integer math and will give you a decision on which step to do next, up/down/left/right. That's what you need for your steppers.

    Negative numbers are directly supported by SPIN. In PASM it simply depends on which instructions you use. There are instructions for signed numbers and instruction for unsigned numbers.
  • hover1hover1 Posts: 1,929
    edited 2009-05-22 21:10
    science_geek said...
    i have recently built a 3 axis cnc mill, i can get it to draw squares like theres no tomorrow. i am using 3 easy step v3 stepper motor controllers from sparkfun so that it only requires a pulse to move it. i was wondering if anyone knew of an algorithm to get the prop to plot a cirlce, also is it possible for the prop to understand and use a negative value,·or if anyone has done something like this any help/advice is VERY welcome.
    In the CNC world, it's know as circular interpolation. Most CNC programs have it, but a quick look didn't reveal any code available. I know, that wasn't any help at all smile.gif
    Jim
  • localrogerlocalroger Posts: 3,452
    edited 2009-05-22 22:59
    @science-geek -- there is a trigonometric sine table in the ROM which is there for this exact purpose. It's a detailed scaled integer representation of 1/4 cycle of a sine wave. By replicating this properly to get the whole wave, and offsetting it 90 degrees to get the cosine, you can get a set of points along a very detailed circle of whatever integer scale the table uses. (I haven't used the prop's table yet but I've used the exact same technique in the past on other platforms.)

    Since the CNC mill doesn't go very fast you can use Spin for the coding, which has multiplication and division to do the scaling. (I have tested this, and multiplication isn't any slower than addition in Spin; the overhead of the interpreter dwarfs the overhead of the multiply subroutine in the interpreter.)
  • virtuPICvirtuPIC Posts: 193
    edited 2009-05-23 07:52
    localroger: I am still a fan of the algorithm I mentioned in my last recent posting. If you give it the step size it will tell you the direction of your next step to take. This is exactly what you want for stepper control. In CNC, computer graphics, or elsewhere. Look at the page and see in the first sections results of your approach. Oh, and there you also find a Java program easily convertible to Spin or even to PASM since it only involves simple operations.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Airspace V - international hangar flying!
    www.airspace-v.com/ggadgets for tools & toys
  • localrogerlocalroger Posts: 3,452
    edited 2009-05-23 14:01
    @VirtuPIC -- that is indeed an elegant solution, but it's a lot less obvious how to scale it to do something like an ellipse. The discontinuities in the top circles don't matter for a cnc mill -- you'll cut a "straight line" at the resolution of your stepper to fill the discontinuity, which is what you would do with the discriminator anyway. In this sense a subtractive process like a mill is more forgiving than an additive process like graphic plotting; the same thing pertains to lines at various slopes.
Sign In or Register to comment.