CNC-2022.  Description of the supported G- and M- codes.            Latest change:  2021-10-31


General:
The syntax and de meaning of the used codes is as much in accordance with the Standard RS274, which can be found here:

             https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=823374


Syntax of a G-code file:
A G-code file must have the extension .ngc or .txt.
It must be a human readable text file. (There exists a type of non human readable G-code files, this is not supported)
On one line there may be only one G- or M- code, with the exception of G2, G3, G17, G18, G19. See there.
This machne is not case sensitive. (relaxation of the Standard which allows only UPPERCASE)
A line may have spaces anywhere. They are removed by the preprocessor.
There may be ASCII control characters (< 32 decimal). These are removed too.
A line which begins with one of the characters % ; # * ( / $  is treated as comment.
The same characters may apear after a G- or M- code. The remainder of the line is then regarded as comment.
A line which starts with { turns all lines following into comment, until a line starting with } is found.
The decimal separation character can be either a dot or a comma.
There may be no thousands separation characters. This is not tested for, but it may lead to a crash or misinterpretation.
Any number may be given with decimals. Where decimals are not appropriate they will be removed, not rounded off.
E- notation for numbers  (e.g. 12345E-3 for 12.345) is not supported and may lead to a crash or misinterpretation.
If a G-code gives more than one target value for the same axis, only the first one is honored.
Line numbers (Nxxxxx) are accepted, but they must be the first on a line.
Line numbers don't need to be consecutive, but this has no influence on the order in which the lines are processed.
Line numbers may have decimals. Only the first two are kept for possible error reports
If there is an error the report it will contain the line number if possible.


Axis and Directions:
This machine has the following axis: X, Y, Z, R and E.
X is the longest axis of the machine, Y the movement over the bridge, Z is vertical.
X, Y and Z are linear movements. R is typically a rotation table, and E is an extra motor which can be used for several purposes.
E is for Extra, not for Extruder. The E-axis is treated the same as the R- axis, that is modulo 360 degrees.
If you are standing in front of the short side of the machine the directions are as follows.
X is positive from you, and negative towards you.
Y is positive to the right, negative to the left.
Z is positive up, negative is down.
E- and R-axis are flexible. The rotation direction and scale can be set in the Diagnose Menu 2.
The R-axis defaults to 360 degrees rotation of the Vertex rotating table with a 90:1 transmission.
The E-axis defaults to 360 degrees for one motor axis revolution.


Ranges:
X: 1225 mm.
Y: 520 mm.
Z: 250 mm.
Note: these are the distances between hitting endswitches. Practical use should not approach the endswitches closer than say 10 mm.

Suppoerted codes:

Code
Functie
Beperkingen / bijzonderheden
G0 [X, Y, Z, R, E, F]
Movement without cutting
F is Feedrate
There must be at least one parameter
On successive G0 lines "G0" may be omitted.
The value of Feedrate is kept, even if other feedrates for G1, G2 or G3 were given.
Control of the Highspeed Spindle Motor must be done with the codes M3, M4, c.q. M5.
G0 does not switch off the cutting tool.

G1 [X, Y, Z, R, E, F] Movement without cutting
F is Feedrate
There must be at least one parameter
On successive G1 lines "G1" may be omitted.
The value of Feedrate is kept, even if an other feedrate for G0, was given. 
Control of the Highspeed Spindle Motor must be done with the codes M3, M4, c.q. M5.
G2 [X, Y, Z, I, J, K, R, E, F, Q] Arc or complete circle CW
See the treatment of G2 and G3 codes.
There may be a G17, G18 of G19 code on the same line.
The F- parameter is modal like that of the G1 code.
The Q- parameter gives the number of segments for a whole circle.
Control of the High Speed Spindle Motor must be done with the codes M3, M4, c.q. M5.
G3 [X, Y, Z, I, J, K, R, E, F, Q] Arc or complete circle CCW See the treatment of G2 and G3 codes.
There may be a G17, G18 of G19 code on the same line.
The F- parameter is modal like that of the G1 code.
The Q- parameter gives the number of segments for a whole circle.
Control of the High Speed Spindle Motor must be done with the codes M3, M4, c.q. M5.
G4 Pxxx
Wait P seconden
P negative is infinite dwell time
Typically to let something cool down, heat up, or for a tool change.
With an infinite dwell time the button STOP DWELLING on the GUI will blink.
With a programmed dwell time that button does not blink, but the dwelling can be stopped.
N.B. There is no support for for compensation of a changed tool length or diameter.

G17  (default)
Select X-Y plane for arc or circle
There may be a G2 or G3 code on the same line.
G18
Select X-Z plane for arc or circle There may be a G2 or G3 code on the same line.
G19
SelectY-Z plane for arc or circle There may be a G2 or G3 code on the same line.



Parameters:


X xxx.xx,
Y xxx.xx,
Z xxx.xx
with xxx.xx as Target Position in mm

R xxx.xx, E xxx.xx, with xxx.xx as Target Position in degrees. The Target Position is interpreted modulo 360 degrees.
The movement takes the shortest way.
With negative values a multiple of 360 degrees is added to get a positive value between 0 and 359.999. (including)
Fxxx.xx
The Feedrate in
mm / minute or
degrees / minute
F may not be negative.
Sxxx.xx
In M3 and M4 the Spindle speed in RPM.

In M6xx: 1 =ON, 0 =OFF.
In M7xx: See there.
Spindle Speed is only valid for the High Speed Spindle, no other tools can be controlled with this code.


Pxxx.xx
In G4:  the dwell time in seconds

Qxxx.xx
The number of segments for a circle or arc.
The value is for a whole circle, even if if only a partial arc is to be done.
Decimals are truncated.
The value must be 3 or greater.
Default = 50. A very high number results in a long processing time.
Nxxxx.xx
Line number
Must be the first on a line.



Standard M codes:


M3 Sxxxxx
Start High Speed Spindle CW
Sxxx = rpm
And wait until the spindle is on speed.
S may not be negative.
S minimum is 1000, maximum is 30000.

M4 Sxxxxx
StartHigh Speed Spindle CCW
Sxxx = rpm
And wait until the spindle is on speed.
S may not be negative.
S minimum is 1000, maximum is 30000.
M5
Stop Spindel
And wait until the spindle has stopped



Non-Standaard M-codes:

M601 S0 / S1
Aux Tool 1 ON / OFF
e.g. a tool repalcing the High Speed Spindle motor.
M602 S0 / S1 Aux Tool 2 OFFt / ON e.g. een vacuum cleaner.



M701 Sxxx
Set Data Direction for the digital I/O's on the Feature Connector
xxx = 0..255, binary interpretation of the 8 I/O's.
For inputs the internal pull-up's are not automatically activated.
M702 Sxxx
Set Outputs for the digital I/O's on the Feature Connector xxx = 0..255, binary interpretation of the 8 I/O's.
A 1 given for an input turns on the internal pull-up resistor.
M703 Xxx, Yxx, Zxx
Set xx as PWM for the outputs A, B en C on the Feature Connector.

PWM A, B and C phase correct PWM signals with a resulution of 10 bit and a frequency of 7812 Hz.
There must be at least one parameter.
xx = 0 .. 1023
No change for parameters not given.
M709
Report analog and digitale I/O's.
Report in comma separated text file "M709.txt" .
M714 S0 / S1
Switch illumination ON / OFF
For photography
M715 S0 / S1
Switch the camera contact ON / OFF For photography. In general there must be a G4 between an M715 S1 en M715 S0



Op demand ....

We can implement additional M- codes.


About Arcs and Circles:
RS274 lists two methods of specifying arcs and circles, the Radius Format and the Center Format.
We support only the Center Format, because the radius format has problems with arcs forming nearly complete circles.
In this format the endpoint of the arc is specified as absolute (X ,Y) while the center of the arc is specified as (I, J) relative to the starting point or the current position. This is for arcs in the XY plane. For curves in the YZ plane replace (X, Y) by (Y, Z) and (I, J) by (J, K). For the XZ plane replace (X, Y) by (X, Z) and (I, J) by (I, K).
It is an error if the distance from the center to the current position differs from the distance between the center and the end position by more than 0.02 mm.
It is an error if the used (I, J, K) parameters do not correspond to the plane selected by G17, G18, G19.
If the out-of-plane axis is also specified to move the result will be a helical track.
Specifying arcs in any plane can be combined with movements of R and E, but the result may be tricky to interprete.
Many G-code generating software suites do not use G2 or G3 at all. They form arcs or circles as a sequence of linear tracks by themselves.


The following codes and features are deliberately NOT supported:
G20, G21 (inch / mm). We always work in millimeters and degrees.
G28:  As "Home" command (goto end switch) During the execution of a job one should not change the co÷rdinate system.
Many G-code generating software packages generate an pre-ambule with homing commands. These must be removed from the file.
G28:  As "Goto the zero position" is not supported either. Typically this is for the situation where a new workpiece is (automatically) mounted to repeat the same job. Automatic workpiece changing is not supported and re-zeroing can be done with existing supported commands.
Keep in mind that it is generally wise to first bring the Z-axis up before moving X or Y.
G53 .. G89 (several presets and canned cycles, cutter radius and length compensation, etc).
G90, G91 Absolute or incremental distances. We always work with absolute distances (G90)
% sign or M0, M1, M2, M30, M60 for start and end of a job is not madatory and is not supported. % indicates a comment line.
The T parameter for a tool change. This machine has no facilities for automatic tool change.
Canonical Machine Functions (Whatever that may be. See RS274).
Inline calculations, temporary variables, multi-file jobs.