1WP: G Code, interplay between polar, incremental, and plane selection.

The #1 community for Gun Owners in Indiana

Member Benefits:

  • Fewer Ads!
  • Discuss all aspects of firearm ownership
  • Discuss anti-gun legislation
  • Buy, sell, and trade in the classified section
  • Chat with Local gun shops, ranges, trainers & other businesses
  • Discover free outdoor shooting areas
  • View up to date on firearm-related events
  • Share photos & video with other members
  • ...and so much more!
  • CathyInBlue

    Grandmaster
    Rating - 0%
    0   0   0
    In this issue of First World Problem Theatre:

    I'm trying to learn all the ins and outs of CNC programming in G Code by creating my own "conversational" compiler to G Code.

    There are a number of "modes" the machine can be in:
    G20, inch (English/Imperial) mode or G21 millimeter (Metric) mode.
    G90, absolute positioning mode or G91 incremental positioning mode.
    For instructions that specify circular motion, select one of the three cartesian machine planes: G17 (X-Y), G18 (X-Z), or G19 (Y-Z).

    I've got all of those, but now, I'm trying to understand how the machine uses this mode:
    G15 cartesian coordinates mode or G16 polar coordinates mode.

    Most resources seem to indicate that at the moment of dropping into G16 mode, you form a new coordinate system, completely independent of previous positioning, coordinate, and plane settings. That this new polar coordinate system has its origin fixed in the old coordinate system, but is itself absolute in radius but relative in angle (or maybe absolute in angle as well?), that it ignores plane selection and always operates exclusively in the X-Y plane (or for whatever the plane selection is, the first axis is interpretted as the radius and the second as the angle in whatever orientation?).

    I've been scouring the bowels of the Internet (H/T: Weasel Zippers) for CNC programming guides that at least pretend to be authoritative about polar coordinate CNC programming and how it plays with G17/G18/G19 and G90/G91, but no dice. Most of them are just plagiarized off one another, complete with some of the same wrong information. Some claim that while in G16 mode, the only X-Y travel instructions that are permitted are G00 (rapid) or G01 (linear), but then some have examples that show canned cycle instructions that have X and/or Y travel in them, using polar coordinates in those values.

    So, if INGO does not have its fair share of CNC machinists, then I miss my guess. Any of you G Code Jockeys care to enlighten me as to all of the true ins and outs of G16 polar coordinate system programming? My compiler is kinda stymied until I can fill in this hole.
     

    GodFearinGunTotin

    Super Moderator
    Staff member
    Moderator
    Site Supporter
    Rating - 100%
    1   0   0
    Mar 22, 2011
    52,160
    113
    Mitchell
    I don't know CNC programming but I do know a little about robot programming. Are those codes used to establish a new coordinate system relative to some feature of whatever you're machining? In robot programming, it's common to establish various user frames or tool frames to make it easier to program positions relative to a certain object in space. I am guessing that in CNC programming world, there may be a similar need.
     

    CathyInBlue

    Grandmaster
    Rating - 0%
    0   0   0
    There are on order of a hundred "work coordinate systems" that one could be working in. Every CNC machine should have instructions G54 through G59 give six WCSs and most will also have another 99 in G154 P1 through G154 P99, and then there's G53, which is the hardware-based machine coordinate system.

    Again, best as I can figure, dropping into polar coordinates, G16, is orthogonal to all of those, forming its own temporary WCS based on the tool tip's coordinates in the original WCS at the time G16 was executed being the (initial?) origin of the new polar coordinate system.
     

    DoggyDaddy

    Grandmaster
    Site Supporter
    Rating - 100%
    73   0   1
    Aug 18, 2011
    112,822
    149
    Southside Indy
    I'd just like to toss a "LOL, wut" out there

    9770e5f10f280ea090202548dbd7afb9ed100b3baf74a60dfa4900ae14a21026.jpg
     
    Rating - 100%
    28   0   0
    Oct 3, 2008
    4,260
    149
    On a hill in Perry C
    Not sure if I can be much help. Been doing CNC work for almost 20 years now and I think I've used polar programming a handful of times, mostly for putting holes in a circular pattern because it is easier than doing the math.
    Basically what you are doing is using a temporary origin based on the the tool tip coordinate when you go to G16, as you said, but that origin can be offset from the physical location of the tool. From then until you go back to G15, your movements will be based off that point instead of the X0 Y0 Z0 point. You should be able to do anything that you can do while using G15 in all 3 axes, including tool changes, speed, and feed.
    IIRC a lot of your code is going to be dependent on your controller. Some use regular X, Y, Z; others use Px, Py, Pz; as the origin for your polar coordinates, then there are others for your angle, radius, and/or vector. But the big one is, the controller has to be able to use polar coordinates, quite a few don't.
    I'll dig through my books at work tomorrow and see what I can find. If this didn't help, let me know, I may have misunderstood your questions. Heck, I might even do a little polar programming myself. Been a while since I've had a good crash.:)::):

    I don't know CNC programming but I do know a little about robot programming. Are those codes used to establish a new coordinate system relative to some feature of whatever you're machining? In robot programming, it's common to establish various user frames or tool frames to make it easier to program positions relative to a certain object in space. I am guessing that in CNC programming world, there may be a similar need.

    Very similar.
     

    CathyInBlue

    Grandmaster
    Rating - 0%
    0   0   0
    Helpful.

    I have a machine specification feature in my compiler, complete with optional supported features list, so any G code instruction that's not regularly supported, I just check my has_feature API call before allowing the programmer to try and do something stupid with a machine that can't handle it.

    I understand that a lot of these last 5% of instructions I'm trying to implement in my API are seldom used, but that doesn't change the fact that I have to shag down some form of concrete description of how they work when they are used in order to call my compiler complete.

    So, it sounds like you're saying G16 ignores G90/G91 and creates its own G90-ish system. That being the case, G01 X1 Y90 would go 1 unit in the +Y Cartesian (90°) direction. The question I have is if I then go G01 X1 Y0, which describes a move 1 unit in the +X direction (0°), do I go to (0,1), which would be the case if all polar motion is relative to the G90-ish origin created at the point of the G16 instruction, or is it really G91-ish, and I'll end up at (1,1) because that Y0 heading is relative not to the G16 origin, but more incremental off the first Y90 move? I'll accept any explanation that can be nailed down to a specific implementation, preferably Haas. I'm 99.999% sure the angle spec in polar is absolute, always relative to the X+ axis/3 o'clock position with positive angles being CCW and negative angles being CW, like a secondary school protractor.

    Then, on top of those issues, is that explanation only accurate for G17 (X-Y) plane work? If I'm in G18 (X-Z plane), would the angle spec have to be given in the Z option or else the machine alarm out and <defecate> itself?

    Some examples of G16 programming I've found on the web seem to indicate that the radius spec is absolute while the angle spec is relative, repeatedly executing X2 Y60 inside a canned drill cycle will get you a 4" diameter 6 bolt circle. While others would require X2 Y0, then X2 Y60, then X2 Y120, X2 Y180, X2 Y240, X2 Y300 to get all six bolt holes. Why one would use the drilling cycle and polar rather than G70 for a bolt circle, though, is beyond me.
     

    Mr Evilwrench

    Quantum Mechanic
    Emeritus
    Rating - 0%
    0   0   0
    Aug 18, 2011
    11,560
    63
    Carmel
    My, but we work so hard to make things easy. Been there, done that, mathwise; think I'll stay with twiddling the XYZ by hand, maybe get a rotary vise for rotary things. I certainly have become set in my ways in my old age.
     

    jmiller676

    Master
    Rating - 100%
    2   0   0
    Mar 16, 2009
    3,882
    38
    18 feet up
    My, but we work so hard to make things easy. Been there, done that, mathwise; think I'll stay with twiddling the XYZ by hand, maybe get a rotary vise for rotary things. I certainly have become set in my ways in my old age.

    My dad is 55 years old. He has a tool and die shop. He vowed he would "never own one of them damn cnc things". The one that currently sits on his floor barely stops running now, all the while he's doing other parts of the job/ other jobs/ eating lunch. :):
     

    Mr Evilwrench

    Quantum Mechanic
    Emeritus
    Rating - 0%
    0   0   0
    Aug 18, 2011
    11,560
    63
    Carmel
    A shop for money is one thing, I just have a well-equipped garage. I can crank out 80% lowers to my heart's content. I do plan on playing with ram EDM, though. Heck, you could do 80% lowers with that, too.
     

    CathyInBlue

    Grandmaster
    Rating - 0%
    0   0   0
    ****!

    Just got word that my Summer session of MTTC 208, CNC Programming I has been cancelled. I'm enrolled in MTTC 242, CNC Machining for the fall and 208 is a prereq for it. This is a colossal cluster ****. Nevermind that I could largely teach 208, but I really dislike being tossed into the deep end of the shark tank with porterhouses tied to my ankles.
     

    jmiller676

    Master
    Rating - 100%
    2   0   0
    Mar 16, 2009
    3,882
    38
    18 feet up
    ****!

    Just got word that my Summer session of MTTC 208, CNC Programming I has been cancelled. I'm enrolled in MTTC 242, CNC Machining for the fall and 208 is a prereq for it. This is a colossal cluster ****. Nevermind that I could largely teach 208, but I really dislike being tossed into the deep end of the shark tank with porterhouses tied to my ankles.

    I hear ya! Enrollment must have been down for that particular section. Did they have multiple sessions where you could be rolled over into another one, if you explain your situation?
     

    rhino

    Grandmaster
    Rating - 100%
    24   0   0
    Mar 18, 2008
    30,906
    113
    Indiana
    ****!

    Just got word that my Summer session of MTTC 208, CNC Programming I has been cancelled. I'm enrolled in MTTC 242, CNC Machining for the fall and 208 is a prereq for it. This is a colossal cluster ****. Nevermind that I could largely teach 208, but I really dislike being tossed into the deep end of the shark tank with porterhouses tied to my ankles.

    Are we talking Ivy Tech? Maybe you could go to another campus for that one class?

    You might want to send a PM to lovemywoods. I think his daughter recently finished (or is close to it) her schooling at Ivy Tech in Indy and may have some insight for you. Some of the other engineers on here may be hip to your situation as well.
     

    CathyInBlue

    Grandmaster
    Rating - 0%
    0   0   0
    I hear ya! Enrollment must have been down for that particular section. Did they have multiple sessions where you could be rolled over into another one, if you explain your situation?
    The entirety of the MTTC offering for the Summer evapourated. Their explanation was "circumstances beyond our control."

    Are we talking Ivy Tech? Maybe you could go to another campus for that one class?

    You might want to send a PM to lovemywoods. I think his daughter recently finished (or is close to it) her schooling at Ivy Tech in Indy and may have some insight for you. Some of the other engineers on here may be hip to your situation as well.
    There don't appear to be any distance learning classes, state-wide, college-wide for the Summer session.

    I'm gonna try to cut a deal where if I deliver a working compiler by the start of MTTC 242 in the Fall, if I then pass 242, they give me credit for 208. The system also kicked out my registration for the Fall PLC level I course because they don't have me down as having passed INDT 100 and INDT 113. 113 is Basic Electricity. I have an all but dissertation for an MS in Physics. I've taken more than my fair share of electrodynamics classes and am conversant with Maxwell's Equations, nevermind Ohm's Law. LinuxGizmos:* all about Linux-powered devices is my Christmas wish list. I just want to learn industrial PLCs.

    Talk about "First World Problems"…
     
    Rating - 100%
    28   0   0
    Oct 3, 2008
    4,260
    149
    On a hill in Perry C
    Helpful.

    I have a machine specification feature in my compiler, complete with optional supported features list, so any G code instruction that's not regularly supported, I just check my has_feature API call before allowing the programmer to try and do something stupid with a machine that can't handle it.

    I understand that a lot of these last 5% of instructions I'm trying to implement in my API are seldom used, but that doesn't change the fact that I have to shag down some form of concrete description of how they work when they are used in order to call my compiler complete.

    So, it sounds like you're saying G16 ignores G90/G91 and creates its own G90-ish system. That being the case, G01 X1 Y90 would go 1 unit in the +Y Cartesian (90°) direction. The question I have is if I then go G01 X1 Y0, which describes a move 1 unit in the +X direction (0°), do I go to (0,1), which would be the case if all polar motion is relative to the G90-ish origin created at the point of the G16 instruction, or is it really G91-ish, and I'll end up at (1,1) because that Y0 heading is relative not to the G16 origin, but more incremental off the first Y90 move? I'll accept any explanation that can be nailed down to a specific implementation, preferably Haas. I'm 99.999% sure the angle spec in polar is absolute, always relative to the X+ axis/3 o'clock position with positive angles being CCW and negative angles being CW, like a secondary school protractor.

    Close. G01 X1 Y90 would move 90 units in Y at least with the machines I'm currently working with. You also have to specify an angle. What I've seen it is usually A. X, Y and Z will still indicate a movement in however many units, but the actual machine movement will be dependent on your A. So if your A is 90, and you program a movement of 1 unit in X, then your actual movement will be 1 unit in the machine Y axis. Whether that movement is +1 or -1, I'm not sure as I didn't get the chance to play much at work today. IIRC, each movement will require an A until you go back to G15. The A of succeeding moves will be based off A of the preceding movement. So if your first movement was X1 Y1 A90, and you wanted to go 45 degrees more for your second movement then your A would be 45 and not 135. Now whether the actual XY of the second movement is based off the point you started your G16, or the end of the first movement, I'll have to get back with you on that. You are correct in the angle is based off the X+ axis, however that axis is not always 3 o'clock. I've seen some that use 9 o'clock as X+ and a very few that the X+ can be user specified as 3, 6, 9 or 12.

    Then, on top of those issues, is that explanation only accurate for G17 (X-Y) plane work? If I'm in G18 (X-Z plane), would the angle spec have to be given in the Z option or else the machine alarm out and <defecate> itself?

    Yes, you will need to specify the A in any plane you working in.

    Some examples of G16 programming I've found on the web seem to indicate that the radius spec is absolute while the angle spec is relative, repeatedly executing X2 Y60 inside a canned drill cycle will get you a 4" diameter 6 bolt circle. While others would require X2 Y0, then X2 Y60, then X2 Y120, X2 Y180, X2 Y240, X2 Y300 to get all six bolt holes. Why one would use the drilling cycle and polar rather than G70 for a bolt circle, though, is beyond me.

    Exactly, the angle is always relative to the previous. In your example of the 4" diameter circle I would use G16X2Y0A60G70RPT6. Drilling multiple holes with G70 and G16 is fairly easy, when it gets to milling with G16, it gets interesting to say the least.


    I'll try to play with it a little tomorrow, got some other projects going that I can fold it in with. Let the boss know I've got stuff to work on and put up the DO NOT DISTURB UNLESS A MACHINE PUKES sign. :):
     

    Site Supporter

    INGO Supporter

    Staff online

    Forum statistics

    Threads
    531,066
    Messages
    9,965,810
    Members
    54,981
    Latest member
    tpvilla
    Top Bottom