This is an old revision of the document!
Important note: This manual describes several M and G codes which are relevant for the use of the Cyborg engraving machines.
The controller which we use handles a lot of other M and G codes, useful for other types of machinery, such as 3d-printers, plasma cutters, etc.
The codes which are of no use for an engraver without toolchanger are not described in this manual.
This chapter describes the input language, RS274/NGC.
The RS274/NGC language is based on lines of code. Each line (also called a “block”) may include commands to a machining center to do several different things. Lines of code may be collected in a file to make a program.
A typical line of code consists of an optional line number at the beginning followed by one or more “words.” A word consists of a letter followed by a number (or something that evaluates to a number).
A word may either give a command or provide an argument to a command. For example, “G1 X3” is a valid line of code with two words.
“G1” is a command meaning “move in a straight line at the programmed feed rate,” and “X3” provides an argument value (the value of X should be 3 at the end of the move).
Most RS274/NGC commands start with either G or M (for miscellaneous). The words for these commands are called “G codes” and “M codes.”
The RS274/NGC language has no indicator for the start of a program. The RS274/NGC language has two commands (M2 or M30), either of which ends a program.
A permissible line of input RS274/NGC code consists of the following, in order, with the restriction that there is a maximum (currently 256) to the number of characters allowed on a line.
• An optional line number.
• Any number of words, parameter settings, and comments.
Any input not explicitly allowed is illegal and will cause the Interpreter to signal an error.
Spaces and tabs are allowed anywhere on a line of code and do not change the meaning of the line, except inside comments.
This makes some strange-looking input legal. The line “g0x +0. 12 34y 7” is equivalent to “g0 x+0.1234 y7”, for example.
Blank lines are allowed in the input. They are to be ignored.
Input is case insensitive.
A line number is the letter N followed by an integer (with no sign) between 0 and 99999 written with no more than five digits (000009 is not OK, for example).
Line numbers may be repeated or used out of order, although normal practice is to avoid such usage.
Line numbers may also be skipped, and that is normal practice. A line number is not required to be used, but must be in the proper place if used.
A word is a letter other than N followed by a real value.
Words may begin with any of the letters shown in Table 3-2. The table includes N for completeness, even though, as defined above, line numbers are not words.
Several letters (I, J, K, L, P, and R) may have different meanings in different contexts.
| D | Tool radius compensation number |
| F | Feed rate |
| G | Genral function |
| H | Tool length offset index |
| I | X-axis offset for arcs X offset in G87 canned cycle |
| J | Y-axis offset for arcs Y offset in G87 canned cycle |
| K | Z-axis offset for arcs Z offset in G87 canned cycle |
| L | number of repetitions in canned cycles key used with G10 |
| M | miscellaneous function (see Table 3-6) |
| N | line number |
| P | dwell time in canned cycles dwell time with G4 key used with G10 |
| Q | feed increment in G83 canned cycle |
| R | arc radius, clear_z distance in canned cycle |
| S | Spindle speed |
| T | tool selection |
| X | X-axis of machine |
| Y | Y-axis of machine |
| Z | Z-axis of machine |
| A | A-axis of machine |
| B | B-axis of machine |
| C | C-axis of machine |
The following rules are used for (explicit) numbers. In these rules a digit is a single character between 0 and 9.
• A number consists of (1) an optional plus or minus sign, followed by (2) zero to many digits, followed, possibly, by (3) one decimal point, followed by (4) zero to many digits - provided that there is at least one digit somewhere in the number
• There are two kinds of numbers: integers and decimals. An integer does not have a decimal point in it; a decimal does.
• Numbers may have any number of digits, subject to the limitation on line length. Only about seventeen significant figures will be retained, however (enough for all known applications).
• A non-zero number with no sign as the first character is assumed to be positive.
Notice that initial (before the decimal point and the first non-zero digit) and trailing (after the decimal point and the last non-zero digit) zeros are allowed but not required.
A number written with initial or trailing zeros will have the same value when it is read as if the extra zeros were not there.
Numbers used for specific purposes in RS274/NGC are often restricted to some finite set of values or some to some range of values.
In many uses, decimal numbers must be close to integers; this includes the values of indexes (for parameters and carousel slot numbers, for example), M codes, and G codes multiplied by ten.
A decimal number which is supposed be close to an integer is considered close enough if it is within 0.0001 of an integer.
Printable characters and white space inside parentheses is a comment. A left parenthesis always starts a comment. The comment ends at the first right parenthesis found thereafter.
Once a left parenthesis is placed on a line, a matching right parenthesis must appear before the end of the line. Comments may not be nested; it is an error if a left parenthesis is found after the start of a comment and before the end of the comment.
Here’s an example of a line containing a comment: “G80 M5 (stop motion)”. Comments do not cause a machining center to do anything.
A comment contains a message if “MSG,” appears after the left parenthesis and before any other printing characters. Variants of “MSG,” which include white space and lower case characters are allowed.
The rest of the characters before the right parenthesis are considered to be a message. Messages should be displayed on the message display device. Comments not containing messages need not be displayed there.
A line may have any number of G words, but two G words from the same modal group may not appear on the same line.
A line may have zero to four M words. Two M words from the same modal group may not appear on the same line.
For all other legal letters, a line may have only one word beginning with that letter.
In RS274/NGC, many commands cause a machining center to change from one mode to another, and the mode stays active until some other command changes it implicitly or explicitly.
Such commands are called “modal”. For example, if coolant is turned on, it stays on until it is explicitly turned off. The G codes for motion are also modal.
If a G1 (straight move) command is given on one line, for example, it will be executed again on the next line if one or more axis words are available on the line, unless an explicit command is given on that next line using the axis words or cancelling motion.
“Non-modal” codes have effect only on the lines on which they occur. For example, G4 (dwell) is non-modal.
Modal commands are arranged in sets called “modal groups”, and only one member of a modal group may be in force at any given time.
In general, a modal group contains commands for which it is logically impossible for two members to be in effect at the same time - like measure in inches vs. measure in millimeters.
A machining center may be in many modes at the same time, with one mode from each modal group being in effect. The modal groups are shown in the following table.
Modal Groups The modal groups for G codes are:
| group 1 | {G0, G1, G2, G3, G38.2, G76, G80, G81, G82, G83, G84, G85, G86, G87, G88, G89} motion |
| group 2 | {G17, G18, G19} plane selection |
| group 3 | {G90, G91} distance mode |
| group 5 | {G93, G94} feed rate mode |
| group 6 | {G20, G21} units |
| group 7 | {G40, G41, G42} cutter radius compensation |
| group 8 | {G43, G49} tool length offset |
| group 10 | {G98, G99} return mode in canned cycles |
| group 12 | {G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3} coordinate system selection |
| group 13 | {G61, G61.1, G64} path control mode |
| group 14 | {G68, G69} XY plane rotation. |
The modal groups for M codes are:
| group 4 | {M0, M1, M2, M30, M60} stopping |
| group 5 | {54, M55, M56, M64, M65, M66} AUX and general purpose I/O |
| group 6 | {M6} tool change |
| group 7 | {M3, M4, M5} spindle turning |
| group 8 | {M7, M8, M9} coolant (special case: M7 and M8 may be active at the same time) |
| group 9 | {M48, M49, M50, M51, M52} enable/disable feed and speed override switches |
| group 10 | {M90, M91, M92, M95, M97} select standard or alternate spindle or touch probe or camera offset, M90=standard. |
| Enable THC = {M20, M21} THC ON\\THC OFF (Torch height control) A axis clamp = {M26, M27} Clamp on\\clamp off. | |
| In addition to the above modal groups, there is a group for non-modal G codes: | |
| group 0 | {G4, G10, G28, G30, G53, G92, G92.1, G92.2, G92.3} |
Continue to the table of contents.