, 4 min, 654 words
Tags: hardware
Over in another post, I've been working on getting an old 3D printer up and running. It became clear by the end of that post that I need to understand g-code better. So here's my attempt at that. (These are effectively notes for myself, and if they help someone else out, all the better.)
G-Code is, according to Wikipedia, "the most widely used computer numerical control programming language". That is, it's the assembly language of automated manufacturing – the basic set of instructions that you can use to tell an automated lathe, CNC mill, or 3D printer what to do.
For reference, here's the "starting gcode" in Cura (Manage Printers -> Machine Settings)
G21 ;metric values
G90 ;absolute positioning
M82 ;set extruder to absolute mode
M106 ;start with the fan on for filament cooling
G28 X0 Y0 ;move X/Y to min endstops
G28 Z0 ;move Z to min endstops
G29 ;run auto bed leveling
G1 Z15.0 F9000 ;move the platform down 15mm
G92 E0 ;zero the extruded length
G1 F200 E10 ;extrude 10mm of feed stock
G92 E0 ;zero the extruded length again
G1 F9000
;Put printing message on LCD screen
M117 Printing...
Cura inserts the following before the starting code (apparently if you include heating commands in your custom gcode, it may skip adding these beforehand, but I haven't tested that):
;FLAVOR:Marlin
;TIME:191
;Filament used: 0.0893543m
;Layer height: 0.2
;MINX:42.45
;MINY:92.95
;MINZ:0.3
;MAXX:57.55
;MAXY:110.05
;MAXZ:8.3
;Generated with Cura_SteamEngine 4.8.0
M140 S60
M105
M190 S60
M104 S200
M105
M109 S200
M82 ;absolute extrusion mode
And here's what happens after that:
G92 E0
G92 E0
G1 F2700 E-0.7
;LAYER_COUNT:41
;LAYER:0
M107
G0 F3600 X45.411 Y93.329 Z0.3 <-- this sets the Z height for the 0th layer
;TYPE:SKIRT
G1 F2700 E0
G1 F1500 X45.997 Y93.128 E0.03091
G1 X46.604 Y93.004 E0.06182
G1 X47.124 Y92.961 E0.08785
; ... more G1/G0 commands with absolute coordinates
; E[xxx] means the cumulative extrusion length should reach [xxx] over the course of the move.
; F[xxx] means the "Feed rate" (move speed) shouldn't exceed xxx (units??)
; ... end of 0th layer
;MESH:NONMESH
G0 F600 X51.401 Y98.919 Z0.5 ; <-- this is what moves us up to 0.5mm in Z
G0 F3600 X52.08 Y104.58
G0 X52.15 Y104.65
;TIME_ELAPSED:24.380026
;LAYER:1
M106 S255
;TYPE:WALL-INNER
;MESH:settlement.STL
G1 F1816.3 X47.85 Y104.65 E18.08754
And at the end of the run:
;MESH:NONMESH
G0 F600 X50.143 Y98.147 Z8.3
G0 F7200 X50.074 Y104.95
G0 X50.074 Y105.05
;TIME_ELAPSED:189.910031
;LAYER:40
;TYPE:WALL-OUTER
;MESH:settlement.STL
G1 F600 X49.926 Y105.05 E89.02557
G1 X49.925 Y97.95 E89.26172
G1 X50.074 Y97.95 E89.26668
G1 X50.074 Y105.05 E89.35434
G0 F7200 X49.926 Y105.05
G0 X49.926 Y104.998
;TIME_ELAPSED:191.375966
G1 F2700 E88.65434
M140 S0
M107
M104 S0 ;extruder heater off
M140 S0 ;heated bed heater off (if you have it)
G91 ;relative positioning
G1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure
G1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even
more
G28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way
M84 ;steppers off
G90 ;absolute positioning
M82 ;absolute extrusion mode
M104 S0
;End of Gcode
I have neither the expertise nor the time to do a line-by-line breakdown of what all this does.
I believe that what I want is to move the platform up or the extruder down by a bit. The advice seems to be moving in 0.2mm increments to avoid damaging the build plate. So here we go!