I need some help for my homemade CNC

Discussion in 'General Electronics Chat' started by CVMichael, Apr 20, 2009.

  1. CVMichael

    Thread Starter AAC Fanatic!

    Aug 3, 2007
    I posted on another forum (to show off :D ) about my homemade CNC:
    You can also see the it in action here:

    My problem is that I don't know the logic to make it move in circle (oval, etc.) motion. Right now I can only make straight lines.

    Btw, the "O" in the "hello" is drawn kind of like this:
    Code ( (Unknown Language)):
    1. /---\
    2. |   |
    3. |   |
    4. \---/
    I don't need code, as long as I know how to do it logically, I can figure out the programming.
  2. jpanhalt


    Jan 18, 2008
    Very nice. I like your use of twin lead screws on X and Y axes. I have not built one (yet), but when I see designs that use single lead screws, particularly to move the gantry, I wonder about rigidity.

    Sorry I can't help on the logic question.
  3. Wendy


    Mar 24, 2008
    Figure steps, X, then Y, then X, etc.

    I've been known to do something similar with a milling machine. I figured where the radius of the cutting tool would be with in the circle. I was cutting a larger circle with a flat side for a component in a case. I could draw it better than descibing it, but I went in steps of 5 mils each, and figured the start and stop points accordingly.

    The resulting cutout had noticable ripple, but worked like a charm.
  4. CVMichael

    Thread Starter AAC Fanatic!

    Aug 3, 2007
    jpanhalt, I am not familiar with all the terms when it comes to hardware, I tried to search for "twin lead screws" on google, and I get many kinds of things....

    But relating to that (I think), I plan to re-create the CNC, and next time I will use acme rods instead of threaded rods. I was told they are much more precise.

    Bill_Marsden, I want to do the calculations in the microcontroller, and I am not satisfied if I make it move in a circle by calculating in small lines.

    I want to enter the formula for a circle, and calculate very precisely at what position it should be at any point in the circle.

    For example, I made a picture with a circle that I zoomed 600%, and you can see that a circle is not really made of straight lines connected together
  5. bertus


    Apr 5, 2008

    Alberto is correct.
    An other thing you can do is giving different values for Xradius and Yradius.
    This way you will get ovals.
    An other thing you can do is adding a phase shift, this will tilt the circle.
    See also under lissajous curve.

  6. nucleargungus


    Apr 6, 2009
  7. CVMichael

    Thread Starter AAC Fanatic!

    Aug 3, 2007
    Hi Alberto

    That is not really what I had in mind.

    What I need is to get every point on the circle at 1 point distance each.

    For example, if you look at the image I attached.

    Suppose I start making the circle from the red point, then blue, then brown, and so on...

    I will get the points like this
    X, Y
    2, 8
    2, 7
    2, 6
    3, 5
    4, 4
    5, 3

    But if I do it the way posted, and if I have the Resol too high, then it will miss points, if the Resol is too low, then it will return the same point more than once.

    I was thinking to use the equation of the circle: X2 + Y2=r2 and solve for X when I have Y, and the other way around
  8. CVMichael

    Thread Starter AAC Fanatic!

    Aug 3, 2007
    I still don't think you understand what I want.

    The way you said, you always get the same number of points regardless of the radius of the circle. And this way A LOT of points repeat or not enough points. Either way, it is too difficult to fiddle with the resolution to get the perfect number of points for each radius of every circle.

    Here are some examples with radius, and how many points there should be:

    Radius 5 = 36 points
    Radius 10 = 64 points
    Radius 20 = 120 points
    Radius 30 = 176 points
    Radius 50 = 288 points
    Radius 100 = 572 points
    Radius 150 = 856 points
    Radius 200 = 1136 points
    Radius 500 = 2836 points

    Here is some code in Visual Basic 6 that shows how it's done, and how I got the above numbers:
    This code draws a perfect circle every time !
    Code ( (Unknown Language)):
    2. Option Explicit
    4. Private PointCount As Long
    6. Private Sub Form_Load()
    7.     Me.Show
    8.     DoEvents
    10.     PointCount = 0
    11.     DrawCircle 100, 100, 500
    12.     Debug.Print PointCount
    13.     Unload Me
    14. End Sub
    16. Private Sub DrawCircle(ByVal CX As Single, ByVal CY As Single, ByVal R As Single)
    17.     Dim PX As Single
    18.     Dim PY As Single
    19.     Dim T As Single
    20.     Dim M As Single
    22.     'this function is using the formula (x^2 + y^2 = r)
    24.     R = R * R
    25.     M = Sqr(R) / 1.4
    27.     For PY = 0 To M
    28.         PX = Sqr(R - (PY * PY))
    30.         DrawPoint CX + PX, CY + PY
    31.         DrawPoint CX - PX, CY + PY
    32.         DrawPoint CX + PX, CY - PY
    33.         DrawPoint CX - PX, CY - PY
    34.     Next PY
    36.     T = PX
    37.     For PX = 0 To T
    38.         PY = Sqr(R - (PX * PX))
    40.         DrawPoint CX + PX, CY + PY
    41.         DrawPoint CX - PX, CY + PY
    42.         DrawPoint CX + PX, CY - PY
    43.         DrawPoint CX - PX, CY - PY
    44.     Next PX
    45. End Sub
    47. Private Sub DrawPoint(ByVal X As Single, ByVal Y As Single)
    48.     PointCount = PointCount + 1
    49.     Debug.Print PointCount, Fix(X), Fix(Y)
    50.     Me.PSet (X, Y)
    51. End Sub
    The ONLY problem with that code is that it does not give the points in sequence.

    Actually while writing this, I just got an idea how to do it.
    Last edited: Apr 22, 2009
  9. CVMichael

    Thread Starter AAC Fanatic!

    Aug 3, 2007
    I tried to explain to you, but it seems it does not work.

    Yes, I did look at the project you posted, but the same problem still persists.

    It does not make sense to enter the "resolution" when you don't have to.

    And on top of that a circle made up of lines is not a circle.

    Did you look at the code I posted ? you don't have to give the resolution, it always makes a perfect circle with not too many points, and not too few.

    Anyways... there is no point to continue.