I want to understand G-Code a little more

One of the issues caused by an EMI event or wanting to (safely) stop a long process to continue at a later time, can be resolved by ‘tweaking’ the g-code file to start at the last known ‘safe’ point.

I’ve tried to do this when my machine suffered an EMI, but without success - probably because I did’t know what I was doing - and as this has come up recently, I thought I’d post the text of a short .nc file to see if I understand it better. Apologies if this is boring.

Question 1: Is the text within brackets just information, and not relevant to the running of the program?

Here’s the code:

(Design File: .Volumes.Libraries.CNC.Files.Design.Projects.Bench.Front.T-Track.Bench.Front.T-Track.c2d)
(stockMin:0.00mm, 0.00mm, -38.00mm)
(stockMax:63.50mm, 850.90mm, 0.00mm)
(STOCK/BLOCK,63.50, 850.90, 38.00,0.00, 0.00, 38.00)
G90
G21
(Move to safe Z to avoid workholding)
G53G0Z-5.000
(T-Track.Groove.-.Pocket)
M05
(TOOL/MILL,6.35, 0.00, 0.00, 0.00)
M6T201
M03S18000
(PREPOSITION FOR RAPID PLUNGE) Question 2: Is this line and everything everything above it the ‘preamble’?
G0X31.75Y15.88 Question 3: Is this line the “move down from safety height” where you would start an edited .nc from?
Z6.35
G1Z-2.54F1270.0
Y819.78F2540.0
Y15.88
X28.57Y12.70
Y822.96
X34.92
Y12.70
X28.57
X25.40Y9.53
Y826.13
X38.10
Y9.53
X25.40
Z6.35
G0X31.75Y15.88
Z-1.27
G1Z-5.08F1270.0
Y819.78F2540.0
Y15.88
X28.57Y12.70
Y822.96
X34.92
Y12.70
X28.57
X25.40Y9.53
Y826.13
X38.10
Y9.53
X25.40
Z6.35
G0X31.75Y15.88
Z-3.81
G1Z-7.62F1270.0
Y819.78F2540.0
Y15.88

Question 4: So if this is where the ‘Stop’ is initiated (caused) and you want/need to start again, would you delete everything between the bold and italicised line above and the line Q3 is on?

X28.57Y12.70 And the machine would run from here, after going through the ‘preamble’?
Y822.96
X34.92
Y12.70
X28.57
X25.40Y9.53
Y826.13
X38.10
Y9.53
X25.40
Z6.35
G0X31.75Y15.88
Z-6.35
G1Z-10.16F1270.0
Y819.78F2540.0
Y15.88
X28.57Y12.70
Y822.96
X34.92
Y12.70
X28.57
X25.40Y9.53
Y826.13
X38.10
Y9.53
X25.40
Z6.35
G0X31.75Y15.88
Z-8.89
G1Z-12.70F1270.0
Y819.78F2540.0
Y15.88
X28.57Y12.70
Y822.96
X34.92
Y12.70
X28.57
X25.40Y9.53
Y826.13
X38.10
Y9.53
X25.40
Z6.35
M02

Thank you :+1:

This is G-Code, rather than being specifically Grbl.

  1. Yes, the text in parentheses are comments.

  2. Yes, the preamble would be everything above (PREPOSITION FOR RAPID PLUNGE)

  3. Correct.

  4. I wouldn’t — I’d scroll up from there to find the latest move down from safety/retract height, but otherwise, yes.

1 Like

Hmm, I’m not sure I understand your last comment.

Wouldn’t you delete it and (I forgot to add this bit) save it as a new file just to run the rest of the code?

It may help to know what you’re telling the machine to do at each line (see below). Since the line you are starting from doesn’t have a Z value and is in G0 (move as fast as you can mode), the machine will be moving as fast as possible for that layer you’re starting at (hopefully cutting through air and not hitting any clamps, your workpiece, or other objects). You can use the information below to create a sane starting point at an arbitrary point in the file.

You can learn more about G-code from the RS-274 specification (The NIST RS274NGC Interpreter - Version 3 | NIST) or from the Linux CNC documents since Grbl adheres to the Linux CNC implementation of their G-codes (G Codes).

G90                            ; All X, Y, Z values will be in absolute coordinates and not offsets of current positions
G21                            ; All values are in millimeters
G53G0Z-5.000                   ; Move to 5 millimeters below the highest Z point
M05                            ; Turn off the spindle/router
M6T201                         ; Change to tool number 201
M03S18000                      ; Turn on spindle/router clock-wise at 18,000 RPM
G0X31.75Y15.88                 ; Move as fast as you can to the given X, Y position offset from your work zero/origin
Z6.35                          ; Move as fast as you can to a quarter inch above the work zero
G1Z-2.54F1270.0                ; Move at 1270mm/min cutting speed, -2.54 mm below your work zero
Y819.78F2540.0                 ; Move at 2540mm/min cutting speed to the given Y position (X and Z stay the same)
Y15.88                         ; Maintain same speed, same X, same Z, and move to Y 15.88
...
2 Likes

Will already answered your specific questions, but I would also recommend using ncviewer (online app); it lets you load gcode into it and it’'ll visualize the paths. Also then you can highlight each line and it’ll show what each specific line of gcode is about in the visualisation

3 Likes

You want the first move in the file to be a plunge from a safe position.

1 Like

Thanks, @WillAdams. Title updated accordingly.

OK, so (PREPOSITION FOR RAPID PLUNGE) isn’t part of the preamble, thank you.

Sorry, but would you mind pointing an appropriate line out to me, please, because I thought this…

…was that?

Thanks, @fenrus. I use that to visualise the toolpath, but didn’t think to use it to identify specific lines.

Thanks, everyone.

The relevant parts are these lines:

G53G0Z-5.000 ; Rapid the Z axis up (it's -5 in the machine coordinate system (that's what the G53 is for), which I assume has max-Z at 0, so this is 5mm below the maximum Z height)
G0X31.75Y15.88 ; Rapid to X31.75, Y15.88
Z6.35 ; Rapid to 6.35mm above the stock
G1Z-2.54F1270.0 ; Plunge 2.54mm into the stock at 1270mm/min

Those last two are the plunge. First, a fast plunge to just above the stock to make sure you’re not rapiding through material, then a second, slower plunge, to safely enter the material.

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.