To avoid these ads, REGISTER NOW!

A small challenge to you G coders

gol4

Well-known member
Joined
Jun 16, 2012
Messages
287
Location
Nebraska
I recently built a small CNC machine so I am now learning gcode. I have been to various tutorials and feel like I am getting it down, just not mastered.
I learn best by seeing examples of the several ways others to do things.

What I would ask is for you to post "your" gcode doing an engraving of a game of TIC-TAC-TOE in a 6”x6” grid. (That size should fit most machines)

The order you do it in does not matter, draw the grid (2 vertical and 2 horizontal lines) and fill it in with XOX,XOO,OXX. Make it 1/4“ depth with the deepest pass being 1/8” (2 passes). Cutter rotation is clock wise with a 1/8” bit. Last step is raising the bit. No need to home it.

Choose 1 of 2 goals:
1. Do it using the least lines of code. (don’t worry about tear out or up milling)
2. Make it the most efficient. (Clean cuts and least amount of machine movement)

Please use a lot of comments to describe what/why you are doing with the code. This will assist with learning. Comments don’t count as lines of code. If calling a sub program make sure that is included as well.

I want to see how others efficiently do things like repeat lines, call subroutines, use parameters and other gcode processes.

There are no prizes, just a chance to show off your skills. I am sure others can learn from this exercise as well.
 
To avoid these ads, REGISTER NOW!

rockwithjason

Well-known member
Joined
Jan 8, 2006
Messages
2,633
Location
Las Vegas
if you want to get buy in for this you should post your own work first. in my experience if you ask a person to do the exercise they have little to no motivation to do so. if you post your own work and comments they can easily give you pointers and references. when you ask them to do it for you it seems like you are wanting them to do your homework for you. JMHO.
 

gte718p

Well-known member
Joined
Mar 12, 2009
Messages
3,949
I don't think you will find to many G-code experts out there anymore. No one writes complicated Gcode by hand anymore.

If I was bored I could draw it up and run it through my python path optimization program, but that doesn't seem sporting and defeats the purpose. I had to write the program almost 20 years ago for a school project. It is not exactly difficult and similar routines are built into just about every CAM package. Though most of them balance best finish and tool life with most efficient instead of going for only the most efficient.
 
OP
G

gol4

Well-known member
Joined
Jun 16, 2012
Messages
287
Location
Nebraska
Jason, I understand what you mean about doing the homework. I know other forums I was on in past years there would always be the occasional student looking for you to complete his assignment. I have not had homework in 35 years. If I just wanted to print it out I could let one of the many apps do it for me. I only suggested tic tac toe as it was repetitive and figured I would see some examples on parameters and subroutines. The one I wrote for practice is pretty long and would be reduced if I wrote the 5 xs and 4 o's from subroutines.


gte718P Based on the responses so far I think what you say may be true.It is very easy to have something generate the code. Everything I read indicated that while the code may be generated for you knowledge was pretty much essential. One tutorial indicated that 40% write their code from scratch and 45% read or tweak their programs.
 

Fcvapor05

Well-known member
Joined
May 4, 2014
Messages
1,079
45% read or tweak their programs.

This is *maybe* true.

Most guys aren't going to edit anything because any reasonably new CAM system is going to do a pretty good job of optimization- but they will still scan through the code real quick as a sanity check.

40% write their code from scratch

In the modern machine shop, there's not a chance this is factual. I can spit out a fully optimized, ready-to-run program from a solid model very, very fast. On anything other than a flat plate with less than 2 or 3 holes, there's not a chance that the fastest g coder in the world can beat a CAM program. Time is money.
 

zkling

Well-known member
Joined
Jan 23, 2007
Messages
16,939
What cnc software are you running? I run Linuxcnc and a few different cam packages. Not doing anything very complex though. IMHO the best way to learn about it is to generate a machine input file via a cam package and then view it in a text editor (notepad ++ is a favorite of mine). Add different features and then see how that changes the code. It's like creating your own function for a built in function in matlab, for school is one thing, but learning to use in practice is different. Unless you just really want to know the ins and outs of code generation and optimization, which will take quite a bit of time and mathematics. At one point in time I had to write a matlab script that would generate G code from a imported step file.
 

gte718p

Well-known member
Joined
Mar 12, 2009
Messages
3,949
gte718P Based on the responses so far I think what you say may be true.It is very easy to have something generate the code. Everything I read indicated that while the code may be generated for you knowledge was pretty much essential. One tutorial indicated that 40% write their code from scratch and 45% read or tweak their programs.

I'm not a professional machinist by any means. But I highly doubt 40% of machinists write code by hand. For complex 3D parts, it is just to hard or impossible to do path computation and optimization by hand. I just ran an extremely simple part last night. It was basically one pocket. The spiral plunge just to get to the cutting depth was almost 200 lines of code, but the computer spit it out in less then a second and it ran in less the 3 seconds. There is no value added in paying someone to physically type the code in. It would probably have take me 20 minutes to type and proofread it.

There are exceptions. There are still thousands of old school machining centers floating around in production environments that run on old old equipment. One of the shipyards I spend a lot of time is still running punch cards for some of their machines. (Good luck finding parts or competent programmers for them) Once every blue moon they have to tweak something. The only option is to code them by hand.

I understand the value of learning the basics. In college for my CAD/CAM class we started with the basic math behind how to build a CAD system. I had to learn how curves and surfaces work and how to represent curves, nodes, and surfaces as mathematical equations. Then join them and smooth them. It was painful, and didn't contribute to my ability to design parts in a CAD system. We actually had to learn the CAD program they were "teaching" ourselves. I have not used I-deas since college. It doesn't even exist anymore. They got bought out and are part of the NX package now. I did learn how all CAD programs work under the hood, so it is just a matter of finding the right button to make it do what I want it to do. I can also write my own tools. I think it is valuable to know basic coding and understand the language. But I wouldn't waste time practicing optimizations or doing big projects by hand.


What cnc software are you running? I run Linuxcnc and a few different cam packages. Not doing anything very complex though. IMHO the best way to learn about it is to generate a machine input file via a cam package and then view it in a text editor (notepad ++ is a favorite of mine). Add different features and then see how that changes the code. It's like creating your own function for a built in function in matlab, for school is one thing, but learning to use in practice is different. Unless you just really want to know the ins and outs of code generation and optimization, which will take quite a bit of time and mathematics. At one point in time I had to write a matlab script that would generate G code from a imported step file.

My entire tool chain for CAD/CAM is freeware.

I'm running LinuxCNC as the control package for the mill. I used to run GRBL and bCNC. For smaller machines and projects I highly recommend it.

I use a combination of FreeCAD, Medusa, and Fusion360 for CAD. Each has strengths and weakness. As Fusion 360 matures it is becoming my go to package. Originally it did not support 3D milling, and FEA. Both now are included to a limited extent. FreeCAD still have much better FEA analysis, but overall is not as user friendly.

For anything I draw in Fusion 360 I use the integrated CAM package. The EMC post process is not the best and causes some issues with my mill, but the path planning and optimization are pretty top notch. For FreeCAD I use PyCAM and scripts I wrote myself.
 

Heavy Metal Doctor

Well-known member
Joined
May 26, 2010
Messages
5,417
Location
Mason Dixon Line
Interesting read. All I want to say that it appears things have changed a lot in 25 / 30 years!:lol_hitti

I used to write code for my own machines off of drawings, tailoring it to match the tooling available....I cut my teeth on a Matsuura Tiger and we thought we where high tech back then just cause we could then run thousands of the same part once the program was written!
 
OP
G

gol4

Well-known member
Joined
Jun 16, 2012
Messages
287
Location
Nebraska
I am running linuxCNC and like it. I have been playing with the various gcode generator software that came with it but have to say I enjoy sitting in the MDI and punching in codes.
Trying to truly understand (g2,g3) the archs and and such I feel will be a true benefit to me.
I have no intent to try and not use tools that are available to me. If I am going to engrave a sign or something I would not even try to code out letter movement.

The site that I saw the percentages was from a tutorial I took on cnc cookbook
 

bsaint

Well-known member
Joined
Apr 26, 2010
Messages
5,109
Location
Manchester, CT
The laser process is a involved one. Pierce routines, modulation for corners, lead in and what not. They are all generally tailored to a machine, Ive never seen a generic one thats worth anything. Ive been in the field for 9 years.
 

SuperCheyenne

Well-known member
Joined
Jul 18, 2016
Messages
147
Location
Newton KS
there's not a chance this is factual. I can spit out a fully optimized, ready-to-run program from a solid model very, very fast.

Not to get too sidetracked in this thread. But you'd be surprised. There's places where they only use G-Code and the skill level and creativity would blow your mind. Same goes for manual machines BTW. The true skill is the guys who run a knee mill with a rotary head attachment. I bow in their presence.

I'm on the wrong side of 40 and sit behind a desk now. But "in my day" I could program a 4 axis part using MDI and I could often stay ahead of the machine.
*Variables apply of course.

Sorry for drifting off topic.
 
To avoid these ads, REGISTER NOW!

SuperCheyenne

Well-known member
Joined
Jul 18, 2016
Messages
147
Location
Newton KS
Trying to truly understand (g2,g3) the archs and and such I feel will be a true benefit to me.


G2 and G3 are calculated the same. Obviously one is clockwise (G2) and the other is counter clockwise (G3).

Climb cutting or conventional cutting is going to determine if you want to use G2 or G3.

I will try to diagram the "formula" for Circular Interpolation.

Start point is x#1 y#1
Center of arc is x#2 y#2
End point is x#3 y#3

So your "formula" would look like

G2 x#3 y#3 i (x#2 - x#1) j (y#2 - y#1)

remember your basic math rules. a minus/minus is really a plus. etc. etc.


That "formula" is for your standard 2 xy axis but it works in all axis.
To change axis coordinates you'd use G17 (xy), G18 (xz), G19 (yz).
 

SuperCheyenne

Well-known member
Joined
Jul 18, 2016
Messages
147
Location
Newton KS
Please use a lot of comments to describe what/why you are doing with the code.

I'll give you the theory of what I'd do.

write one program in incremental (G91) (include plunge and retract) for a 1.5" square "X" (call it program O0010) end program with G90 & m99
write one program in incremental (G91) (include plunge and retract)for a 1.5' square "O" (call it program 00020) end program with G90 & m99

Now go to your main program.
Create your 4 grid lines (beyond simple because they're at 2" increments).

Then go to the center of each grid. (X1 Y1 for example)
Call M98 P0010 (for an X) or M98 P0020 (for a O)

I realize that probably won't translate well over a message board but I could do that in roughly 10 minutes at a control.
 
Last edited:
OP
G

gol4

Well-known member
Joined
Jun 16, 2012
Messages
287
Location
Nebraska
supercheyenne, Thanks for the detail. No doubt in my mind you have it down.The m98 and 99 calls was what I was not fully understanding. It makes sense now

I spent some more time tonight in the mdi and writing some code. I do this because I need to see the effects the code has.
There was one point that I mis-typed and did G0 Z1.25 instead of .125. Let me just say it plunges pretty quickly.
I am getting closer to having g2 and g3 down prety good. What I have to remember is to allow for the thickness of the bit during these calculations. I do like that once you place the bit just calling i will create the circle. (assuming feed rate is already loaded
The reason I want to get this down is I don't want to have to sit down and draw in cad, convert some files,then align the piece then load the program.
I want to fix the piece on the table line up the bit, make my cuts, and get back to tasks at hand.
Usually what I will do is cut a circle or square in 1/4" or less material. The squares I can use it like a DRO but for circles I need to actually know what I am doing.:)
 

APEowner

Well-known member
Joined
Oct 2, 2009
Messages
4,164
Location
Sunny, New Mexico
The laser process is a involved one. Pierce routines, modulation for corners, lead in and what not. They are all generally tailored to a machine, Ive never seen a generic one thats worth anything. Ive been in the field for 9 years.

Thanks. That's the impression I've gotten from the little research I've done on the subject. We're adding laser welding to our manufacturing process and I'm anticipating that it'll all be hand coded. I've done very little g-code but I've done a bunch of embedded programing and robotic motion control so I'm not really worried about it but if there were an affordable tool that would automate that I sure would prefer that.
 

Jim Johnstone

Well-known member
Joined
Apr 11, 2011
Messages
1,841
Location
Brantford, Ontario
I spent 10 minutes helping a younger guy at work trying to make a simple contour program with a step down and cutter compensation for sizing. He had it so convoluted with loops and sub routines I just gave up trying to sort out his program and sat down at mastercam and drew the part and programmed it in about 2 minutes.
 
OP
G

gol4

Well-known member
Joined
Jun 16, 2012
Messages
287
Location
Nebraska
Well I am getting better. Turns out Linuxcnc won't do M98 and 99 calls. It uses ocodes instead. Last evening I practiced passing a few parameters to some subs. Today I had about 20 minutes at lunch and wrote this from scratch in MS wordpad. Emailed it to myself, pasted it in when I got home and it ran first time. The circles could be a bit larger and centered better. But not bad considering I have been doing this in my spare time in less than a week.
I am sure this could be even shorter by a real coder.
My first attempt at this was over 100 lines and took hours to debug.

As you recall in war games they stopped world annihilation by teaching the computer the futility of tictactoe. Feel free to use this should AI ever take over and you need to calm your CNC :)

<code>
(engrave 6X6grid XOXXOOOXX)
o100 sub
(cuts x x=#1 y=#2)
G0 X[#1] Y[#2](Position cutter top left square)
G0 Z-.125(PLUNGE BIT)
G91(switch to incremental mode)
G1 X2 Y2 (CUTS \)
G0 Z.25(RAISE BIT)
G0 Y-2 (MOVE 2" left)
G0 Z-.25(PLUNGE BIT)
G1 X-2 Y2 (CUTS /)
G0 Z.25(RAISE BIT X DONE)
G90 (switch back to absolute mode)
o100 endsub

o200 sub
(cuts circle x=#1 y=#2)
G0 X[#1+.125] Y[#2+.875](Position cutter top center)
G0 Z-.125(PLUNGE BIT)
G2 i.75 (CUTS CLOCKWISE)
G0 Z.25 (RAISE BIT TO MOVE)
o200 endsub

o300 sub
(cut lines #1startx #2starty #3endx #4endy)
G0 X#1 Y#2
G0 z-.125 (plunge bit)
G1 x[#3] y[#4] (FIRST LINE DONE)
G0 Z.25 (RAISE BIT)
o300 endsub

G20 G90 F5(Inches,Absolute,feed)
o300 call [0] [2] [6] [2]
o300 call [6] [4] [0] [4]
o300 call [2] [6] [2] [0]
o300 call [4] [0] [4] [6]
o100 call [4] [4] (1st X BOTTOM RIGHT)
o100 call [4] [2] (2nd X BOTTOM MIDDLE)
o200 call [4] [0] (1st 0 BOTTOM LEFT)
o100 call [2] [0] (3RD X MIDDLE LEFT)
o200 call [2] [2] (2nd 0 CENTER)
o200 call [2] [4] (3rd 0 CENTER RIGHT)
o100 call [0] [4] (4th X TOP RIGHT)
o200 call [0] [2] (4th O TOP CENTER)
o100 call [0] [0] (5th X TOPLEFT)

M2 (end program)
%
</code>
 

gte718p

Well-known member
Joined
Mar 12, 2009
Messages
3,949
Your modules for x and circle doesn't appear to have the second pass to get it to .25 get for problem statement.

I got bored and ran it through python last night unfortunately that machine doesn't have an internet connection. With two passes it is a good bit more efficient in terms of machining time to start at the center of the x and go out to the end of each leg. At the end plunge again and return to center.. It generates a ton of extra code though.
 

highangle501

Member
Joined
Feb 16, 2016
Messages
13
The best way I have found to do g02 g03 it to break it up int the 4 corners of the circle this way you have a true never interrupted circle

as far as sub routine the quickest way I got my head wrapped around it was to program a looping jeweling program where you want a brush to touch off the top of the part, dwell raise up and advance on the axis .125 and start over.
Set it to run x number of times to make you length then step down to the next row and move back to the start point and do this x number of times to compete your length

You will end up with very few lines of code and 2 separate subs


Sent from my iPhone using Tapatalk
 
OP
G

gol4

Well-known member
Joined
Jun 16, 2012
Messages
287
Location
Nebraska
Holy **** highangle501, I never thought of using the CNC for jeweling.

I just typed this in wordpad. Untested but think it would work. Is this close to what you had come up with?
This uses nested do while loops.
<code>
o101 sub
(#1=Length #2=x start #3=yend)
#4=.75 (y start position)
do (will move along the y axis)
g0 y[#4]
do (Will move along the x axiz)
g0 z-.125(drop bit)
G4 P2 ( dwell for 2 seconds)
g0 z.125 (raise bit)
#2 = [#2+.75](add 3/4 inch)
g0 x[#2] (move x)
while [#2 LT #1]

#4 = [#4 + .75] (add 3/4 inch to Y)
while [#4 LT #3]
o101 endsub

g20 g90
0101 call [4] [.75][4]
m2
</code>
 
OP
G

gol4

Well-known member
Joined
Jun 16, 2012
Messages
287
Location
Nebraska
Went to get me a coffee and realized I did not move the x back to start. Would need to add #5 before the first do loop to track x start #5= #2. I told you it was untested
then after x completes first pass add 2 more lines.
while [#2 LT #1]
#2= #5
g0 x[#2]
#4 = [#4 + .75] (add 3/4 inch to
 
To avoid these ads, REGISTER NOW!
Top Bottom