Closed giannissc closed 1 year ago
G-code (also RS-274) is the most widely-used computer numerical control (CNC) programming language. It is used mainly in computer-aided manufacturing to control automated machine tools, as well as from a 3D-printing slicer app. Here we concentrate on a subset of G-code relevant for 3-axis CNC machining. Explanations of commands that are out of scope will be included for completeness and it will be indicated that they are out of scope.
A G-code command (word address) is formed by single letter (letter address) followed by 2 digits. Multiple G-code commands on the same line are called command blocks
G 01 XYZ
⌊ ⌋ letter address
⌊ ⌋ word address
⌊ ⌋ command block
G-code word addresses are used to configure the machine state and control the motors. The two primary letter addresses are M-codes and G-codes. M-codes are known as machine codes (or more accurately miscellaneous codes) and G-codes are called preparatory codes. M-codes allow for state changes of the machine components and the running program. G-codes control the motion of the motors and the internal configuration of the machine. In addition to the G and M address there are other letter addresses that are used in conjunction with them
Below is a comprehensive list of the available letter addresses:
inch: 4 fractional positions mm: 3 fractional positions
G-code commands can be categorized as modal or non-modal. Modal commands remain in effect until they are replaced or cancelled by another command. Non-modal commands execute in their block scope. M-code and G-code are further organized into modal groups
G-code Modal Groups:
M-code Modal Groups:
Letter Address Order: N G X Y Z R P Q I J K F M S T
Word Address Groups:
G-code Command Formats:
G00 X<inch/mm> Y<inch/mm> Z<inch/mm>
G01 X<inch/mm> Y<inch/mm> Z<inch/mm> F<inch/mm>
G02 X<inch/mm> Y<inch/mm> Z<inch/mm> I<inch/mm> J<inch/mm> K<inch/mm> F<inch/mm> (preferred)
R<inch/mm> F<inch/mm>
G98 G81 X<inch/mm> Y<inch/mm> Z<inch/mm> R<inch/mm> F<inch/mm>
G99 G82 P<0.001-1000.0>
G83
G84
G85
G86
G87
G88
G89
spindle
->speed
common.py
->groups.py
address.py
withXYZ
andIJK
classes moveprint_xyz()
andprint_ijk()
GCodeEnum
->GCodeAddress
GCodeEnum.to_gcode()
->GCodeEnum.__repr__()
andGCodeEnum._str_()
precision
parameter and choose precision based on selected Unit addressclass FeedRate(GCodeEnum)
and createprint_feed()