RWC

Ray West (Consultancy)

    The G-Code Interpreter

DeskCNC supports the following G and M Codes

G0 rapid positioning

G1 linear interpolation

G2 circular (clockwise XY Plane Only)

G3 circular (counterclockwise XY Plane Only)

G4 Dwell

G10 coordinate system origin setting

G17 xy plane selection

G20 inch system selection

G21 millimeter system selection

G40 cancel cutter diameter compensation

G41 start cutter diameter compensation left

G42 start cutter diameter compensation right

G43 tool length offset (plus)

G49 cancel tool length offset

G53 motion in machine coordinate system

G54 use preset work coordinate system 1

G55 use preset work coordinate system 2

G56 use preset work coordinate system 3

G57 use preset work coordinate system 4

G80 cancel motion mode (including any canned cycle)

G81 drilling canned cycle

G83 chip-breaking drilling canned cycle

G85 boring, no dwell, feed out canned cycle

G86 boring, spindle stop, rapid out canned cycle

G87 back boring canned cycle

G88 boring, spindle stop, manual out canned cycle

G90 absolute distance mode

G91 incremental distance mode

G92 offset coordinate systems

G92.2 cancel offset coordinate systems

G93 inverse time feed mode

G94 feed per minute mode

G98 initial level return in canned cycles

G99 R-point level return in canned cycles

M0 program stop

M1 optional program stop

M2 program end

M3 Spindle on Clockwise

M4 Spindle on Counter Clockwise

M5 Spindle Off

M6 tool change

M7 Mist Coolant On

M8 Flood Coolant On

M9 Coolant Off

It is not my intention to explain in detail the above codes, but hopefully I can give you enough information to get you over the initial stages of manually editing the g-code (.dnc) files that Deskcnc uses in its machining process. There is plenty of detailed information available on the Internet or elsewhere, and the best way for you to learn is by experimenting in altering your existing code or producing new.

A common way of producing g-codes within Deskcnc is by inputting a dxf or other drawing file. The resulting codes may need editing, in particular if you have appended a number of files, so it is essential that you have at least a basic understanding of g-codes.

Each line of code is to be considered as a block. This block contains at least one letter followed by a numeric field which refers to the value to be assigned to that letter or function. Comments can be added and are enclosed in brackets. You can relatively easily write correctly formatted g-codes, or edit existing g- codes with a standard ASCII text editor, such as windows notepad.

Spaces or tabs are ignored, but their use increases readability. Blank lines are also ignored. The code is case insensitive, upper or lower case characters are translated the same. If you append a number of files, you will find that the machining stops when it hits the first M2, so you will probably want to delete these from the files, (leave the last one, however) and possible the preceding and following G0 x0 y0 z0 blocks or whatever.

Line numbers begin with an N. Within deskcnc this line number is not referred to or otherwise used, but it helps you to trace errors or edit the code, or track the machining process (Note that the line highlighted in the small edit window at the bottom of the machine screen is not the line being machined at the moment.)

Many codes are modal, that means they are active until they are changed, even outside of their block. For example the line of code g01 Z-5.00 will set the z axis to -5.00. Subsequent moves such as g01 x5 y25.44 will move the cutter from where it was to x5, y25.44 at a depth of 5.00. (It is usual to set the top surface of the workpiece as Z0, thus any cutting into the work will be given by negative Z values.)

The feed rate is also modal, and like other commands it applies to its current block and subsequent ones. Thus G01 x5.0 f150 will move the cutter at a speed of 150 to a new position at x5.0 subsequent g01 moves will be at the same speed, until another 'f' value is entered. Feed rate does not apply to G00 moves, of course.

For circular moves, G2 and G3, as well as the X,Y end of arc coordinates there will either be an I and J value, or an R value. The example below demonstrates this use. I, J is the distance from the start of the arc to the centre, or R is the radius.

N10 G00 z2.00

N20 G00 x20 y20

N30 G01 z-5 f200

N40 G02 x30 y10 I0 J-10 f300

N50 G00 z2.00

This will move the cutter above the work surface, then go to x20, y20 at rapid speed, then feed down at a rate of 200, cut a clockwise arc of radius 10 ( centred on x20,y10) to a position x30,y10 at a feed rate of 300 then raise the cutter to clear the work piece again. The line N40 could also be written as N40 G02 x30 y10 r10 f300.

M6 will normally stop the machine to allow a tool change. You can write your own macro code to move the tool to the appropriate position, (see the software help documentation). The results of M commands for coolant are brought out to terminals on the controller board, and you can use relays or whatever to switch coolant on or off, or use these commands to control other functions.

The modal drilling canned cycle is entered in the form

G81 x10 y10 z-15 r-10 f75

X20 y20

X30 y30

G80

G00 z2

This will drill three holes, at x10,y10 x20,y20 x30,y30 to a depth of 15. The r value is the start depth of drilling, so the above code would apply to a surface which had already been milled out to a depth of more than 10 (assuming surface was at z0.) The feed rate (75) will only apply to the drill macro, and the machine will revert to the previously feed rate setting after the holes have been drilled

G83 is the chip breaking version, it will withdraw the drill to clear swarf, and is useful for deep holes. The code looks like

G83 x10 y10 z-25 r1 q4 f75

This is similar to code G81, except it will withdraw the cutter every 4 units of drilling, i.e. It will go to x10,y10,z1 then go to z-3, withdraw, go to z-6, withdraw, go to z-10, withdraw, and so on. This is often referred to as 'pecking', for obvious birdlike reasons.

Remember to cancel the canned cycles with code G80.

It is suggested that you experiment with the codes that you are likely to use, so that you gain a full understanding of how your machine behaves. It is simple to write fragments of code, or alter existing code with the editor, in the machine mode, and immediately test the effect by running the code. The results can be seen on screen, provided the controller board is powered up, you need waste no material in testing.