584,879 active members*
5,142 visitors online*
Register for free
Login
IndustryArena Forum > OpenSource CNC Design Center > Coding > Algorithm for G02 / G03 coding
Results 1 to 20 of 20
  1. #1
    Join Date
    Mar 2003
    Posts
    322

    Algorithm for G02 / G03 coding

    Hi,

    Can anybody help with an algorithm for generating circular interpolation for ARCs? I know the arc center (X,Y) the radius and the start angle and the end angle.

    I want to output either a G02 or G03 gcode line.

    TIA,

    -James Leonard
    '
    James Leonard - www.DragonCNC.com - www.LeonardCNCSoftware.com - www.CorelDRAWCadCam.com - www.LeonardMusicalInstruments.com

  2. #2
    Join Date
    Mar 2003
    Posts
    35538
    Are you just looking for a formula to find the start and endpoints? That's all you'll need to write G2 or G3 code.
    Gerry

    UCCNC 2017 Screenset
    http://www.thecncwoodworker.com/2017.html

    Mach3 2010 Screenset
    http://www.thecncwoodworker.com/2010.html

    JointCAM - CNC Dovetails & Box Joints
    http://www.g-forcecnc.com/jointcam.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  3. #3
    Join Date
    Mar 2003
    Posts
    322

    I need to calculate X, Y, I and J

    Quote Originally Posted by ger21 View Post
    Are you just looking for a formula to find the start and endpoints? That's all you'll need to write G2 or G3 code.
    Hi,

    I need to calculate X, Y, I and J (relative) for both G02 and G03, do you have formulas to do that based on the arc center, radius and start and end angles? These are values from a DXF file.

    Thanks!

    -James Leonard
    James Leonard - www.DragonCNC.com - www.LeonardCNCSoftware.com - www.CorelDRAWCadCam.com - www.LeonardMusicalInstruments.com

  4. #4
    Join Date
    Mar 2003
    Posts
    35538
    You just need to find the start and endpoints using trig. I and J are the center point relative to the start point. From the little research I just did, arcs are always CCW in a dxf. It looks like you'd take the sine of the start angle times the radius will give you the Y value of the start point (relative to the center of the arc). for the X, take the sine of 90°- start angle times the radius (again relative to the center of the arc). You probably need to convert the angles from (or to) radians.

    Your previous line of code needs to get you to the start point. Do the same thing to find the endpoint, which is the X,Y in your G2/G3 line.


    I wrote an AutoCAD macro that outputs g-code, but it doesn't do arcs. But It will do G2 and G3 from polyline arcs. A polyline gives you the start and end points, and radius (bulge) but not the center. I find the center using a chord, and the rest is easy.
    Gerry

    UCCNC 2017 Screenset
    http://www.thecncwoodworker.com/2017.html

    Mach3 2010 Screenset
    http://www.thecncwoodworker.com/2010.html

    JointCAM - CNC Dovetails & Box Joints
    http://www.g-forcecnc.com/jointcam.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  5. #5
    Join Date
    Mar 2003
    Posts
    322
    Quote Originally Posted by ger21 View Post
    You just need to find the start and endpoints using trig. I and J are the center point relative to the start point. From the little research I just did, arcs are always CCW in a dxf. It looks like you'd take the sine of the start angle times the radius will give you the Y value of the start point (relative to the center of the arc). for the X, take the sine of 90°- start angle times the radius (again relative to the center of the arc). You probably need to convert the angles from (or to) radians.

    Your previous line of code needs to get you to the start point. Do the same thing to find the endpoint, which is the X,Y in your G2/G3 line.


    I wrote an AutoCAD macro that outputs g-code, but it doesn't do arcs. But It will do G2 and G3 from polyline arcs. A polyline gives you the start and end points, and radius (bulge) but not the center. I find the center using a chord, and the rest is easy.

    Hi again,

    Thats good info, but I was hoping for explicit formulas. I really don't see how to calculate I and J, my math skills are not that good.

    Yes, DXF ARCs are always CCW, but for CNC purposes I may need to flip them to CW. I already know how to do this and how to derive the ARC center, radius and start and end angle from three points on the ARC (begin, end and middle) but I still don't see how to do the G02 / G03 stuff.

    -James Leonard
    James Leonard - www.DragonCNC.com - www.LeonardCNCSoftware.com - www.CorelDRAWCadCam.com - www.LeonardMusicalInstruments.com

  6. #6
    Join Date
    Mar 2003
    Posts
    35538
    Find the start point of the arc using the sin method like I said. You already know the centerpoint.

    I = Centerpoint X - Startpoint X
    J= Centerpoint Y - Startpoint Y
    Gerry

    UCCNC 2017 Screenset
    http://www.thecncwoodworker.com/2017.html

    Mach3 2010 Screenset
    http://www.thecncwoodworker.com/2010.html

    JointCAM - CNC Dovetails & Box Joints
    http://www.g-forcecnc.com/jointcam.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  7. #7
    Join Date
    Mar 2003
    Posts
    322
    Quote Originally Posted by ger21 View Post
    Find the start point of the arc using the sin method like I said. You already know the centerpoint.

    I = Centerpoint X - Startpoint X
    J= Centerpoint Y - Startpoint Y
    OK!

    I will give it a fly tomorrow.

    -James
    James Leonard - www.DragonCNC.com - www.LeonardCNCSoftware.com - www.CorelDRAWCadCam.com - www.LeonardMusicalInstruments.com

  8. #8
    Join Date
    Mar 2004
    Posts
    761
    Here is an open source program to convert DXF to G-Code:

    http://www.dakeng.com/ace.html

    Here is my program to convert G-Code to DXF:

    http://www.cnczone.com/forums/showth...?t=8814&page=2
    Wayne Hill

  9. #9
    Join Date
    Mar 2003
    Posts
    322
    Quote Originally Posted by WayneHill View Post
    Here is an open source program to convert DXF to G-Code:

    http://www.dakeng.com/ace.html

    Here is my program to convert G-Code to DXF:

    http://www.cnczone.com/forums/showth...?t=8814&page=2
    Hi,

    The ACE converter source code is the most difficult I have ever read. I had a LOT of trouble trying to follow the DXF load and conversion process. Also ACE won't process my DXF files (from the DXFTool for CorelDraw). So, I am trying to come to a deeper understanding of this.

    -James Leonard
    James Leonard - www.DragonCNC.com - www.LeonardCNCSoftware.com - www.CorelDRAWCadCam.com - www.LeonardMusicalInstruments.com

  10. #10
    Join Date
    Mar 2004
    Posts
    761
    James,

    Can you post a short file of the DXF format that will not work with ACE ?

    Line,circle and a point.
    Wayne Hill

  11. #11
    Join Date
    Mar 2003
    Posts
    322

    Here is a DXF that ACE will not process

    All of these DXF files are pure LINE and ARC entities. This is to improve cutting over the many shortline segments CorelDraw generates for a polyline.

    Here is a circle, ellipse, star and rectangle. Both LazyCAM and SheetCAM are very happy with these DXF files.

    -James
    Attached Files Attached Files
    James Leonard - www.DragonCNC.com - www.LeonardCNCSoftware.com - www.CorelDRAWCadCam.com - www.LeonardMusicalInstruments.com

  12. #12
    Join Date
    Jun 2007
    Posts
    30
    Could someone post the "formula" for cutting circles or circular interpolations. Just What to put in, where it all goes, and what it means. I need to cut circles and arcs.

  13. #13
    Join Date
    Mar 2004
    Posts
    761
    Quote Originally Posted by teenrocketnerd View Post
    Could someone post the "formula" for cutting circles or circular interpolations. Just What to put in, where it all goes, and what it means. I need to cut circles and arcs.

    http://technology.calumet.purdue.edu.../lecture13.pdf
    Wayne Hill

  14. #14
    Join Date
    Jul 2003
    Posts
    1220
    James
    Did you get what you needed.
    I'm working on a program which may be of some help.
    Checkout what has been done and advise (errors, improvements, future additions) if you are interested.
    Attached Files Attached Files

  15. #15
    Join Date
    Mar 2003
    Posts
    322
    Thank you!

    I do have the routines under control now. My big problem was a basic misunderstanding of degrees versus radians.

    -James
    James Leonard - www.DragonCNC.com - www.LeonardCNCSoftware.com - www.CorelDRAWCadCam.com - www.LeonardMusicalInstruments.com

  16. #16
    Join Date
    Jul 2005
    Posts
    12177
    Quote Originally Posted by teenrocketnerd View Post
    Could someone post the "formula" for cutting circles or circular interpolations. Just What to put in, where it all goes, and what it means. I need to cut circles and arcs.
    The circular interpolation commands are G02 for clockwise and G03 for counterclockwise tool travel. The commands below work on a Haas, there may be machine related differences.

    G91 G03 R1. X0.5 Y0.5 Fffff is the incremental command which tells the machine to cut an arc with a radius of 1.0" from where it is to the point that is 0.5" away on both the X and Y axes. The arc path to be followed is the shortest route, i.e. the arc subtends less than 180 degrees

    G91 G03 R-1. X0.5 Y0.5 Fffff is the same command but the arc path to be followed is the longest route, i.e. the arc subtends greater than 180 degrees.


    G90 G03 R1. X0.5 Y0.5 Fffff is the absolute command which tells the machine to cut an arc with a radius of 1.0" from where it is to the point that is located at 0.5" on both the X and Y axes using the current Work Coordinate system. The arc path to be followed is the shortest route, i.e. the arc subtends less than 180 degrees.

    G90 G03 R-1. X0.5 Y0.5 Fffff is the same command but the arc path to be followed is the longest route, i.e. the arc subtends greater than 180 degrees


    G03 I0. J-0.5 tells the machine to do a full counterclockwise circle around a center that is zero distance away along the X axis and 0.5" away in the negative direction on the Y axis. It does not matter whether the command is G91 or G90 this command still generates a full circle.

    It is possible to have Z motion during a circular interpolation and this depends on the choice of G91 or G90. The command G91 G02 I0. J-0.5 Z-.2 tells the machine to do a full clockwise circle about the center negative 0.5" along the Y axis and at the same time increment the Z axis down 0.2". A G90 would tell the machine to move to the position Z-.2 in the current Work Coordinate system.
    An open mind is a virtue...so long as all the common sense has not leaked out.

  17. #17
    Join Date
    Mar 2006
    Posts
    61
    hope this info helps.

    Stu
    Attached Thumbnails Attached Thumbnails circle calcs.jpg  

  18. #18
    Join Date
    Aug 2009
    Posts
    1

    Wink Drawing Circles :)

    Quote Originally Posted by jemmyell View Post
    Hi,

    Can anybody help with an algorithm for generating circular interpolation for ARCs? I know the arc center (X,Y) the radius and the start angle and the end angle.

    I want to output either a G02 or G03 gcode line.

    TIA,

    -James Leonard
    '
    OK I'm newbie here but i have simply solution for you.
    Use simply raster algorithm it's eliminate all sin(x) cosin etc. living just simply adding etc. simply enough to use it on microcontroler..
    To calculate it you need create something in way matrix of point each step give you 1 point on matrix. And use this Midpoint circle algorithm.

    you can find it on this pages >
    http://www.cs.unc.edu/~mcmillan/comp...e7/circle.html
    http://en.wikipedia.org/wiki/Midpoint_circle_algorithm

    To calculate G02 G03 code you need have in memory last position ( point X Y where you end after last G-command that will be a start point of your arc ) and then depend from what parameters you want get data of circle ( radius R , or I J ) you calculating closed circle and then from G02 (03) you need to take end ( pre-calculate end point ) to finding point on circle when you circle need to stop. Then you need to use jump algo to jump from start point to end and when you jumping from point to point you copping this like result of your calculation and then you can start driving motors.

    I hope this hellp you a bit.

  19. #19
    Join Date
    Mar 2004
    Posts
    761
    Ar2uR,

    Interesting.
    Wayne Hill

  20. #20
    Join Date
    Mar 2003
    Posts
    322

    just a note

    Just a note.

    This issue was settled for me and successfuly implemented quite a while ago. The problem I was having was trying to work in degrees when all the published algorithms / code I had been looking at needed radians...

    -James
    James Leonard - www.DragonCNC.com - www.LeonardCNCSoftware.com - www.CorelDRAWCadCam.com - www.LeonardMusicalInstruments.com

Similar Threads

  1. Algorithm?
    By CNCgr in forum OpenSource Software
    Replies: 16
    Last Post: 12-08-2009, 12:23 AM
  2. XY positioning algorithm needed
    By Tracid in forum PIC Programing / Design
    Replies: 4
    Last Post: 11-28-2006, 05:26 PM
  3. Need Help With Circular Pocketing Algorithm
    By lerman in forum G-Code Programing
    Replies: 9
    Last Post: 11-20-2006, 11:41 PM
  4. Blending algorithm of EMC2
    By Hebert in forum LinuxCNC (formerly EMC2)
    Replies: 1
    Last Post: 10-21-2006, 04:22 PM
  5. Adaptive clearing algorithm video
    By davidmb in forum DIY CNC Router Table Machines
    Replies: 3
    Last Post: 05-02-2006, 07:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •