TurboCNC gCode Summary
G-Code Summary (TurboCNC)
G00 Rapid move
Moves to the coordinates specified as fast as possible.
Usage:
G00 X1.2 Y0.3 ;Moves to coordinate (1.2,0.3) at full speed.
G01 Interpolated feedrate move
Moves to the coordinates specified using the programmed feedrate for interpolation (as modified by the override)
Usage:
G01 X1.2 Y0.3 F3.0 ;Moves to coordinate (1.2,0.3) at 3 units/minute
Here are the rules for feedrates (assuming english units):
- A single linear axis moves in ipm or ipr.
- A single angular axis moves in deg/sec.
- Multiple linear axes move in ipm/ipr according to the square root of the sum of their squares distance.
- Multiple angular axes move in deg/sec for the first axis on the line, all others follow.
- Mixed angular and linear axes follow the rules for linear axes, the angular axes will follow.
- No axis will ever go faster than the max speed established in setup.
The feed override affects all moves except for rapids (G00).
G02 CW circular interpolation
Moves in a CW circular arc with its center set by signed I and J increments, to the destination given.
Usage:
G02 X1.0 Y1.0 I0 J1 F2.0 ;Arc to (1,1) with center at origin
That will move from the current point to (1,1) in an arc with its center at the current point + 1 unit in the Y direction at 2 units/minute.
In G16 mode (implicit planes) I is the center point offset for the first axis on the line (X in this case) and J is the center point offset for the second (Y in this case) regardless of the actual axis names.
If the destination is the same as the origin, a full circle will be described by the tool motion. I and J are always incremental. (PLEASE NOTE: In rev 3.00g and prior, the I and J word were absolute in absolute mode, incremental in incremental mode. This is no longer the case.)
In G17/18/19 modes, the order of parameters on the program line is not important. Use the I word for offset in the X direction, J for offset in Y, and K for offset in Z to describe the center position from the starting point.
An alternate syntax is to define the radius of the arc and the endpoints only, as follows:
G02 X1.0 Y1.0 R0.25 ;Radius defined arc to (1,1)
This heads to (1,1) from the current point with an arc of .25 radius. Using a negative radius chooses the arc greater than 180 degrees that crosses both points, a positive radius takes the arc that is 180 degrees or less. The program will stop with a warning if you have a radius that is impossible.
Although you can cut a full circle by specifying the endpoint to be the same as the start point, I don't recommend this since rounding of the values can cause the control to cut the infinitesimally short arc instead. Program both halves of a full circle. Eventually I'll add a "full circle" code to get around this.
G03 CCW circular interpolation
Similar to G02, but counterclockwise.
G04 Dwell
Pauses execution for an integer number of seconds.
Usage:
G04 #6 ;pauses for 6 seconds
**WARNING** Don't use G04 and your hands as a tool-changer. It takes longer than you think... Use M00 or M06 instead.
G16 Set implicit planes (TurboCNC former standard)
The original TurboCNC thru rev 3.00g+ used an implicit plane specification in which the first two axes called out on a G02/03 line became the plane of action for the interpolation. This is the default mode at startup for compatibility with files written for earlier versions. I suggest you re-write them to use the conventional plane selectors if possible. Note that I and J are always incremental now.
G17 Set XY plane
Sets plane for circular and helical interpolation to X-Y.
G18 Set XZ plane
Sets plane for circular and helical interpolation to Z-X.
G19 Set YZ plane
Sets plane for circular and helical interpolation to Z-Y.
The rule for planes and CW/CCW is this (from the RS-274 standard):
Arcs shall be CW or CCW as viewed in the negative direction of the out-of- plane axis in a standard right hand axis system.
Translation: For mill users, if +X is rightward and +Y is toward the back of the machine (That's tool motion relative to the work!) and +Z is up, then as you look down (-Z) at the table in G17 mode, arcs will look CW or CCW as you'd expect.
For lathe users, if +Z is away from the headstock, and +X is increasing diameter, then in G18 mode CW/CCW will look reversed if you look down at the slide. This is because in this right hand system, -Y is looking up.
G20 Inch units
Sets distance unit to inches.
G21 Metric units
Sets distance unit to mm.
NOTE: G20 and G21 are identical to G70 and G71.
G28 Home all axes
Each axis with a home switch will be driven to the home position and its position reset. This is for recalibrating your machine during long cycle times where temperature creep or position loss is a factor.
G31 Probe move
Move with continuous check for digitizer probe strike. If the probe hits something, the machines stops and write the position to the file POINTS.DAT in the same directory as the executable.
Use G31 just like G01, e.g.:
G31 Z-4 F10
This will move to Z-4 at 10 ipm, unless the probe input goes active. If so, it'll stop and write the tripped position to points.dat in the current directory. You can use G31 to get off of the part again if you need to, the program only accepts the rising edge as valid input. Note that if you move twice in the same direction with G31, you can smash your probe!
Manual probing: When the probe is "on" in jogging mode, every move is like a G31, except that the points are not written when the input is triggered. Use "F" to write a point anytime. This is mainly for tinkering and testing the probe geometry, although clever folks might figure out how to make a teachable CNC using this feature.
G32 Probe cycle
Repetitive probing to digitizer scan a 2 or 3D surface
Usage:
G32 Xbound Ybound Zbound Idiscretization Ffeed #reserved
This is 2 or 3-axis general, so the last axis cycles the most and the first axis only once through a number of points determined by the discretization distance. In the future, separate algorithms for this will be supported, so until then don't use the # code. The digitizing scheme is of the "bed of nails" variety, e.g.: straight up and down in the last axis on the line.
WARNING: Rounding error may prevent the last row or column from being scanned. Add a small amount to the bounding distance to avoid this, e.g.:
G32 X1 Y1 Z-1 I0.250 F10 ;X1,Y1 may or may not be reached
G32 X1.001 Y1.001 Z-1 I0.250 F10 ;This is better
The output is written to the a scan file in the same directory as the executable, with a filename of surfscan.dat.
G33 Single pass, single axis threading
Moves an axis to a destination point, in synchronization with the tool spindle at some lead per revolution.
Usage:
G33 Z-1.25 K0.050 ;20 TPI to Z=-1.25
A spindle index pulse must be enabled and present for this to work. The program will time-out the spindle pulse after 5 seconds of inactivity. K is the lead parameter for any axis that this code is used in conjunction with.
Allow a few revs of "lead in" for the axis to synchronize. You need a lot of acceleration to keep up with the changes in velocity - I use 14000 for the accel parameter and it's still a tad sluggish. If the axis falls behind and can't keep up, it'll stop and warn you.
The synchronization is always from the start point, so for multi-start threads, offset the start position by some fraction of the thread lead. For 30 degree infeed, change the start position on each pass along a 30 deg vector.
G53 Change to master coordinates
Puts the machine in the master coordinate system. This has the same effect as calling T0.
TurboCNC defaults to the master coordinate system at startup. Once a system of offsets is created in jog/setup mode, it may be saved using the file menu for later retrieval.
G50 Probe hole ID
Finds the center of a hole using a touch probe.
Put the probe inside the hole approximately in the center, and call G50 from within a program. This is an orthogonal six hit probing algorithm - clock positions struck are 12,6,9,3,12,6 in the XY plane as you normally view the part on a mill. In jog mode, press C to do this. You must have a touch probe installed and the input configured for this to work. This is limited to probing in the XY plane for now.
In jog mode, the two-place roundness TIR and diameter will be reported after you input the probe diameter.
Watch out for keyways and similar things that can throw you off. The reason for making this available within a program is for auto-setting boring operations or fixture locating where some part-to-part variation is expected.
G54-G59 Change to coordinate offset 1-6
This is an alias for T1, T2, T3, etc... (G54 is T1). The coordinates of each axis are reset to align with the origin point in the new offset. For example, in jog mode:
- - Get into T0 (use R and T keys)
- - Move to some special point on your machine, and zero all the axes. This is the master origin.
- - Press T to go to tool 1
- - Jog to some other point, and zero the axes again. This is the 1st offset origin. (G54 or T1)
- - If you press R to get to master/machine coordinates (T0 or G53), the coordinates in the STATUS window will change to reflect your position relative to the first point again.
The most common uses for this are tool length adjustment and multiple fixturing on the same table.
G70 Inch mode
Sets distance unit to inches.
G71 Millimeter mode
Sets distance unit to mm.
G72 CW helical interpolation
Like G02, but allows a third axis to travel linearly as well.
Usage:
G72 X1.0 Y1.0 Z.125 I0.0 J1 F2.0 ; Helical move
This line moves from the current point to (1,1) in an arc with its center at +1 unit from the starting point in Y; at 2 units/minute. Meanwhile, Z will move linearly to 0.125.
The radius form of definition using the R word may be used here as well, just like G02.
G73 CCW helical interpolation
Similar to G72, but counterclockwise.
G77 Turning/Boring/Milling Cycle
Cuts with multiple passes, infeeding by an amount set by the I word.
Usage:
G77 Z-1.250 X0.250 I0.050 F5.0 ; Diameter turning cycle
That cuts to an X coordinate of 0.250, back and forth in Z from current position to -1.250, feeding in 0.050 each pass and cutting at 5 units/min. The sign of I is important! If you're turning, I should be +, use a - I for boring (same as change on infeed axis). Infeed is applied to the second axis on the line - so this code can be used for flycutting/slabmilling or cutting deep blind slots on mills or trimming the edges of stock. Here's the actual motion sequence for on the above, assuming the tool started at 0,0:
X0.050 slowly
Z-1.250 slowly
X-0.025 slowly
Z0 rapidly
X0.100 slowly
Z-1.250 slowly
... etc
NOTE: After each pass, the control "backs off" by 1 1/2 times the infeed. So if you're boring, make sure you have enough clearance for the bar.
Also, if the infeed doesn't divide into an even number of passes, don't worry. The program's smart enough take a small finishing pass.
The order of the operands defines the motion. The back-and-forth action will occur from the current position of the first axis on the line to the position specified. The second axis called out will eventually reach the position specified by feeding in increments of I each pass.
G78 Peck Drilling Cycle
Feeds to a position on an axis, incrementally in "pecks" with a full rapid retract.
Usage:
G78 Z-2.000 I-0.100 F2.0
That drills from the current position to Z-2.000 at 2 units/min 0.100 units at a time (retracts to original Z each time) . Sign of I must be the same as the direction of cutting. If you put in a dwell parameter with the # operator, a dwell in milliseconds will be taken at the "bottom of the hole". So:
G78 Z-2.000 I-0.100 F2.0 #100
does the same as the above, with a tenth of a second dwell at the bottom of the hole. This helps the tool life considerably in some cases. After each peck and retract, the drill will rapid to 10% of the peck increment before the bottom of the hole before feeding in again.
Note that this code can be used for "peck turning" plastic on a lathe to keep the chips short.
G80 Cancel drill cycle
It's good practice, although not strictly necessary, to put this code after a series of the G81, G82, or G83 drill cycles. It clears the canned cycle variables from memory.
Usage:
G80 ;Clears canned cycles
Some CAM programs automatically generate this code after every series of drilled holes.
G81 Drill cycle
This is the canonical RS-274D drill cycle. Drills a hole at a specific XY position, to a depth Z at the current feedrate, and retracts to a release plane "R". If the release plane is further away from the work than the drill at the start, the control will rapid to the release plane first for maximum clearance.
Usage:
G81 X1 Y1 Z-0.75 F2.0 R0.25
This line will cause the control to perform the following actions:
- - Rapid to R plane if Z is less than 0.25 absolute
- - Move the table to the XY position (1,1) specified, holding Z at the point it was before.
- - Feed the Z axis to -0.75 at 10ipm.
- - Rapid the Z axis to 0.25 (the release plane)
To drill another hole just like the first, just input the XY position on the next line:
G81 X1.5 Y1.25
This second hole will be done the exact same way was the first, but at the new position of X=1.5 and Y=1.25.
If the R plane is between the current Z position and the bottom of the hole, the control will rapid to the R plane after moving XY and before drilling. If the R plane is "above" where the drill is in Z at the start of G81, the control will rapid to the R plane first before moving XY. This affords maximum safety without overly compromising speed.
Note that R is absolute in absolute mode, incremental in incremental mode! All the other parameters behave similarly.
All of the coordinates (XYZR) need to be called out on the first G81. These will "stay in effect" thereafter until G80 is called. So, if you have a series of holes that are all to the same depth, you can use this:
G81 X1 Y1 Z-0.75 F2.0 R0.25 ;First hole
G81 X2 Y2
G81 X3 Y2
X2.5
G80 ;Four holes were drilled at (1,1) (2,2) (3,2) and (2.5,2)
NOTE: These cycles ignore the plane selector - they must be carried out conventionally in XYZ as shown.
G82 Drill + Dwell cycle
Similar to G81, but requires a # parameter for the dwell at the bottom of the hole in milliseconds.
Usage:
G82 X0 Y0.5 Z-1 F10 R0.25 #250
Drills at coord (0,0.5) to a depth of Z=-1 at 10 ipm. Dwells for a quarter second, and then retracts to Z=0.25.
G83 Peck drill cycle
Similar to G81/82, but requires an I parameter for the peck increment when drilling.
Usage:
G83 X0 Y0.5 Z-1 F10 R0.25 I-0.100 #250
Same as the G82 example above, but the drill will descend at the 10 ipm feedrate in 0.100 inch pecks with a rapid retract to the original Z. The drill rapids down to 10% of the peck distance above the bottom of the hole before feeding again to minimize "air time".
The dwell parameter (#) is optional with G83. The above example will dwell a quarter second at the end of each peck. The dwell is in integer milliseconds. Expect it to be accurate to about 15% or so, it doesn't use a high precision timer.
G90 Absolute coordinates
Set coordinates to absolute mode (default).
G91 Incremental coordinates
Set coordinates to incremental mode (offsets from current position)
G92 Preload of registers/Set machine coordinates
This code sets the position of any or all axes to a specific value. Use this to reset the position inside a program. No motion will occur.
Usage:
G92 X0 ;Zeroes X axis
G92 X0 Y0 Z0 ;Zeroes all principle axes on a mill
G92 Z1.234 ;Z is now set to 1.234
You must be in the master coordinate system to use this code. All of the other offsets (1-20_ follow the master. Ergo, if the origin in offset 1 is set to be exactly 3" away from the master origin (in G53 mode), then that relationship is maintained as the master origin moves.
Use jog mode to setup the coordinate offsets (tool offsets) and save them through the file menu. This command is not modal in versions 3.1 and up.
G94 IPM feedrate
Set feedrate unit to units/min
G95 IPR feedrate
Set feedrate unit to units/rev. Be sure to have set the "S" parameter when calling this function!
G95 S1000 F0.002 ;feed is .002/rev at 1000 rpm
.
.
G01 F0.001 ;Finish pass at .001/rev
G97 Program spindle RPM
Set spindle RPM using S word.
Usage:
G97 S1000 ;1000 rpm
This function is a "placeholder" in the source code. Registered users can use it as a starting point to program their own spindle control routines into TurboCNC. Note that if you use inches/rev feedrates by calling G95, you must call G97 or otherwise set the S parameter beforehand with the spindle speed.
M00 Automatic halt
Halts program until operator presses a key.
M01 Optional halt
Same as M00, but can be disabled by the operator. (Option available under machining menu)
M02 End of program
Stops execution and cycles. This must be the last line of the program.
M03 Spindle on CW (usual for a lathe or mill)
Turns on spindle.
M04 Spindle on CCW
Similar to M03.
M05 Spindle off
Turns spindle off to coast to a stop.
M06 Tool change
Essentially the same as M00, but with a prompt to tell the user which tool is being requested. Registered users may program their own, more sophisticated routines for automated tool changes here.
Usage:
M06 T1 ;Prompts for change to tool #1 and changes to tool 1 coord offset.
M07 Coolant A on (flood)
Switches on relay A.
M08 Coolant B on (mist)
Switches on relay B.
M09 Coolants off
Switches off both relay A & B.
M13 Spindle CW and coolant A on
Turns the spindle on in the CW direction and activate the "A" coolant.
M14 Spindle CCW and coolant A on
Similar to M14.
M17 Enable drives
The Stepper World SP3 and some versions of the MAXNC drives require an enable signal in order to operate. After the enable pins have been setup in TurboCNC, use this code to turn them on. The drives will be disabled during a panic abort, or when you exit TurboCNC normally. They will be turned on when the program starts.
M18 Disable drives
Similar to M18, this turns the enable lines off. By default, they are enabled when TurboCNC starts. There are hotkeys in the jogging mode to switch these on and off as well, mainly so that you can confirm that everything works.
M30 End of program & rewind
Functionally identical to M02. Hard disks don't need to be "rewound" of course, but paper tapes used to be! Some CAM programs generate this code instead of M02 at the end of a program, so it's here for compatibility.
M48 Restore feed override
After an M49, this brings the feed override back to whatever it was just before the M49 call.
M49 Cancel feed override
This resets the feed override to 100% "from the inside". Use it before entering a critical section of your program that requires an exact feedrate.
M50 Read tachometer
This reads the spindle speed into the program for use with IPR feedrates by reading the spindle index pulse. You must have an index pulse enabled to use this code. See the short section on threading in the setup section for details on how to set this up.
M60 Jump to subroutine
Jump to line number given and save return address.
Usage:
N020 M60 #10 ;Jumps to line 10. Use a unique N code when calling subs.
M62 Return from subroutine
Back to most recent M60 call.
Usage:
M62 ;Will jump back to line N020 and execute next line in the above example.
See sample.cnc for a simple subroutine example. Please note that when using subroutines, you'll need a unique N code on each calling line so that the program knows where to go back to.
M70 Set PLC handshake output to inactive
Two PLC handshaking lines can be configured in TurboCNC. These are for telling external logic, such as an automatic tool changer or what-have-you to do some work. M70 sets the output handshake line to the inactive state. This can also be used to control extra solenoids or relays.
M71 Set PLC handshake output to active
Similar to M70, M71 sets the output handshake line to the active state.
M72 Wait for PLC handshake input to go inactive
When this code is called, the program stops running and waits for the PLC input line (separate from the output line) to go to the inactive state. This is intended to be used to synchronize the program with external logic that might be loading more stock, or performing some other function.
M73 Wait for PLC handshake input to go active
Similar to M72, this pauses until the PLC line goes to the active state. With either of these two codes, the user can press
Code letters:
N Line number
F Feedrate
I Interpolation parameter, 1st axis; or infeed parameter
J Interpolation parameter, 2nd axis
K Thread lead parameter (not yet implemented)
T Tool offset
R Arc radius; or release plane
S Spindle speed parameter
D,L,H,Q Future Use
# Timer or subroutine parameter