Parametric G-Code for cutting PCBs

Tags:

It’s convenient to be able to cut rectangular PCBs with your CNC mill, but calculating the required coordinates and compensating for tool size by hand is no fun. Fortunately, G-code is sophisticated enough to describe this task parametrically.

cut-rectangle.ngc (download)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(-- BEGIN CONFIGURATION --)

(Tool size [mm])
#100 = 1.0
(Board width [mm])
#101 = 20.0
(Board height [mm])
#102 = 30.0
(Board thickness [mm])
#103 = 1.5
(Safe Z value [mm])
#104 = 5.0

(Feedrate [mm], spindle speed [rpm])
F30 S1200

(-- END CONFIGURATION --)

(Metric, Absolute)
G21 G90

G00 X[-#100/2] Y[-#100/2] Z#104
M03

G01 Z[-#103]
G01 Y[#102+#100/2]
G01 X[#101+#100/2]
G01 Y[-#100/2]
G01 X[-#100/2]

G00 Z#104
M02

Of course, before you launch this script, you need to set up the coordinate system. Jogging the tool to (0, 0, 0) and executing G10 L20 P0 X0 Y0 Z0 would do the job.

You can even simulate the toolpath in OpenSCAM, as it can perform calculations in g-code:


Want to discuss this note? Drop me a letter.