If you own or plan to buy a CNC hot wire foam cutting machine, understanding G-code is essential. G-code is the programming language that tells your machine exactly where to move, how fast to move, and when to start or stop the cutting wire. Even if you use software that generates G-code automatically, knowing the basics helps you troubleshoot problems, optimize cuts, and customize your workflow.
This tutorial starts from absolute zero — no prior programming or CNC experience required. By the end, you'll understand every G-code command used in foam cutting and be able to write simple programs by hand.
What is G-Code?
G-code (also written as G code or gcode) is a standardized programming language used to control CNC (Computer Numerical Control) machines. It was developed in the 1950s and is used worldwide for CNC mills, lathes, 3D printers, laser cutters, and of course, hot wire foam cutters.
A G-code program is simply a text file containing a list of commands, executed one line at a time. Each line tells the machine to perform a specific action — move to a position, set a speed, turn on the wire, etc. Here's what a simple G-code program looks like:
G90 ; Use absolute coordinates
G28 ; Home all axes
M3 ; Turn on hot wire
G1 X100 F300 ; Move to X=100mm at 300mm/min
G1 Y50 ; Move to Y=50mm
G1 X0 ; Move back to X=0
G1 Y0 ; Move back to Y=0
M5 ; Turn off hot wire
G28 ; Return home
That's it — nine lines that tell the machine to cut a 100mm × 50mm rectangle. Let's break down every part.
Essential G-Code Commands for Foam Cutting
CNC foam cutters use a subset of the full G-code standard. Here are the commands you'll use 95% of the time:
Movement Commands
| Command | Name | What It Does | Example |
|---|---|---|---|
| G0 | Rapid Move | Moves to position at maximum speed (no cutting). Used for positioning before or after a cut. | G0 X50 Y30 |
| G1 | Linear Move | Moves in a straight line at a controlled feed rate. This is the primary cutting command. | G1 X100 Y50 F300 |
| G2 | Clockwise Arc | Moves in a clockwise arc. Uses I,J to define arc center offset or R for radius. | G2 X50 Y50 R25 |
| G3 | Counter-clockwise Arc | Moves in a counter-clockwise arc. Same parameters as G2. | G3 X50 Y50 I25 J0 |
Positioning Modes
| Command | Name | What It Does |
|---|---|---|
| G90 | Absolute Mode | Coordinates are relative to the origin (0,0). G1 X100 means "go to position X=100mm". This is the most common mode for foam cutting. |
| G91 | Incremental Mode | Coordinates are relative to current position. G1 X100 means "move 100mm in the X direction from wherever you are now". |
Machine Control Commands
| Command | Name | What It Does |
|---|---|---|
| G28 | Home | Returns all axes to their home (zero) position. Always use at the start and end of a program. |
| M3 | Wire On | Turns on the hot wire heating. Must be called before making cuts. |
| M5 | Wire Off | Turns off the hot wire. Always turn off when done cutting. |
| F | Feed Rate | Sets the cutting speed in mm/min. F300 = 300 millimeters per minute. Once set, it applies to all subsequent G1/G2/G3 moves. |
Important: The F (feed rate) value directly determines cutting time. A higher feed rate means faster cuts but may create rougher edges in dense foam. A lower feed rate means slower cuts but smoother, cleaner edges. Finding the right balance for your material is key to quality results.
Understanding Feed Rate: The Key to Quality Cuts
The feed rate (F value) is the single most important parameter you'll adjust. It controls how fast the wire moves through the foam, which directly affects both cutting time and edge quality.
| Foam Type | Density | Recommended Feed Rate | Notes |
|---|---|---|---|
| Low-density EPS | 10–15 kg/m³ | 400–600 mm/min | Very soft, cuts easily at high speed |
| Standard EPS (Thermocol) | 15–25 kg/m³ | 200–400 mm/min | Most common material, medium speed |
| High-density EPS | 25–35 kg/m³ | 150–250 mm/min | Slower for clean edges |
| XPS (Styrofoam) | 30–40 kg/m³ | 100–250 mm/min | Denser, needs more melting time |
💡 Feed Rate Rules of Thumb
- Too fast → Wire drags, bends, may break. Cut surface is rough and uneven.
- Too slow → Excessive melting occurs. Cut is wider than intended, creating a large kerf. Edges may be wavy.
- Just right → Wire glides smoothly through foam. Cut surface is smooth, sealed, and dimensionally accurate.
- Start slow, speed up → Always test with a slower feed rate first, then gradually increase until edge quality degrades.
4-Axis G-Code: Controlling Two Towers Independently
On a 4-axis CNC foam cutter, each tower has its own X and Y axis. The standard convention is:
- X, Y — Left tower position
- U, V (or A, B) — Right tower position
When both towers receive the same coordinates, the wire moves as one unit (2D profile cut). When they receive different coordinates, the wire tilts and creates 3D tapered shapes.
; Example: Tapered cut (circle → square)
; Left tower traces a circle, right tower traces a square
G90
G28
M3
; Left tower: circle path | Right tower: square path
G1 X50 Y0 U0 V0 F200
G1 X50 Y0 U100 V0
G3 X0 Y50 I0 J50 U100 V0 ; Left: arc, Right: straight
G1 X0 Y50 U100 V100
G3 X-50 Y0 I-50 J0 U100 V100 ; continues...
G1 X-50 Y0 U0 V100
G3 X0 Y-50 I0 J-50 U0 V100
G1 X0 Y-50 U0 V0
M5
G28
This capability is what makes 4-axis machines so powerful — and why they're the preferred choice for professional work.
The Complete Workflow: From CAD to Finished Cut
Here's the end-to-end process for going from an idea to a finished foam piece:
- Design your shape in CAD software — Use any 2D/3D design tool: AutoCAD, SolidWorks, Inkscape (free), FreeCAD (free), or even CorelDRAW. Create the cutting profile as a 2D vector path.
- Export the path — Export your design as DXF, SVG, or a similar vector format that preserves the cutting path coordinates.
- Generate G-code using CAM software — Import the vector file into foam-cutting CAM software:
- Jedicut — Free, designed specifically for 4-axis foam cutting
- GMFC — Free G-code maker for foam cutting
- FoamWorks — Specialized foam cutting software
- DevFoam — Professional foam cutting CAM
- Set parameters — Configure feed rate, wire temperature, and cutting dimensions in the CAM software.
- Transfer G-code to machine — Send the generated G-code file to the CNC controller via USB.
- Setup and calibrate — Place the thermocol block, home the machine, and verify wire tension and temperature.
- Run the program — Execute the G-code and monitor the first cut. Adjust feed rate if needed.
- Remove finished piece — The cut piece is complete with smooth, sealed edges — no post-processing required.
Common G-Code Mistakes and How to Fix Them
1. Forgetting to Set the Coordinate Mode
Always start your program with G90 (absolute mode) unless you specifically need incremental mode. If the mode isn't set, the machine may use whatever mode was active from the previous program, causing unpredictable movement.
2. Missing Feed Rate
If you use G1 without specifying F, the machine uses the last set feed rate — which might be from a previous program. Always set F explicitly for your first cutting move.
3. Not Homing Before Cutting
Always use G28 at the start of every program. If the machine doesn't home first, all coordinates will be offset by however far the wire is from the origin, ruining the cut.
4. Feed Rate Too High for Material
If the wire bends during cutting or the edges are rough and uneven, your feed rate is too high for the foam density. Reduce F by 25–50% and test again. Check our precision cutting guide for detailed tips.
5. Not Turning Off the Wire
Always end your program with M5 to turn off the hot wire. Leaving it on can overheat the wire, damage foam near the end position, and pose a safety risk.
Frequently Asked Questions
What G-code commands are used in CNC foam cutting?
The most common commands are: G0 (rapid move), G1 (linear cutting move), G2/G3 (arc moves), G90 (absolute positioning), G91 (incremental positioning), G28 (home), M3 (wire on), M5 (wire off), and F (feed rate). These cover 95% of all foam cutting needs.
What feed rate should I use for cutting thermocol?
For standard EPS thermocol (15–25 kg/m³), use 200–400 mm/min. For denser XPS, slow to 100–250 mm/min. For low-density EPS, 400–600 mm/min works well. Always start slower and increase gradually until edge quality degrades, then back off slightly.
Can I generate G-code automatically from CAD designs?
Yes! Use CAM software like Jedicut (free, 4-axis foam cutting), GMFC (free), FoamWorks, or DevFoam to automatically convert CAD designs into G-code. Import your DXF/SVG file, set cutting parameters, and export the G-code file for your machine.