G Code - Square
The following G Code produces a square on a round bar mounted in a 4th axis running parallel with the X axis of the milling machine. The X position is static and requires setting at initial set up, thus the height of the square is limited to the diameter of the cutting tool. The code allows for one roughing pass and then one finishing pass, and cuts from -ve to +ve Y (conventional milling).
It is very difficult to accurately find the Z position of the centre of the rod as the tools of my mill are not fixed in the collet, thus in preparation for this code it is necessary to take a cut at A0 and A180 (A being the 4 axis) and measure distance between flats. The Z position of the finished dimension can then be calculated by halving the difference between the required and measured dimensions and subtracting that from the Z position of the preparation cuts.
**Please note, this code is written to suit my milling machine, use as an example only**
( G CODE FOR SQUARE FROM BAR - 4TH AXIS)
(Cut on Y, repeat on Z, X Fixed at required depth)
(G49 Cancel Tool length of set; G40 cancel radius comp)
(G17 XY Plane; G80 Cancel Canned cycles)
(G50 Cancel scale factors; G90 Absolute distance mode)
(G60 Constant velocity; G21 mm)
G49 G40 G17 G80 G50 G90 G64 G21
#1=0 (Y in front to clear bar)
#2=10.5 (Y rear past cut)
#3=3 (Safe Z)
#4=-0.37 (Z rough)
#5=-0.415 (Z finish)
#6=30 (feedrate - ROUGH)
#7=30 (feedrate - FINISH)
M3
(ROUGHING)
F#6
G0 A0
G0 Z#3
G0 Y#1
G0 Z#4
G1 Y#2
G0 Z#3
G0 Y#1
G0 A90
G0 Z#4
G1 Y#2
G0 Z#3
G0 Y#1
G0 A180
G0 Z#4
G1 Y#2
G0 Z#3
G0 Y#1
G0 A270
G0 Z#4
G1 Y#2
G0 Z#3
G0 Y#1
(FINISHING)
f#7
G0 A0
G0 Z#5
G1 Y#2
G0 Z#3
G0 Y#1
G0 A90
G0 Z#5
G1 Y#2
G0 Z#3
G0 Y#1
G0 A180
G0 Z#5
G1 Y#2
G0 Z#3
G0 Y#1
G0 A270
G0 Z#5
G1 Y#2
G0 Z#3
G0 Y#1
M5
M30
The following G Code produces a square on a round bar mounted in a 4th axis running parallel with the X axis of the milling machine. The X position is static and requires setting at initial set up, thus the height of the square is limited to the diameter of the cutting tool. The code allows for one roughing pass and then one finishing pass, and cuts from -ve to +ve Y (conventional milling).
It is very difficult to accurately find the Z position of the centre of the rod as the tools of my mill are not fixed in the collet, thus in preparation for this code it is necessary to take a cut at A0 and A180 (A being the 4 axis) and measure distance between flats. The Z position of the finished dimension can then be calculated by halving the difference between the required and measured dimensions and subtracting that from the Z position of the preparation cuts.
**Please note, this code is written to suit my milling machine, use as an example only**
( G CODE FOR SQUARE FROM BAR - 4TH AXIS)
(Cut on Y, repeat on Z, X Fixed at required depth)
(G49 Cancel Tool length of set; G40 cancel radius comp)
(G17 XY Plane; G80 Cancel Canned cycles)
(G50 Cancel scale factors; G90 Absolute distance mode)
(G60 Constant velocity; G21 mm)
G49 G40 G17 G80 G50 G90 G64 G21
#1=0 (Y in front to clear bar)
#2=10.5 (Y rear past cut)
#3=3 (Safe Z)
#4=-0.37 (Z rough)
#5=-0.415 (Z finish)
#6=30 (feedrate - ROUGH)
#7=30 (feedrate - FINISH)
M3
(ROUGHING)
F#6
G0 A0
G0 Z#3
G0 Y#1
G0 Z#4
G1 Y#2
G0 Z#3
G0 Y#1
G0 A90
G0 Z#4
G1 Y#2
G0 Z#3
G0 Y#1
G0 A180
G0 Z#4
G1 Y#2
G0 Z#3
G0 Y#1
G0 A270
G0 Z#4
G1 Y#2
G0 Z#3
G0 Y#1
(FINISHING)
f#7
G0 A0
G0 Z#5
G1 Y#2
G0 Z#3
G0 Y#1
G0 A90
G0 Z#5
G1 Y#2
G0 Z#3
G0 Y#1
G0 A180
G0 Z#5
G1 Y#2
G0 Z#3
G0 Y#1
G0 A270
G0 Z#5
G1 Y#2
G0 Z#3
G0 Y#1
M5
M30