diff --git a/PythonicGcodeMachine/Gcode/Fanuc/__init__.py b/PythonicGcodeMachine/Gcode/Fanuc/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..37fdd45a0d6bed35fad763c9e5dbb87020fe76cb --- /dev/null +++ b/PythonicGcodeMachine/Gcode/Fanuc/__init__.py @@ -0,0 +1,384 @@ +#################################################################################################### +# +# PythonicGcodeMachine - @licence_header_description@ +# Copyright (C) 2018 Fabrice Salvaire +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +#################################################################################################### + +"""Module to implement the G-code language. + +History +------- + +The G-code language, also called RS-274, is a programming language for numerical control. It was +developed by the EIA in the early 1960s, and finally standardised by ISO in February 1980 as RS274D +/ ISO 6983. + +The G-code language has several flavours and historical versions. A list of reference documents +follows : + +* The NIST RS274NGC Interpreter - Version 3, T. Kramer, F. Proctor, E. Messina, National Institute + of Standards and Technology, NISTIR 6556, August 17, 2000 +* The documentation of the `Linux CNC `_ project, formerly Enhanced Machine + Controller developed at NIST, +* EIA Standard RS-274-D Interchangeable Variable Block Data Format for Positioning, Contouring, and + Contouring/Positioning Numerically Controlled Machines, 2001 Eye Street, NW, Washington, + D.C. 20006: Electronic Industries Association, February 1979 + +Overview +-------- + +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. + +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, +:code:`G1 X3` is a valid line of code with two words. :code:`G1` is a command meaning “move in a +straight line at the programmed feed rate,” and :code:`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.” + +Language View of a Machining Center +----------------------------------- + +Parameters +~~~~~~~~~~ + +In the RS274/NGC language view, a machining center maintains an array of 5400 numerical +parameters. Many of them have specific uses. The parameter array should persist over time, even if +the machining center is powered down. + +Coordinate Systems +~~~~~~~~~~~~~~~~~~ + +In the RS274/NGC language view, a machining center has an absolute coordinate system and nine +program coordinate systems. + +You can set the offsets of the nine program coordinate systems using G10 L2 Pn (n is the number of +the coordinate system) with values for the axes in terms of the absolute coordinate system. + +You can select one of the nine systems by using G54, G55, G56, G57, G58, G59, G59.1, G59.2, or +G59.3. It is not possible to select the absolute coordinate system directly. You can offset the +current coordinate system using G92 or G92.3. This offset will then apply to all nine program +coordinate systems. This offset may be cancelled with G92.1 or G92.2. + +You can make straight moves in the absolute machine coordinate system by using G53 with either G0 or +G1. + +Data for coordinate systems is stored in parameters. + +During initialization, the coordinate system is selected that is specified by parameter 5220. A +value of 1 means the first coordinate system (the one G54 activates), a value of 2 means the second +coordinate system (the one G55 activates), and so on. It is an error for the value of parameter 5220 +to be anything but a whole number between one and nine. + +Format of a Line +---------------- + +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 block delete character, which is a slash :code:`/` . +#. an optional line number. +#. any number of words, parameter settings, and comments. +#. an end of line marker (carriage return or line feed or both). + +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 :code:`g0x +0. 12 34y +7` is equivalent to :code:`g0 x+0.1234 y7`, for example. + +Blank lines are allowed in the input. They are to be ignored. + +Input is case insensitive, except in comments, i.e., any letter outside a comment may be in upper or +lower case without changing the meaning of a line. + +Line Number +~~~~~~~~~~~ + +A line number is the letter :code:`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. + +Word +~~~~ + +A word is a letter other than :code:`N` followed by a real value. + +Words may begin with any of the letters shown in the following table. The table includes :code:`N` +for completeness, even though, as defined above, line numbers are not words. Several letters +(:code:`I`, :code:`J, K`, :code:`L`, :code:`P`, :code:`R`) may have different meanings in different +contexts. + +Table. Linux CNC Words and their meanings Letter + +====== ===================================================== +Letter Meaning +====== ===================================================== +A A axis of machine +B B axis of machine +C C axis of machine +D Tool radius compensation number +F Feed rate +G General function (See table Modal Groups) +H Tool length offset index +I X offset for arcs and G87 canned cycles +J Y offset for arcs and G87 canned cycles +K Z offset for arcs and G87 canned cycles. + Spindle-Motion Ratio for G33 synchronized movements. +L Generic parameter word for G10, M66 and others +M Miscellaneous function (See table Modal Groups) +N Line number +P Dwell time in canned cycles and with G4. + Key used with G10. +Q Feed increment in G73, G83 canned cycles +R Arc radius or canned cycle plane +S Spindle speed +T Tool selection +U U axis of machine +V V axis of machine +W W axis of machine +X X axis of machine +Y Y axis of machine +Z Z axis of machine +====== ===================================================== + +A real value is some collection of characters that can be processed to come up with a number. A real +value may be an explicit number (such as 341 or -0.8807), a parameter value, an expression, or a +unary operation value. + +Number +~~~~~ + +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. +* 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. + +Parameter Value +~~~~~~~~~~~~~~~ + +A parameter value is the pound character :code:`#` followed by a real value. The real value must +evaluate to an integer between 1 and 5399. The integer is a parameter number, and the value of the +parameter value is whatever number is stored in the numbered parameter. + +The :code:`#` character takes precedence over other operations, so that, for example, :code:`#1+2` +means the number found by adding 2 to the value of parameter 1, not the value found in parameter +3. Of course, :code:`#[1+2]` does mean the value found in parameter 3. The :code:`#` character may +be repeated; for example :code:`##2` means the value of the parameter whose index is the (integer) +value of parameter 2. + +Expressions and Binary Operations +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +An expression is a set of characters starting with a left bracket :code:`[` and ending with a +balancing right bracket :code:`]`. In between the brackets are numbers, parameter values, +mathematical operations, and other expressions. An expression may be evaluated to produce a +number. The expressions on a line are evaluated when the line is read, before anything on the line +is executed. An example of an expression is :code:`[ 1 + acos[0] - [#3 ** [4.0/2]]]`. + +Binary operations appear only inside expressions. Nine binary operations are defined. There are four +basic mathematical operations: addition :code:`+`, subtraction :code:`-`, multiplication :code:`*`, +and division :code:`/`. There are three logical operations: non-exclusive or :code:`OR`, exclusive +or :code:`XOR`, and logical and :code:`AND`. The eighth operation is the modulus operation +:code:`MOD`. The ninth operation is the “power” operation :code:`**` of raising the number on the +left of the operation to the power on the right. The binary operations are divided into three +groups. The first group is: power. The second group is: multiplication, division, and modulus. The +third group is: addition, subtraction, logical non- exclusive or, logical exclusive or, and logical +and. If operations are strung together (for example in the expression :code:`[2.0 / 3 * 1.5 - 5.5 / +11.0]`), operations in the first group are to be performed before operations in the second group and +operations in the second group before operations in the third group. If an expression contains more +than one operation from the same group (such as the first / and * in the example), the operation on +the left is performed first. Thus, the example is equivalent to: :code:`[((2.0 / 3) * 1.5) - (5.5 / +11.0)]`, which simplifies to :code:`[1.0 - 0.5]`, which is 0.5. + +The logical operations and modulus are to be performed on any real numbers, not just on integers. +The number zero is equivalent to logical false, and any non-zero number is equivalent to logical +true. + +Unary Operation Value +~~~~~~~~~~~~~~~~~~~~~ + +A unary operation value is either :code:`ATAN` followed by one expression divided by another +expression (for example :code:`ATAN[2]/[1+3]`) or any other unary operation name followed by an +expression (for example :code:`SIN[90]`). The unary operations are: :code:`ABS` (absolute value), +:code:`ACOS` (arc cosine), :code:`ASIN` (arc sine), :code:`ATAN` (arc tangent), :code:`COS` +(cosine), :code:`EXP` (e raised to the given power), :code:`FIX` (round down), :code:`FUP` (round +up), :code:`LN` (natural logarithm), :code:`ROUND` (round to the nearest whole number), :code:`SIN` +(sine), :code:`SQRT` (square root), and :code:`TAN` (tangent). Arguments to unary operations which +take angle measures (:code:`COS`, :code:`SIN`, and :code:`TAN`) are in degrees. Values returned by +unary operations which return angle measures (:code:`ACOS`, :code:`ASIN`, and :code:`ATAN`) are also +in degrees. + +The :code:`FIX` operation rounds towards the left (less positive or more negative) on a number line, +so that :code:`FIX[2.8] = 2` and :code:`FIX[-2.8] = -3`, for example. The :code:`FUP` operation +rounds towards the right (more positive or less negative) on a number line; :code:`FUP[2.8] = 3` and +:code:`FUP[-2.8] = -2`, for example. + +Parameter Setting +~~~~~~~~~~~~~~~~~ + +A parameter setting is the following four items one after the other: (1) a pound character +:code:`#`, (2) a real value which evaluates to an integer between 1 and 5399, (3) an equal sign +:code:`=`, and (4) a real value. For example :code:`#3 = 15` is a parameter setting meaning “set +parameter 3 to 15.” + +A parameter setting does not take effect until after all parameter values on the same line have +been found. For example, if parameter 3 has been previously set to 15 and the line :code:`#3=6 G1 +x#3` is interpreted, a straight move to a point where x equals 15 will occur and the value of +parameter 3 will be 6. + +Comments and Messages +~~~~~~~~~~~~~~~~~~~~~ + +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 is an example of a line containing a comment: +:code:`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. + +Item Repeats +~~~~~~~~~~~~ + +A line may have any number of :code:`G` words, but two :code:`G` words from the same modal group may +not appear on the same line. + +A line may have zero to four :code:`M` words. Two :code:`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. + +If a parameter setting of the same parameter is repeated on a line, :code:`#3=15 #3=6`, for example, +only the last setting will take effect. It is silly, but not illegal, to set the same parameter +twice on the same line. + +If more than one comment appears on a line, only the last one will be used; each of the other +comments will be read and its format will be checked, but it will be ignored thereafter. It is +expected that putting more than one comment on a line will be very rare. + +Item order +~~~~~~~~~~ + +The three types of item whose order may vary on a line (as given at the beginning of this section) +are word, parameter setting, and comment. Imagine that these three types of item are divided into +three groups by type. + +The first group (the words) may be reordered in any way without changing the meaning of the line. + +If the second group (the parameter settings) is reordered, there will be no change in the meaning of +the line unless the same parameter is set more than once. In this case, only the last setting of the +parameter will take effect. For example, after the line :code:`#3=15 #3=6` has been interpreted, the +value of parameter 3 will be 6. If the order is reversed to :code:`#3=6 #3=15` and the line is +interpreted, the value of parameter 3 will be 15. + +If the third group (the comments) contains more than one comment and is reordered, only the last +comment will be used. + +If each group is kept in order or reordered without changing the meaning of the line, then the three +groups may be interleaved in any way without changing the meaning of the line. For example, the line +:code:`g40 g1 #3=15 (foo) #4=-7.0` has five items and means exactly the same thing in any of the 120 +possible orders (such as :code:`#4=-7.0 g1 #3=15 g40 (foo)`) for the five items. + +Commands and Machine Modes +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +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 :code:`G` codes for motion are also modal. If a :code:`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 is +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, :code:`G4` (dwell) +is non-modal. + +Modal Groups +------------ + +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 Table 4. + +For several modal groups, when a machining center is ready to accept commands, one member of the +group must be in effect. There are default settings for these modal groups. When the machining +center is turned on or otherwise re-initialized, the default values are automatically in effect. + +Group 1, the first group on the table, is a group of :code:`G` codes for motion. One of these is +always in effect. That one is called the current motion mode. + +It is an error to put a G-code from group 1 and a G-code from group 0 on the same line if both of +them use axis words. If an axis word-using G-code from group 1 is implicitly in effect on a line (by +having been activated on an earlier line), and a group 0 G-code that uses axis words appears on the +line, the activity of the group 1 G-code is suspended for that line. The axis word-using G-codes +from group 0 are :code:`G10`, :code:`G28`, :code:`G30`, and :code:`G92`. + +G and Input Codes +----------------- + +See ... + +.. + G codes of the RS274/NGC language are shown in Table 5 and described following that. + + In the command prototypes, three dots (...) stand for a real value. As described earlier, a real + value may be (1) an explicit number, 4, for example, (2) an expression, :code:`[2+2]`, for example, + (3) a parameter value, #88, for example, or (4) a unary function value, :code:`acos[0]`, for + example. In most cases, if axis words (any or all of X..., Y..., Z..., A..., B..., C...) are given, + they specify a destination point. Axis numbers are in the currently active coordinate system, unless + explicitly described as being in the absolute coordinate system. Where axis words are optional, any + omitted axes will have their current value. Any items in the command prototypes not explicitly + described as optional are required. It is an error if a required item is omitted. + + In the prototypes, the values following letters are often given as explicit numbers. Unless stated + otherwise, the explicit numbers can be real values. For example, :code:`G10 L2` could equally well + be written :code:`G[2*5] L[1+1]`. If the value of parameter 100 were 2, :code:`G10 L#100` would also + mean the same. Using real values which are not explicit numbers as just shown in the examples is + rarely useful. + + If L... is written in a prototype the “...” will often be referred to as the “L number”. Similarly the + “...” in H... may be called the “H number”, and so on for any other letter. + +Order of Execution +------------------ + +The order of execution of items on a line is critical to safe and effective machine operation. Items +are executed in a particular order if they occur on the same line. + +""" diff --git a/PythonicGcodeMachine/Gcode/Fanuc/data/fanuc-gcodes-lathe.yaml b/PythonicGcodeMachine/Gcode/Fanuc/data/fanuc-gcodes-lathe.yaml new file mode 100644 index 0000000000000000000000000000000000000000..71c4370169cda210f6766c9bb6f3d783d3d36077 --- /dev/null +++ b/PythonicGcodeMachine/Gcode/Fanuc/data/fanuc-gcodes-lathe.yaml @@ -0,0 +1,106 @@ +F: + meaning: set feed rate +G00: + meaning: Rapid traverse +G01: + meaning: Linear interpolation +G02: + meaning: Circular interpolation CW +G03: + meaning: Circular interpolation CCW +G04: + meaning: Dwell +G09: + meaning: Exact stop +G10: + meaning: Programmable data input +G20: + meaning: Input in inch +G21: + meaning: Input in mm +G22: + meaning: Stored stroke check function ON +G23: + meaning: Stored stroke check function OFF +G27: + meaning: Reference position return check +G28: + meaning: Return to reference position +G32: + meaning: Thread cutting +G40: + meaning: Tool nose radius compensation cancel +G41: + meaning: Tool nose radius compensation left +G42: + meaning: Tool nose radius compensation right +G70: + meaning: Finish machining cycle +G71: + meaning: Turning cycle +G72: + meaning: Facing cycle +G73: + meaning: Pattern repeating cycle +G74: + meaning: Peck drilling cycle +G75: + meaning: Grooving cycle +G76: + meaning: Threading cycle +G92: + meaning: Coordinate system setting or max. spindle speed setting +G94: + meaning: Feed per minute +G95: + meaning: Feed per revolution +G96: + meaning: Constant surface speed control +G97: + meaning: Constant surface speed control cancel +M00: + meaning: Program stop +M01: + meaning: Optional program stop +M02: + meaning: End of program +M03: + meaning: Spindle start forward CW +M04: + meaning: Spindle start reverse CCW +M05: + meaning: Spindle stop +M08: + meaning: Coolant ON +M09: + meaning: Coolant OFF +M29: + meaning: Rigid tap mode +M30: + meaning: End of program reset +M40: + meaning: Spindle gear at middle +M41: + meaning: Low gear select +M42: + meaning: High gear select +M68: + meaning: Hydraulic chuck close +M69: + meaning: Hydraulic chuck open +M78: + meaning: Tailstock advancing +M79: + meaning: Tailstock reversing +M94: + meaning: Cancel mirror image +M95: + meaning: Mirror image of X axis +M98: + meaning: Subprogram call +M99: + meaning: End of subprogram +S: + meaning: set spindle speed +T: + meaning: select tool diff --git a/PythonicGcodeMachine/Gcode/Fanuc/data/fanuc-gcodes-mill.yaml b/PythonicGcodeMachine/Gcode/Fanuc/data/fanuc-gcodes-mill.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e4c1198a25c4d51f49af2e2e91603a8642ffa646 --- /dev/null +++ b/PythonicGcodeMachine/Gcode/Fanuc/data/fanuc-gcodes-mill.yaml @@ -0,0 +1,134 @@ +F: + meaning: set feed rate +G00: + meaning: Rapid traverse +G01: + meaning: Linear interpolation +G02: + meaning: Circular interpolation CW +G03: + meaning: Circular interpolation CCW +G04: + meaning: Dwell +G17: + meaning: X Y plane selection +G18: + meaning: Z X plane selection +G19: + meaning: Y Z plane selection +G28: + meaning: Return to reference position +G30: + meaning: 2nd, 3rd and 4th reference position return +G40: + meaning: Cutter compensation cancel +G41: + meaning: Cutter compensation left +G42: + meaning: Cutter compensation right +G43: + meaning: Tool length compensation + direction +G44: + meaning: Tool length compensation - direction +G49: + meaning: Tool length compensation cancel +G53: + meaning: Machine coordinate system selection +G54: + meaning: Workpiece coordinate system 1 selection +G55: + meaning: Workpiece coordinate system 2 selection +G56: + meaning: Workpiece coordinate system 3 selection +G57: + meaning: Workpiece coordinate system 4 selection +G58: + meaning: Workpiece coordinate system 5 selection +G59: + meaning: Workpiece coordinate system 6 selection +G68: + meaning: Coordinate rotation +G69: + meaning: Coordinate rotation cancel +G73: + meaning: Peck drilling cycle +G74: + meaning: Left-spiral cutting circle +G76: + meaning: Fine boring cycle +G80: + meaning: Canned cycle cancel +G81: + meaning: Drilling cycle, spot boring cycle +G82: + meaning: Drilling cycle or counter boring cycle +G83: + meaning: Peck drilling cycle +G84: + meaning: Tapping cycle +G85: + meaning: Boring cycle +G86: + meaning: Boring cycle +G87: + meaning: Back boring cycle +G88: + meaning: Boring cycle +G89: + meaning: Boring cycle +G90: + meaning: Absolute command +G91: + meaning: Increment command +G92: + meaning: Setting for work coordinate system or clamp at maximum spindle speed +G98: + meaning: Return to initial point in canned cycle +G99: + meaning: Return to R point in canned cycle +M00: + meaning: Program stop +M01: + meaning: Optional program stop +M02: + meaning: End of program +M03: + meaning: Spindle start forward CW +M04: + meaning: Spindle start reverse CCW +M05: + meaning: Spindle stop +M06: + meaning: Tool change +M07: + meaning: Coolant ON – Mist coolant/Coolant thru spindle +M08: + meaning: Coolant ON – Flood coolant +M09: + meaning: Coolant OFF +M19: + meaning: Spindle orientation +M28: + meaning: Return to origin +M29: + meaning: Rigid tap mode +M30: + meaning: End of program (Reset) +M41: + meaning: Low gear select +M42: + meaning: High gear select +M94: + meaning: Cancel mirror image +M95: + meaning: Mirror image of X axis +M96: + meaning: Mirror image of Y axis +M98: + meaning: Subprogram call +M99: + meaning: End of subprogram +S: + meaning: set spindle speed +T: + meaning: select tool diff --git a/PythonicGcodeMachine/Gcode/Heidenhain/__init__.py b/PythonicGcodeMachine/Gcode/Heidenhain/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..37fdd45a0d6bed35fad763c9e5dbb87020fe76cb --- /dev/null +++ b/PythonicGcodeMachine/Gcode/Heidenhain/__init__.py @@ -0,0 +1,384 @@ +#################################################################################################### +# +# PythonicGcodeMachine - @licence_header_description@ +# Copyright (C) 2018 Fabrice Salvaire +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +#################################################################################################### + +"""Module to implement the G-code language. + +History +------- + +The G-code language, also called RS-274, is a programming language for numerical control. It was +developed by the EIA in the early 1960s, and finally standardised by ISO in February 1980 as RS274D +/ ISO 6983. + +The G-code language has several flavours and historical versions. A list of reference documents +follows : + +* The NIST RS274NGC Interpreter - Version 3, T. Kramer, F. Proctor, E. Messina, National Institute + of Standards and Technology, NISTIR 6556, August 17, 2000 +* The documentation of the `Linux CNC `_ project, formerly Enhanced Machine + Controller developed at NIST, +* EIA Standard RS-274-D Interchangeable Variable Block Data Format for Positioning, Contouring, and + Contouring/Positioning Numerically Controlled Machines, 2001 Eye Street, NW, Washington, + D.C. 20006: Electronic Industries Association, February 1979 + +Overview +-------- + +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. + +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, +:code:`G1 X3` is a valid line of code with two words. :code:`G1` is a command meaning “move in a +straight line at the programmed feed rate,” and :code:`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.” + +Language View of a Machining Center +----------------------------------- + +Parameters +~~~~~~~~~~ + +In the RS274/NGC language view, a machining center maintains an array of 5400 numerical +parameters. Many of them have specific uses. The parameter array should persist over time, even if +the machining center is powered down. + +Coordinate Systems +~~~~~~~~~~~~~~~~~~ + +In the RS274/NGC language view, a machining center has an absolute coordinate system and nine +program coordinate systems. + +You can set the offsets of the nine program coordinate systems using G10 L2 Pn (n is the number of +the coordinate system) with values for the axes in terms of the absolute coordinate system. + +You can select one of the nine systems by using G54, G55, G56, G57, G58, G59, G59.1, G59.2, or +G59.3. It is not possible to select the absolute coordinate system directly. You can offset the +current coordinate system using G92 or G92.3. This offset will then apply to all nine program +coordinate systems. This offset may be cancelled with G92.1 or G92.2. + +You can make straight moves in the absolute machine coordinate system by using G53 with either G0 or +G1. + +Data for coordinate systems is stored in parameters. + +During initialization, the coordinate system is selected that is specified by parameter 5220. A +value of 1 means the first coordinate system (the one G54 activates), a value of 2 means the second +coordinate system (the one G55 activates), and so on. It is an error for the value of parameter 5220 +to be anything but a whole number between one and nine. + +Format of a Line +---------------- + +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 block delete character, which is a slash :code:`/` . +#. an optional line number. +#. any number of words, parameter settings, and comments. +#. an end of line marker (carriage return or line feed or both). + +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 :code:`g0x +0. 12 34y +7` is equivalent to :code:`g0 x+0.1234 y7`, for example. + +Blank lines are allowed in the input. They are to be ignored. + +Input is case insensitive, except in comments, i.e., any letter outside a comment may be in upper or +lower case without changing the meaning of a line. + +Line Number +~~~~~~~~~~~ + +A line number is the letter :code:`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. + +Word +~~~~ + +A word is a letter other than :code:`N` followed by a real value. + +Words may begin with any of the letters shown in the following table. The table includes :code:`N` +for completeness, even though, as defined above, line numbers are not words. Several letters +(:code:`I`, :code:`J, K`, :code:`L`, :code:`P`, :code:`R`) may have different meanings in different +contexts. + +Table. Linux CNC Words and their meanings Letter + +====== ===================================================== +Letter Meaning +====== ===================================================== +A A axis of machine +B B axis of machine +C C axis of machine +D Tool radius compensation number +F Feed rate +G General function (See table Modal Groups) +H Tool length offset index +I X offset for arcs and G87 canned cycles +J Y offset for arcs and G87 canned cycles +K Z offset for arcs and G87 canned cycles. + Spindle-Motion Ratio for G33 synchronized movements. +L Generic parameter word for G10, M66 and others +M Miscellaneous function (See table Modal Groups) +N Line number +P Dwell time in canned cycles and with G4. + Key used with G10. +Q Feed increment in G73, G83 canned cycles +R Arc radius or canned cycle plane +S Spindle speed +T Tool selection +U U axis of machine +V V axis of machine +W W axis of machine +X X axis of machine +Y Y axis of machine +Z Z axis of machine +====== ===================================================== + +A real value is some collection of characters that can be processed to come up with a number. A real +value may be an explicit number (such as 341 or -0.8807), a parameter value, an expression, or a +unary operation value. + +Number +~~~~~ + +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. +* 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. + +Parameter Value +~~~~~~~~~~~~~~~ + +A parameter value is the pound character :code:`#` followed by a real value. The real value must +evaluate to an integer between 1 and 5399. The integer is a parameter number, and the value of the +parameter value is whatever number is stored in the numbered parameter. + +The :code:`#` character takes precedence over other operations, so that, for example, :code:`#1+2` +means the number found by adding 2 to the value of parameter 1, not the value found in parameter +3. Of course, :code:`#[1+2]` does mean the value found in parameter 3. The :code:`#` character may +be repeated; for example :code:`##2` means the value of the parameter whose index is the (integer) +value of parameter 2. + +Expressions and Binary Operations +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +An expression is a set of characters starting with a left bracket :code:`[` and ending with a +balancing right bracket :code:`]`. In between the brackets are numbers, parameter values, +mathematical operations, and other expressions. An expression may be evaluated to produce a +number. The expressions on a line are evaluated when the line is read, before anything on the line +is executed. An example of an expression is :code:`[ 1 + acos[0] - [#3 ** [4.0/2]]]`. + +Binary operations appear only inside expressions. Nine binary operations are defined. There are four +basic mathematical operations: addition :code:`+`, subtraction :code:`-`, multiplication :code:`*`, +and division :code:`/`. There are three logical operations: non-exclusive or :code:`OR`, exclusive +or :code:`XOR`, and logical and :code:`AND`. The eighth operation is the modulus operation +:code:`MOD`. The ninth operation is the “power” operation :code:`**` of raising the number on the +left of the operation to the power on the right. The binary operations are divided into three +groups. The first group is: power. The second group is: multiplication, division, and modulus. The +third group is: addition, subtraction, logical non- exclusive or, logical exclusive or, and logical +and. If operations are strung together (for example in the expression :code:`[2.0 / 3 * 1.5 - 5.5 / +11.0]`), operations in the first group are to be performed before operations in the second group and +operations in the second group before operations in the third group. If an expression contains more +than one operation from the same group (such as the first / and * in the example), the operation on +the left is performed first. Thus, the example is equivalent to: :code:`[((2.0 / 3) * 1.5) - (5.5 / +11.0)]`, which simplifies to :code:`[1.0 - 0.5]`, which is 0.5. + +The logical operations and modulus are to be performed on any real numbers, not just on integers. +The number zero is equivalent to logical false, and any non-zero number is equivalent to logical +true. + +Unary Operation Value +~~~~~~~~~~~~~~~~~~~~~ + +A unary operation value is either :code:`ATAN` followed by one expression divided by another +expression (for example :code:`ATAN[2]/[1+3]`) or any other unary operation name followed by an +expression (for example :code:`SIN[90]`). The unary operations are: :code:`ABS` (absolute value), +:code:`ACOS` (arc cosine), :code:`ASIN` (arc sine), :code:`ATAN` (arc tangent), :code:`COS` +(cosine), :code:`EXP` (e raised to the given power), :code:`FIX` (round down), :code:`FUP` (round +up), :code:`LN` (natural logarithm), :code:`ROUND` (round to the nearest whole number), :code:`SIN` +(sine), :code:`SQRT` (square root), and :code:`TAN` (tangent). Arguments to unary operations which +take angle measures (:code:`COS`, :code:`SIN`, and :code:`TAN`) are in degrees. Values returned by +unary operations which return angle measures (:code:`ACOS`, :code:`ASIN`, and :code:`ATAN`) are also +in degrees. + +The :code:`FIX` operation rounds towards the left (less positive or more negative) on a number line, +so that :code:`FIX[2.8] = 2` and :code:`FIX[-2.8] = -3`, for example. The :code:`FUP` operation +rounds towards the right (more positive or less negative) on a number line; :code:`FUP[2.8] = 3` and +:code:`FUP[-2.8] = -2`, for example. + +Parameter Setting +~~~~~~~~~~~~~~~~~ + +A parameter setting is the following four items one after the other: (1) a pound character +:code:`#`, (2) a real value which evaluates to an integer between 1 and 5399, (3) an equal sign +:code:`=`, and (4) a real value. For example :code:`#3 = 15` is a parameter setting meaning “set +parameter 3 to 15.” + +A parameter setting does not take effect until after all parameter values on the same line have +been found. For example, if parameter 3 has been previously set to 15 and the line :code:`#3=6 G1 +x#3` is interpreted, a straight move to a point where x equals 15 will occur and the value of +parameter 3 will be 6. + +Comments and Messages +~~~~~~~~~~~~~~~~~~~~~ + +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 is an example of a line containing a comment: +:code:`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. + +Item Repeats +~~~~~~~~~~~~ + +A line may have any number of :code:`G` words, but two :code:`G` words from the same modal group may +not appear on the same line. + +A line may have zero to four :code:`M` words. Two :code:`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. + +If a parameter setting of the same parameter is repeated on a line, :code:`#3=15 #3=6`, for example, +only the last setting will take effect. It is silly, but not illegal, to set the same parameter +twice on the same line. + +If more than one comment appears on a line, only the last one will be used; each of the other +comments will be read and its format will be checked, but it will be ignored thereafter. It is +expected that putting more than one comment on a line will be very rare. + +Item order +~~~~~~~~~~ + +The three types of item whose order may vary on a line (as given at the beginning of this section) +are word, parameter setting, and comment. Imagine that these three types of item are divided into +three groups by type. + +The first group (the words) may be reordered in any way without changing the meaning of the line. + +If the second group (the parameter settings) is reordered, there will be no change in the meaning of +the line unless the same parameter is set more than once. In this case, only the last setting of the +parameter will take effect. For example, after the line :code:`#3=15 #3=6` has been interpreted, the +value of parameter 3 will be 6. If the order is reversed to :code:`#3=6 #3=15` and the line is +interpreted, the value of parameter 3 will be 15. + +If the third group (the comments) contains more than one comment and is reordered, only the last +comment will be used. + +If each group is kept in order or reordered without changing the meaning of the line, then the three +groups may be interleaved in any way without changing the meaning of the line. For example, the line +:code:`g40 g1 #3=15 (foo) #4=-7.0` has five items and means exactly the same thing in any of the 120 +possible orders (such as :code:`#4=-7.0 g1 #3=15 g40 (foo)`) for the five items. + +Commands and Machine Modes +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +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 :code:`G` codes for motion are also modal. If a :code:`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 is +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, :code:`G4` (dwell) +is non-modal. + +Modal Groups +------------ + +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 Table 4. + +For several modal groups, when a machining center is ready to accept commands, one member of the +group must be in effect. There are default settings for these modal groups. When the machining +center is turned on or otherwise re-initialized, the default values are automatically in effect. + +Group 1, the first group on the table, is a group of :code:`G` codes for motion. One of these is +always in effect. That one is called the current motion mode. + +It is an error to put a G-code from group 1 and a G-code from group 0 on the same line if both of +them use axis words. If an axis word-using G-code from group 1 is implicitly in effect on a line (by +having been activated on an earlier line), and a group 0 G-code that uses axis words appears on the +line, the activity of the group 1 G-code is suspended for that line. The axis word-using G-codes +from group 0 are :code:`G10`, :code:`G28`, :code:`G30`, and :code:`G92`. + +G and Input Codes +----------------- + +See ... + +.. + G codes of the RS274/NGC language are shown in Table 5 and described following that. + + In the command prototypes, three dots (...) stand for a real value. As described earlier, a real + value may be (1) an explicit number, 4, for example, (2) an expression, :code:`[2+2]`, for example, + (3) a parameter value, #88, for example, or (4) a unary function value, :code:`acos[0]`, for + example. In most cases, if axis words (any or all of X..., Y..., Z..., A..., B..., C...) are given, + they specify a destination point. Axis numbers are in the currently active coordinate system, unless + explicitly described as being in the absolute coordinate system. Where axis words are optional, any + omitted axes will have their current value. Any items in the command prototypes not explicitly + described as optional are required. It is an error if a required item is omitted. + + In the prototypes, the values following letters are often given as explicit numbers. Unless stated + otherwise, the explicit numbers can be real values. For example, :code:`G10 L2` could equally well + be written :code:`G[2*5] L[1+1]`. If the value of parameter 100 were 2, :code:`G10 L#100` would also + mean the same. Using real values which are not explicit numbers as just shown in the examples is + rarely useful. + + If L... is written in a prototype the “...” will often be referred to as the “L number”. Similarly the + “...” in H... may be called the “H number”, and so on for any other letter. + +Order of Execution +------------------ + +The order of execution of items on a line is critical to safe and effective machine operation. Items +are executed in a particular order if they occur on the same line. + +""" diff --git a/PythonicGcodeMachine/Gcode/Heidenhain/data/heidenhain-TNC-426-mcodes.yaml b/PythonicGcodeMachine/Gcode/Heidenhain/data/heidenhain-TNC-426-mcodes.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ea4160dae65546fdf758f8752e45747a25b2a5f5 --- /dev/null +++ b/PythonicGcodeMachine/Gcode/Heidenhain/data/heidenhain-TNC-426-mcodes.yaml @@ -0,0 +1,38 @@ +M0: + meaning: Program stop +M1: + meaning: Optional stop (program stop only with opt. stop) +M2: + meaning: Program end +M3: + meaning: Spindle ON clockwise +M4: + meaning: Spindle ON counterclockwise +M5: + meaning: Spindle Stop +M6: + meaning: Tool change +M8: + meaning: Coolant ON +M9: + meaning: Coolant OFF +M10: + meaning: Dividing head, clamping ON +M11: + meaning: Dividing head, clamping OFF +M17: + meaning: End of subprogram +M25: + meaning: Open clamp/ machine vice +M26: + meaning: Close clamp/ machine vice +M27: + meaning: Swivel dividing head +M30: + meaning: Main program end +M71: + meaning: Puff blowing device ON +M72: + meaning: Puff blowing device OFF +M99: + meaning: Cycle call diff --git a/PythonicGcodeMachine/Gcode/Heidenhain/data/heidenhain-gcodes.yaml b/PythonicGcodeMachine/Gcode/Heidenhain/data/heidenhain-gcodes.yaml new file mode 100644 index 0000000000000000000000000000000000000000..456523fdd8bb89fd202a3be6a7e2de2cfe100871 --- /dev/null +++ b/PythonicGcodeMachine/Gcode/Heidenhain/data/heidenhain-gcodes.yaml @@ -0,0 +1,473 @@ +F: + meaning: set feed rate +# Tool movements +G00: + meaning: Straight-line interpolation, Cartesian coordinates, rapid traverse +G01: + meaning: Straight-line interpolation, Cartesian coordinates +G02: + meaning: Circular interpolation, Cartesian coordinates, clockwise +G03: + meaning: Circular interpolation, Cartesian coordinates, counterclockwise +G05: + meaning: Circular interpolation, Cartesian coordinates, without indication of direction +G06: + meaning: Circular interpolation, Cartesian coordinates, tangential contour approach +G07: + meaning: Paraxial positioning block +G10: + meaning: Straight-line interpolation, polar coordinates, rapid traverse +G11: + meaning: Straight-line interpolation, polar coordinates +G12: + meaning: Circular interpolation, polar coordinates, clockwise +G13: + meaning: Circular interpolation, polar coordinates, counterclockwise +G15: + meaning: Circular interpolation, polar coordinates, without indication of direction +G16: + meaning: Circular interpolation, polar coordinates, tangential contour approach +# Chamfer/Rounding/Approach contour/Depart contour +G24: + meaning: Chamfer with length R +G25: + meaning: Corner rounding with radius R +G26: + meaning: Tangential contour approach with radius R +G27: + meaning: Tangential contour approach with radius R +# Tool definition +G99: + meaning: With tool number T, length L, radius R +# Tool radius compensation +G40: + meaning: No tool radius compensation +G41: + meaning: Tool radius compensation, left of the contour +G42: + meaning: Tool radius compensation, right of the contour +G43: + meaning: Paraxial compensation for G07, lengthening +G44: + meaning: Paraxial compensation for G07, shortening +# Blank form definition for graphics +G30: + meaning: (G17/G18/G19) min. point +G31: + meaning: (G90/G91) max. point +# Cycles for drilling, tapping and thread milling +G83: + meaning: Pecking +G84: + meaning: Tapping with a floating tap holder +G85: + meaning: Rigid tapping +G86: + meaning: Thread cutting +G200: + meaning: Drilling +G201: + meaning: Reaming +G202: + meaning: Boring +G203: + meaning: Universal drilling +G204: + meaning: Back boring +G205: + meaning: Universal pecking +G206: + meaning: Tapping with a floating tap holder +G207: + meaning: Rigid tapping +G208: + meaning: Bore milling +G209: + meaning: Tapping with chip breaking +Cycles for creating point patterns +# G220: + meaning: Circular pattern +G221: + meaning: Linear pattern +SL Cycles, group 1 +# G37: + meaning: Contour geometry, list of subcontour program numbers +G56: + meaning: Pilot drilling +G57: + meaning: Rough-out +G58: + meaning: Contour milling in clockwise direction (finishing) +G59: + meaning: Contour milling, counterclockwise (finishing) +# SL cycles, group 2 +G37: + meaning: Contour geometry, list of subcontour program numbers +G120: + meaning: Contour data (applies to G121 to G124) +G121: + meaning: Pilot drilling +G122: + meaning: Rough-out +G123: + meaning: Floor finishing +G124: + meaning: Side finishing +G125: + meaning: Contour train (machining open contour) +G127: + meaning: Cylinder surface +G128: + meaning: Cylindrical surface slot +# Coordinate transformation +G53: + meaning: Datum shift in datum table +G54: + meaning: Datum shift in program +G28: + meaning: Mirror image +G73: + meaning: Rotation of the coordinate system +G72: + meaning: Scaling factor (reduce or enlarge contour) +G80: + meaning: Tilting the working plane +G247: + meaning: Datum setting +# Cycles for multipass milling +G60: + meaning: Run 3-D data +G230: + meaning: Multipass milling of plane surfaces +G231: + meaning: Multipass milling of tilted surfaces +G232: + meaning: Face milling +# Special cycles +G04: + meaning: Dwell time with F seconds +G36: + meaning: Spindle orientation +G39: + meaning: Program call +G62: + meaning: Tolerance deviation for fast contour milling +G440: + meaning: Measure axis shift +G441: + meaning: Fast probing +# Define machining plane +G17: + meaning: Working plane X/Y, tool axis Z +G18: + meaning: Working plane Z/X, tool axis Y +G19: + meaning: Working plane Y/Z, tool axis X +G20: + meaning: Tool axis IV +# Dimensions +G90: + meaning: Absolute dimensions +G91: + meaning: Incremental dimensions +# Unit of measure +G70: + meaning: Inches (set at start of program) +G71: + meaning: Millimeters (set at start of program) +# Other G functions +G29: + meaning: Transfer the last nominal position value as a pole (circle center) +G38: + meaning: STOP program run +G51: + meaning: Next tool number (with central tool file) +G79: + meaning: Cycle call +G98: + meaning: Set label number +# Cycles for drilling, tapping and thread milling +G240: + meaning: Centering +G200: + meaning: Drilling +G201: + meaning: Reaming +G202: + meaning: Boring +G203: + meaning: Universal drilling +G204: + meaning: Back boring +G205: + meaning: Universal pecking +G206: + meaning: Tapping with a floating tap holder +G207: + meaning: Rigid tapping +G208: + meaning: Bore milling +G209: + meaning: Tapping with chip breaking +G241: + meaning: Single-lip deep-hole drilling +# Cycles for drilling, tapping and thread milling +G262: + meaning: Thread milling +G263: + meaning: Thread milling/countersinking +G264: + meaning: Thread drilling/milling +G265: + meaning: Helical thread drilling/milling +G267: + meaning: External thread milling +# Cycles for milling pockets, studs and slots +G74: + meaning: Slot milling +G75: + meaning: Rectangular pocket milling in clockwise direction +G76: + meaning: Rectangular pocket milling in counterclockwise direction +G77: + meaning: Circular pocket milling in clockwise direction +G78: + meaning: Circular pocket milling in counterclockwise direction +G210: + meaning: Slot milling with reciprocating plunge +G211: + meaning: Round slot with reciprocating plunge +G212: + meaning: Rectangular pocket finishing +G213: + meaning: Rectangular stud finishing +G214: + meaning: Circular pocket finishing +G215: + meaning: Circular stud finishing +# Cycles for milling pockets, studs and slots +G251: + meaning: Rectangular pocket, complete +G252: + meaning: Circular pocket, complete +G253: + meaning: Slot, complete +G254: + meaning: Circular slot, complete +G256: + meaning: Rectangular stud +G257: + meaning: Circular stud +# Cycles for creating point patterns +G220: + meaning: Circular point pattern +G221: + meaning: Point patterns on lines +# Cycles for multipass milling +G230: + meaning: Multipass milling of smooth surfaces +G231: + meaning: Multipass milling of tilted surfaces +G232: + meaning: Face milling +# Touch probe cycles for measuring workpiece misalignment +G400: + meaning: Basic rotation using two points +G401: + meaning: Basic rotation from two holes +G402: + meaning: Basic rotation from two studs +G403: + meaning: Compensate a basic rotation via a rotary axis +G404: + meaning: Set basic rotation +G405: + meaning: Compensating misalignment with the C axis +# Touch probe cycles for datum setting +G408: + meaning: Slot center reference point +G409: + meaning: Reference point at center of hole +G410: + meaning: Datum from inside of rectangle +G411: + meaning: Datum from outside of rectangle +G412: + meaning: Datum from inside of circle +G413: + meaning: Datum from outside of circle +G414: + meaning: Datum in outside corner +G415: + meaning: Datum in inside corner +G416: + meaning: Datum circle center +G417: + meaning: Datum in touch probe axis +G418: + meaning: Datum in center of 4 holes +G419: + meaning: Reference point in selectable axis +# Touch probe cycles for workpiece measurement +G55: + meaning: Measure any coordinate +G420: + meaning: Measure any angle +G421: + meaning: Measure hole +G422: + meaning: Measure cylindrical stud +G423: + meaning: Measure rectangular pocket +G424: + meaning: Measure rectangular stud +G425: + meaning: Measure slot +G426: + meaning: Measure ridge +G427: + meaning: Measure any coordinate +G430: + meaning: Measure circle center +G431: + meaning: Measure any plane +# Touch probe cycles for tool measurement +G480: + meaning: Calibrating the TT +G481: + meaning: Measure tool length +G482: + meaning: Measure tool radius +G483: + meaning: Measure tool length and tool radius +# +M0: + meaning: Stop program run (Spindle STOP, Coolant OFF) +M1: + meaning: Optional program STOP (Spindle STOP, Coolant OFF) +M2: + meaning: Stop program run (Spindle STOP,Coolant OFF,Go to block 1,Clear the status display(depending on machine parameter)) +M3: + meaning: Spindle ON clockwise +M4: + meaning: Spindle ON counterclockwise +M5: + meaning: Spindle STOP +M6: + meaning: Tool change (STOP program run (depending on machine parameter),Spindle STOP) +M8: + meaning: Coolant ON +M9: + meaning: Coolant OFF +M13: + meaning: Spindle ON clockwise (Coolant ON) +M14: + meaning: Spindle ON counterclockwise (Coolant ON) +M30: + meaning: Same as M2 +M89: + meaning: Vacant miscellaneous function or Cycle call, modally effective (depending on machine parameter) +M91: + meaning: Within the positioning block: Coordinates are referenced to machine datum +M92: + meaning: Within the positioning block: Coordinates are referenced to position defined by machine tool builder, such as tool change position +M94: + meaning: Reduce the rotary axis display to a value below 360° +M97: + meaning: Machine small contour steps +M98: + meaning: Machine open contours completely +M99: + meaning: Blockwise cycle call (Cycle call, NON-MODAL) +M101: + meaning: Automatic tool change with replacement tool if maximum tool life has expired +M102: + meaning: Reset M101 +M103: + meaning: Reduce feed rate during plunging to factor F (percentage) +M104: + meaning: Reactivate the datum as last defined +M105: + meaning: Machining with second kv factor +M106: + meaning: Machining with first kv factor +M107: + meaning: Suppress error message for replacement tools with oversize +M108: + meaning: Reset M107 +M109: + meaning: Constant contouring speed at tool cutting edge (increase and decrease feed rate) +M110: + meaning: Constant contouring speed at tool cutting edge (feed rate decrease only) +M111: + meaning: Reset M109/M110 +M112: + meaning: Enter contour transition between two contour elements +M113: + meaning: Reset M112 +M114: + meaning: Automatic compensation of machine geometry when working with tilted axes +M115: + meaning: Reset M114 +M116: + meaning: Feed rate for rotary axes in mm/min +M117: + meaning: Reset M116 +M118: + meaning: Superimpose handwheel positioning during program run +M120: + meaning: Pre-calculate radius-compensated contour (LOOK AHEAD) +M124: + meaning: Contour filter +M126: + meaning: Shortest-path traverse of rotary axes +M127: + meaning: Reset M126 +M128: + meaning: Retain the position of the tool tip when positioning the tilted axes (TCPM) +M129: + meaning: Reset M128 +M130: + meaning: Moving to position in an untilted coordinate system with a tilted working plane +M134: + meaning: Exact stop at nontangential contour transitions when positioning with rotary axes +M135: + meaning: Reset M134 +M136: + meaning: Feed rate F in millimeters per spindle revolution +M137: + meaning: Reset M136 +M138: + meaning: Selection of tilted axes +M140: + meaning: Retraction from the contour in the tool-axis direction +M141: + meaning: Suppress touch probe monitoring +M142: + meaning: Delete modal program information +M143: + meaning: Delete basic rotation +M144: + meaning: Compensating the machine’s kinematics configuration for ACTUAL/NOMINAL positions at end of block +M145: + meaning: Reset M144 +M148: + meaning: Retract the tool automatically from the contour at NC stop +M149: + meaning: Reset M148 +M150: + meaning: Suppress limit switch message +M200: + meaning: Laser cutting: Output programmed voltage directly +M201: + meaning: Laser cutting: Output voltage as a function of distance +M202: + meaning: Laser cutting: Output voltage as a function of speed +M203: + meaning: Laser cutting: Output voltage as a function of time (ramp) +M204: + meaning: Laser cutting: Output voltage as a function of time (pulse) +S: + meaning: set spindle speed +T: + meaning: select tool diff --git a/PythonicGcodeMachine/Gcode/LinuxCnc/__init__.py b/PythonicGcodeMachine/Gcode/LinuxCnc/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..37fdd45a0d6bed35fad763c9e5dbb87020fe76cb --- /dev/null +++ b/PythonicGcodeMachine/Gcode/LinuxCnc/__init__.py @@ -0,0 +1,384 @@ +#################################################################################################### +# +# PythonicGcodeMachine - @licence_header_description@ +# Copyright (C) 2018 Fabrice Salvaire +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +#################################################################################################### + +"""Module to implement the G-code language. + +History +------- + +The G-code language, also called RS-274, is a programming language for numerical control. It was +developed by the EIA in the early 1960s, and finally standardised by ISO in February 1980 as RS274D +/ ISO 6983. + +The G-code language has several flavours and historical versions. A list of reference documents +follows : + +* The NIST RS274NGC Interpreter - Version 3, T. Kramer, F. Proctor, E. Messina, National Institute + of Standards and Technology, NISTIR 6556, August 17, 2000 +* The documentation of the `Linux CNC `_ project, formerly Enhanced Machine + Controller developed at NIST, +* EIA Standard RS-274-D Interchangeable Variable Block Data Format for Positioning, Contouring, and + Contouring/Positioning Numerically Controlled Machines, 2001 Eye Street, NW, Washington, + D.C. 20006: Electronic Industries Association, February 1979 + +Overview +-------- + +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. + +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, +:code:`G1 X3` is a valid line of code with two words. :code:`G1` is a command meaning “move in a +straight line at the programmed feed rate,” and :code:`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.” + +Language View of a Machining Center +----------------------------------- + +Parameters +~~~~~~~~~~ + +In the RS274/NGC language view, a machining center maintains an array of 5400 numerical +parameters. Many of them have specific uses. The parameter array should persist over time, even if +the machining center is powered down. + +Coordinate Systems +~~~~~~~~~~~~~~~~~~ + +In the RS274/NGC language view, a machining center has an absolute coordinate system and nine +program coordinate systems. + +You can set the offsets of the nine program coordinate systems using G10 L2 Pn (n is the number of +the coordinate system) with values for the axes in terms of the absolute coordinate system. + +You can select one of the nine systems by using G54, G55, G56, G57, G58, G59, G59.1, G59.2, or +G59.3. It is not possible to select the absolute coordinate system directly. You can offset the +current coordinate system using G92 or G92.3. This offset will then apply to all nine program +coordinate systems. This offset may be cancelled with G92.1 or G92.2. + +You can make straight moves in the absolute machine coordinate system by using G53 with either G0 or +G1. + +Data for coordinate systems is stored in parameters. + +During initialization, the coordinate system is selected that is specified by parameter 5220. A +value of 1 means the first coordinate system (the one G54 activates), a value of 2 means the second +coordinate system (the one G55 activates), and so on. It is an error for the value of parameter 5220 +to be anything but a whole number between one and nine. + +Format of a Line +---------------- + +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 block delete character, which is a slash :code:`/` . +#. an optional line number. +#. any number of words, parameter settings, and comments. +#. an end of line marker (carriage return or line feed or both). + +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 :code:`g0x +0. 12 34y +7` is equivalent to :code:`g0 x+0.1234 y7`, for example. + +Blank lines are allowed in the input. They are to be ignored. + +Input is case insensitive, except in comments, i.e., any letter outside a comment may be in upper or +lower case without changing the meaning of a line. + +Line Number +~~~~~~~~~~~ + +A line number is the letter :code:`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. + +Word +~~~~ + +A word is a letter other than :code:`N` followed by a real value. + +Words may begin with any of the letters shown in the following table. The table includes :code:`N` +for completeness, even though, as defined above, line numbers are not words. Several letters +(:code:`I`, :code:`J, K`, :code:`L`, :code:`P`, :code:`R`) may have different meanings in different +contexts. + +Table. Linux CNC Words and their meanings Letter + +====== ===================================================== +Letter Meaning +====== ===================================================== +A A axis of machine +B B axis of machine +C C axis of machine +D Tool radius compensation number +F Feed rate +G General function (See table Modal Groups) +H Tool length offset index +I X offset for arcs and G87 canned cycles +J Y offset for arcs and G87 canned cycles +K Z offset for arcs and G87 canned cycles. + Spindle-Motion Ratio for G33 synchronized movements. +L Generic parameter word for G10, M66 and others +M Miscellaneous function (See table Modal Groups) +N Line number +P Dwell time in canned cycles and with G4. + Key used with G10. +Q Feed increment in G73, G83 canned cycles +R Arc radius or canned cycle plane +S Spindle speed +T Tool selection +U U axis of machine +V V axis of machine +W W axis of machine +X X axis of machine +Y Y axis of machine +Z Z axis of machine +====== ===================================================== + +A real value is some collection of characters that can be processed to come up with a number. A real +value may be an explicit number (such as 341 or -0.8807), a parameter value, an expression, or a +unary operation value. + +Number +~~~~~ + +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. +* 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. + +Parameter Value +~~~~~~~~~~~~~~~ + +A parameter value is the pound character :code:`#` followed by a real value. The real value must +evaluate to an integer between 1 and 5399. The integer is a parameter number, and the value of the +parameter value is whatever number is stored in the numbered parameter. + +The :code:`#` character takes precedence over other operations, so that, for example, :code:`#1+2` +means the number found by adding 2 to the value of parameter 1, not the value found in parameter +3. Of course, :code:`#[1+2]` does mean the value found in parameter 3. The :code:`#` character may +be repeated; for example :code:`##2` means the value of the parameter whose index is the (integer) +value of parameter 2. + +Expressions and Binary Operations +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +An expression is a set of characters starting with a left bracket :code:`[` and ending with a +balancing right bracket :code:`]`. In between the brackets are numbers, parameter values, +mathematical operations, and other expressions. An expression may be evaluated to produce a +number. The expressions on a line are evaluated when the line is read, before anything on the line +is executed. An example of an expression is :code:`[ 1 + acos[0] - [#3 ** [4.0/2]]]`. + +Binary operations appear only inside expressions. Nine binary operations are defined. There are four +basic mathematical operations: addition :code:`+`, subtraction :code:`-`, multiplication :code:`*`, +and division :code:`/`. There are three logical operations: non-exclusive or :code:`OR`, exclusive +or :code:`XOR`, and logical and :code:`AND`. The eighth operation is the modulus operation +:code:`MOD`. The ninth operation is the “power” operation :code:`**` of raising the number on the +left of the operation to the power on the right. The binary operations are divided into three +groups. The first group is: power. The second group is: multiplication, division, and modulus. The +third group is: addition, subtraction, logical non- exclusive or, logical exclusive or, and logical +and. If operations are strung together (for example in the expression :code:`[2.0 / 3 * 1.5 - 5.5 / +11.0]`), operations in the first group are to be performed before operations in the second group and +operations in the second group before operations in the third group. If an expression contains more +than one operation from the same group (such as the first / and * in the example), the operation on +the left is performed first. Thus, the example is equivalent to: :code:`[((2.0 / 3) * 1.5) - (5.5 / +11.0)]`, which simplifies to :code:`[1.0 - 0.5]`, which is 0.5. + +The logical operations and modulus are to be performed on any real numbers, not just on integers. +The number zero is equivalent to logical false, and any non-zero number is equivalent to logical +true. + +Unary Operation Value +~~~~~~~~~~~~~~~~~~~~~ + +A unary operation value is either :code:`ATAN` followed by one expression divided by another +expression (for example :code:`ATAN[2]/[1+3]`) or any other unary operation name followed by an +expression (for example :code:`SIN[90]`). The unary operations are: :code:`ABS` (absolute value), +:code:`ACOS` (arc cosine), :code:`ASIN` (arc sine), :code:`ATAN` (arc tangent), :code:`COS` +(cosine), :code:`EXP` (e raised to the given power), :code:`FIX` (round down), :code:`FUP` (round +up), :code:`LN` (natural logarithm), :code:`ROUND` (round to the nearest whole number), :code:`SIN` +(sine), :code:`SQRT` (square root), and :code:`TAN` (tangent). Arguments to unary operations which +take angle measures (:code:`COS`, :code:`SIN`, and :code:`TAN`) are in degrees. Values returned by +unary operations which return angle measures (:code:`ACOS`, :code:`ASIN`, and :code:`ATAN`) are also +in degrees. + +The :code:`FIX` operation rounds towards the left (less positive or more negative) on a number line, +so that :code:`FIX[2.8] = 2` and :code:`FIX[-2.8] = -3`, for example. The :code:`FUP` operation +rounds towards the right (more positive or less negative) on a number line; :code:`FUP[2.8] = 3` and +:code:`FUP[-2.8] = -2`, for example. + +Parameter Setting +~~~~~~~~~~~~~~~~~ + +A parameter setting is the following four items one after the other: (1) a pound character +:code:`#`, (2) a real value which evaluates to an integer between 1 and 5399, (3) an equal sign +:code:`=`, and (4) a real value. For example :code:`#3 = 15` is a parameter setting meaning “set +parameter 3 to 15.” + +A parameter setting does not take effect until after all parameter values on the same line have +been found. For example, if parameter 3 has been previously set to 15 and the line :code:`#3=6 G1 +x#3` is interpreted, a straight move to a point where x equals 15 will occur and the value of +parameter 3 will be 6. + +Comments and Messages +~~~~~~~~~~~~~~~~~~~~~ + +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 is an example of a line containing a comment: +:code:`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. + +Item Repeats +~~~~~~~~~~~~ + +A line may have any number of :code:`G` words, but two :code:`G` words from the same modal group may +not appear on the same line. + +A line may have zero to four :code:`M` words. Two :code:`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. + +If a parameter setting of the same parameter is repeated on a line, :code:`#3=15 #3=6`, for example, +only the last setting will take effect. It is silly, but not illegal, to set the same parameter +twice on the same line. + +If more than one comment appears on a line, only the last one will be used; each of the other +comments will be read and its format will be checked, but it will be ignored thereafter. It is +expected that putting more than one comment on a line will be very rare. + +Item order +~~~~~~~~~~ + +The three types of item whose order may vary on a line (as given at the beginning of this section) +are word, parameter setting, and comment. Imagine that these three types of item are divided into +three groups by type. + +The first group (the words) may be reordered in any way without changing the meaning of the line. + +If the second group (the parameter settings) is reordered, there will be no change in the meaning of +the line unless the same parameter is set more than once. In this case, only the last setting of the +parameter will take effect. For example, after the line :code:`#3=15 #3=6` has been interpreted, the +value of parameter 3 will be 6. If the order is reversed to :code:`#3=6 #3=15` and the line is +interpreted, the value of parameter 3 will be 15. + +If the third group (the comments) contains more than one comment and is reordered, only the last +comment will be used. + +If each group is kept in order or reordered without changing the meaning of the line, then the three +groups may be interleaved in any way without changing the meaning of the line. For example, the line +:code:`g40 g1 #3=15 (foo) #4=-7.0` has five items and means exactly the same thing in any of the 120 +possible orders (such as :code:`#4=-7.0 g1 #3=15 g40 (foo)`) for the five items. + +Commands and Machine Modes +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +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 :code:`G` codes for motion are also modal. If a :code:`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 is +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, :code:`G4` (dwell) +is non-modal. + +Modal Groups +------------ + +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 Table 4. + +For several modal groups, when a machining center is ready to accept commands, one member of the +group must be in effect. There are default settings for these modal groups. When the machining +center is turned on or otherwise re-initialized, the default values are automatically in effect. + +Group 1, the first group on the table, is a group of :code:`G` codes for motion. One of these is +always in effect. That one is called the current motion mode. + +It is an error to put a G-code from group 1 and a G-code from group 0 on the same line if both of +them use axis words. If an axis word-using G-code from group 1 is implicitly in effect on a line (by +having been activated on an earlier line), and a group 0 G-code that uses axis words appears on the +line, the activity of the group 1 G-code is suspended for that line. The axis word-using G-codes +from group 0 are :code:`G10`, :code:`G28`, :code:`G30`, and :code:`G92`. + +G and Input Codes +----------------- + +See ... + +.. + G codes of the RS274/NGC language are shown in Table 5 and described following that. + + In the command prototypes, three dots (...) stand for a real value. As described earlier, a real + value may be (1) an explicit number, 4, for example, (2) an expression, :code:`[2+2]`, for example, + (3) a parameter value, #88, for example, or (4) a unary function value, :code:`acos[0]`, for + example. In most cases, if axis words (any or all of X..., Y..., Z..., A..., B..., C...) are given, + they specify a destination point. Axis numbers are in the currently active coordinate system, unless + explicitly described as being in the absolute coordinate system. Where axis words are optional, any + omitted axes will have their current value. Any items in the command prototypes not explicitly + described as optional are required. It is an error if a required item is omitted. + + In the prototypes, the values following letters are often given as explicit numbers. Unless stated + otherwise, the explicit numbers can be real values. For example, :code:`G10 L2` could equally well + be written :code:`G[2*5] L[1+1]`. If the value of parameter 100 were 2, :code:`G10 L#100` would also + mean the same. Using real values which are not explicit numbers as just shown in the examples is + rarely useful. + + If L... is written in a prototype the “...” will often be referred to as the “L number”. Similarly the + “...” in H... may be called the “H number”, and so on for any other letter. + +Order of Execution +------------------ + +The order of execution of items on a line is critical to safe and effective machine operation. Items +are executed in a particular order if they occur on the same line. + +""" diff --git a/PythonicGcodeMachine/Gcode/LinuxCnc/data/linuxcnc-gcodes.yaml b/PythonicGcodeMachine/Gcode/LinuxCnc/data/linuxcnc-gcodes.yaml new file mode 100644 index 0000000000000000000000000000000000000000..349ccb73ccab407db9ba41209e2023223d89f80c --- /dev/null +++ b/PythonicGcodeMachine/Gcode/LinuxCnc/data/linuxcnc-gcodes.yaml @@ -0,0 +1,287 @@ +# cf. http://linuxcnc.org/docs/2.7/html/gcode.html +F: + meaning: Set feed rate +# Motion (X Y Z A B C U V W apply to all motions) +G0: + meaning: Rapid Move +G1: + meaning: Linear Move +G23: + meaning: Arc Move + parameters: I J K or R, P +G3: + meaning: Arc Move + parameters: I J K or R, P +G4: + meaning: Dwell + parameters: P +G5: + meaning: Cubic Spline + parameters: I J P Q +G5.1: + meaning: Quadratic Spline + parameters: I J +G5.2: + meaning: NURBS + parameters: P L +G38.2: + meaning: Straight Probe +G38.3: + meaning: Straight Probe +G38.4: + meaning: Straight Probe +G38.5: + meaning: Straight Probe +G33: + meaning: Spindle Synchronized Motion + parameters: K +G33.1: + meaning: Rigid Tapping + parameters: K +G80: + meaning: Cancel Canned Cycle +# Canned cycles (X Y Z or U V W apply to canned cycles, depending on active plane) +G81: + meaning: Drilling Cycle + parameters: R L (P) +G82: + meaning: Drilling Cycle, Dwell + parameters: R L (P) +G83: + meaning: Drilling Cycle, Peck + parameters: R L Q +G73: + meaning: Drilling Cycle, Chip Breaking + parameters: R L Q +G85: + meaning: Boring Cycle, Feed Out + parameters: R L (P) +G89: + meaning: Boring Cycle, Dwell, Feed Out + parameters: R L (P) +G76: + meaning: Threading Cycle + parameters: P Z I J R K Q H L E +# Distance Mode +G90: + meaning: Distance Mode +G91: + meaning: Distance Mode +G90.1: + meaning: Arc Distance Mode +G91.1: + meaning: Arc Distance Mode +G7: + meaning: Lathe Diameter Mode +G8: + meaning: Lathe Radius Mode +# Feed Rate Mode +G93: + meaning: Feed Rate Mode +G94: + meaning: Feed Rate Mode +G95: + meaning: Feed Rate Mode +# Spindle Control +M3: + meaning: Spindle Control + parameters: S +M4: + meaning: Spindle Control + parameters: S +M5: + meaning: Spindle Control + parameters: S +M19: + meaning: Orient Spindle +G96: + meaning: Spindle Control Mode + parameters: S D +G97: + meaning: Spindle Control Mode + parameters: S D +# Coolant +M7: + meaning: Coolant Control +M8: + meaning: Coolant Control +M9: + meaning: Coolant Control +# Tool Length Offset +G43: + meaning: Tool Length Offset + parameters: H +G43.1: + meaning: Dynamic Tool Length Offset +G43.2: + meaning: Apply additional Tool Length Offset + parameters: H +G49: + meaning: Cancel Tool Length Compensation +# Stopping +M0: + meaning: Program Pause +M1: + meaning: Program Pause +M2: + meaning: Program End +M30: + meaning: Program End +M60: + meaning: Pallet Change Pause +# Units +G20: + meaning: Units (inch, mm) +G21: + meaning: Units (inch, mm) +# Plane Selection: (affects G2, G3, G81…G89, G40…G42) +G17: + meaning: Plane Select +G17.1: + meaning: Plane Select +G18: + meaning: Plane Select +G18.1: + meaning: Plane Select +G19: + meaning: Plane Select +G19.1: + meaning: Plane Select +# Cutter Radius Compensation +G40: + meaning: Compensation Off +G41: + meaning: Cutter Compensation + parameters: D +G42: + meaning: Cutter Compensation + parameters: D +G41.1: + meaning: Dynamic Cutter Compensation + parameters: D L +G42.1: + meaning: Dynamic Cutter Compensation + parameters: D L +# Path Control Mode +G61.1: + meaning: Exact Path Mode +G61.1: + meaning: Exact Path Mode +G64: + meaning: Path Blending + parameters: P Q +# Return Mode in Canned Cycles +G98: + meaning: Canned Cycle Return Level +G99: + meaning: Canned Cycle Return Level +# Other Modal Codes +F: + meaning: Set Feed Rate +S: + meaning: Set Spindle Speed +T: + meaning: Select Tool) +M48, M49: + meaning: Speed and Feed Override Control +M50: + meaning: Feed Override Control + parameters: P0 (off) or P1 (on) +M51: + meaning: Spindle Speed Override Control + parameters: P0 (off) or P1 (on) +M52: + meaning: Adaptive Feed Control + parameters: P0 (off) or P1 (on) +M53: + meaning: Feed Stop Control + parameters: P0 (off) or P1 (on) +G54-G59.3: + meaning: Select Coordinate System +# Flow-control Codes +## o sub: +## meaning: Subroutines, sub/endsub call +## o while: +## meaning: Looping, while/endwhile do/while +## o if: +## meaning: Conditional, if/else/endif +## o repeat: +## meaning: Repeat a loop of code +## '[]': +## meaning: Indirection +## o call: +## meaning: Call named file +M70: + meaning: Save modal state +M71: + meaning: Invalidate stored state +M72: + meaning: Restore modal state +M73: + meaning: Save and Auto-restore modal state +# Input/Output Codes +M62: + meaning: Digital Output Control +M63: + meaning: Digital Output Control +M64: + meaning: Digital Output Control +M65: + meaning: Digital Output Control + parameters: P +M66: + meaning: Wait on Input + parameters: P E L Q +M67: + meaning: Analog Output,Synchronized + parameters: T +M68: + meaning: Analog Output, Immediate + parameters: T +# Non-modal Codes +M6: + meaning: Tool Change + parameters: T +M61: + meaning: Set Current Too + l # Q +G10 L1: + meaning: Set Tool Table + parameters: P Q R +G10 L10: + meaning: Set Tool Table + parameters: P +G10 L11: + meaning: Set Tool Table + parameters: P +G10 L2: + meaning: Set Coordinate System + parameters: P R +G10 L20: + meaning: Set Coordinate System + parameters: P +G28: + meaning: Go/Set Predefined Position +G28.1: + meaning: Go/Set Predefined Position +G30: + meaning: Go/Set Predefined Position +G30.1: + meaning: Go/Set Predefined Position +G53: + meaning: Move in Machine Coordinates +G92: + meaning: Coordinate System Offset +G92.1: + meaning: Reset G92 Offsets +G92.2: + meaning: Reset G92 Offsets +G92.3: + meaning: Restore G92 Offsets +M101 - M199: # Don't expand ! + meaning: User Defined Commands + parameters: P Q +S: + meaning: Set spindle speed +T: + meaning: Select tool diff --git a/PythonicGcodeMachine/Gcode/MachineKit/__init__.py b/PythonicGcodeMachine/Gcode/MachineKit/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..37fdd45a0d6bed35fad763c9e5dbb87020fe76cb --- /dev/null +++ b/PythonicGcodeMachine/Gcode/MachineKit/__init__.py @@ -0,0 +1,384 @@ +#################################################################################################### +# +# PythonicGcodeMachine - @licence_header_description@ +# Copyright (C) 2018 Fabrice Salvaire +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +#################################################################################################### + +"""Module to implement the G-code language. + +History +------- + +The G-code language, also called RS-274, is a programming language for numerical control. It was +developed by the EIA in the early 1960s, and finally standardised by ISO in February 1980 as RS274D +/ ISO 6983. + +The G-code language has several flavours and historical versions. A list of reference documents +follows : + +* The NIST RS274NGC Interpreter - Version 3, T. Kramer, F. Proctor, E. Messina, National Institute + of Standards and Technology, NISTIR 6556, August 17, 2000 +* The documentation of the `Linux CNC `_ project, formerly Enhanced Machine + Controller developed at NIST, +* EIA Standard RS-274-D Interchangeable Variable Block Data Format for Positioning, Contouring, and + Contouring/Positioning Numerically Controlled Machines, 2001 Eye Street, NW, Washington, + D.C. 20006: Electronic Industries Association, February 1979 + +Overview +-------- + +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. + +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, +:code:`G1 X3` is a valid line of code with two words. :code:`G1` is a command meaning “move in a +straight line at the programmed feed rate,” and :code:`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.” + +Language View of a Machining Center +----------------------------------- + +Parameters +~~~~~~~~~~ + +In the RS274/NGC language view, a machining center maintains an array of 5400 numerical +parameters. Many of them have specific uses. The parameter array should persist over time, even if +the machining center is powered down. + +Coordinate Systems +~~~~~~~~~~~~~~~~~~ + +In the RS274/NGC language view, a machining center has an absolute coordinate system and nine +program coordinate systems. + +You can set the offsets of the nine program coordinate systems using G10 L2 Pn (n is the number of +the coordinate system) with values for the axes in terms of the absolute coordinate system. + +You can select one of the nine systems by using G54, G55, G56, G57, G58, G59, G59.1, G59.2, or +G59.3. It is not possible to select the absolute coordinate system directly. You can offset the +current coordinate system using G92 or G92.3. This offset will then apply to all nine program +coordinate systems. This offset may be cancelled with G92.1 or G92.2. + +You can make straight moves in the absolute machine coordinate system by using G53 with either G0 or +G1. + +Data for coordinate systems is stored in parameters. + +During initialization, the coordinate system is selected that is specified by parameter 5220. A +value of 1 means the first coordinate system (the one G54 activates), a value of 2 means the second +coordinate system (the one G55 activates), and so on. It is an error for the value of parameter 5220 +to be anything but a whole number between one and nine. + +Format of a Line +---------------- + +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 block delete character, which is a slash :code:`/` . +#. an optional line number. +#. any number of words, parameter settings, and comments. +#. an end of line marker (carriage return or line feed or both). + +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 :code:`g0x +0. 12 34y +7` is equivalent to :code:`g0 x+0.1234 y7`, for example. + +Blank lines are allowed in the input. They are to be ignored. + +Input is case insensitive, except in comments, i.e., any letter outside a comment may be in upper or +lower case without changing the meaning of a line. + +Line Number +~~~~~~~~~~~ + +A line number is the letter :code:`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. + +Word +~~~~ + +A word is a letter other than :code:`N` followed by a real value. + +Words may begin with any of the letters shown in the following table. The table includes :code:`N` +for completeness, even though, as defined above, line numbers are not words. Several letters +(:code:`I`, :code:`J, K`, :code:`L`, :code:`P`, :code:`R`) may have different meanings in different +contexts. + +Table. Linux CNC Words and their meanings Letter + +====== ===================================================== +Letter Meaning +====== ===================================================== +A A axis of machine +B B axis of machine +C C axis of machine +D Tool radius compensation number +F Feed rate +G General function (See table Modal Groups) +H Tool length offset index +I X offset for arcs and G87 canned cycles +J Y offset for arcs and G87 canned cycles +K Z offset for arcs and G87 canned cycles. + Spindle-Motion Ratio for G33 synchronized movements. +L Generic parameter word for G10, M66 and others +M Miscellaneous function (See table Modal Groups) +N Line number +P Dwell time in canned cycles and with G4. + Key used with G10. +Q Feed increment in G73, G83 canned cycles +R Arc radius or canned cycle plane +S Spindle speed +T Tool selection +U U axis of machine +V V axis of machine +W W axis of machine +X X axis of machine +Y Y axis of machine +Z Z axis of machine +====== ===================================================== + +A real value is some collection of characters that can be processed to come up with a number. A real +value may be an explicit number (such as 341 or -0.8807), a parameter value, an expression, or a +unary operation value. + +Number +~~~~~ + +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. +* 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. + +Parameter Value +~~~~~~~~~~~~~~~ + +A parameter value is the pound character :code:`#` followed by a real value. The real value must +evaluate to an integer between 1 and 5399. The integer is a parameter number, and the value of the +parameter value is whatever number is stored in the numbered parameter. + +The :code:`#` character takes precedence over other operations, so that, for example, :code:`#1+2` +means the number found by adding 2 to the value of parameter 1, not the value found in parameter +3. Of course, :code:`#[1+2]` does mean the value found in parameter 3. The :code:`#` character may +be repeated; for example :code:`##2` means the value of the parameter whose index is the (integer) +value of parameter 2. + +Expressions and Binary Operations +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +An expression is a set of characters starting with a left bracket :code:`[` and ending with a +balancing right bracket :code:`]`. In between the brackets are numbers, parameter values, +mathematical operations, and other expressions. An expression may be evaluated to produce a +number. The expressions on a line are evaluated when the line is read, before anything on the line +is executed. An example of an expression is :code:`[ 1 + acos[0] - [#3 ** [4.0/2]]]`. + +Binary operations appear only inside expressions. Nine binary operations are defined. There are four +basic mathematical operations: addition :code:`+`, subtraction :code:`-`, multiplication :code:`*`, +and division :code:`/`. There are three logical operations: non-exclusive or :code:`OR`, exclusive +or :code:`XOR`, and logical and :code:`AND`. The eighth operation is the modulus operation +:code:`MOD`. The ninth operation is the “power” operation :code:`**` of raising the number on the +left of the operation to the power on the right. The binary operations are divided into three +groups. The first group is: power. The second group is: multiplication, division, and modulus. The +third group is: addition, subtraction, logical non- exclusive or, logical exclusive or, and logical +and. If operations are strung together (for example in the expression :code:`[2.0 / 3 * 1.5 - 5.5 / +11.0]`), operations in the first group are to be performed before operations in the second group and +operations in the second group before operations in the third group. If an expression contains more +than one operation from the same group (such as the first / and * in the example), the operation on +the left is performed first. Thus, the example is equivalent to: :code:`[((2.0 / 3) * 1.5) - (5.5 / +11.0)]`, which simplifies to :code:`[1.0 - 0.5]`, which is 0.5. + +The logical operations and modulus are to be performed on any real numbers, not just on integers. +The number zero is equivalent to logical false, and any non-zero number is equivalent to logical +true. + +Unary Operation Value +~~~~~~~~~~~~~~~~~~~~~ + +A unary operation value is either :code:`ATAN` followed by one expression divided by another +expression (for example :code:`ATAN[2]/[1+3]`) or any other unary operation name followed by an +expression (for example :code:`SIN[90]`). The unary operations are: :code:`ABS` (absolute value), +:code:`ACOS` (arc cosine), :code:`ASIN` (arc sine), :code:`ATAN` (arc tangent), :code:`COS` +(cosine), :code:`EXP` (e raised to the given power), :code:`FIX` (round down), :code:`FUP` (round +up), :code:`LN` (natural logarithm), :code:`ROUND` (round to the nearest whole number), :code:`SIN` +(sine), :code:`SQRT` (square root), and :code:`TAN` (tangent). Arguments to unary operations which +take angle measures (:code:`COS`, :code:`SIN`, and :code:`TAN`) are in degrees. Values returned by +unary operations which return angle measures (:code:`ACOS`, :code:`ASIN`, and :code:`ATAN`) are also +in degrees. + +The :code:`FIX` operation rounds towards the left (less positive or more negative) on a number line, +so that :code:`FIX[2.8] = 2` and :code:`FIX[-2.8] = -3`, for example. The :code:`FUP` operation +rounds towards the right (more positive or less negative) on a number line; :code:`FUP[2.8] = 3` and +:code:`FUP[-2.8] = -2`, for example. + +Parameter Setting +~~~~~~~~~~~~~~~~~ + +A parameter setting is the following four items one after the other: (1) a pound character +:code:`#`, (2) a real value which evaluates to an integer between 1 and 5399, (3) an equal sign +:code:`=`, and (4) a real value. For example :code:`#3 = 15` is a parameter setting meaning “set +parameter 3 to 15.” + +A parameter setting does not take effect until after all parameter values on the same line have +been found. For example, if parameter 3 has been previously set to 15 and the line :code:`#3=6 G1 +x#3` is interpreted, a straight move to a point where x equals 15 will occur and the value of +parameter 3 will be 6. + +Comments and Messages +~~~~~~~~~~~~~~~~~~~~~ + +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 is an example of a line containing a comment: +:code:`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. + +Item Repeats +~~~~~~~~~~~~ + +A line may have any number of :code:`G` words, but two :code:`G` words from the same modal group may +not appear on the same line. + +A line may have zero to four :code:`M` words. Two :code:`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. + +If a parameter setting of the same parameter is repeated on a line, :code:`#3=15 #3=6`, for example, +only the last setting will take effect. It is silly, but not illegal, to set the same parameter +twice on the same line. + +If more than one comment appears on a line, only the last one will be used; each of the other +comments will be read and its format will be checked, but it will be ignored thereafter. It is +expected that putting more than one comment on a line will be very rare. + +Item order +~~~~~~~~~~ + +The three types of item whose order may vary on a line (as given at the beginning of this section) +are word, parameter setting, and comment. Imagine that these three types of item are divided into +three groups by type. + +The first group (the words) may be reordered in any way without changing the meaning of the line. + +If the second group (the parameter settings) is reordered, there will be no change in the meaning of +the line unless the same parameter is set more than once. In this case, only the last setting of the +parameter will take effect. For example, after the line :code:`#3=15 #3=6` has been interpreted, the +value of parameter 3 will be 6. If the order is reversed to :code:`#3=6 #3=15` and the line is +interpreted, the value of parameter 3 will be 15. + +If the third group (the comments) contains more than one comment and is reordered, only the last +comment will be used. + +If each group is kept in order or reordered without changing the meaning of the line, then the three +groups may be interleaved in any way without changing the meaning of the line. For example, the line +:code:`g40 g1 #3=15 (foo) #4=-7.0` has five items and means exactly the same thing in any of the 120 +possible orders (such as :code:`#4=-7.0 g1 #3=15 g40 (foo)`) for the five items. + +Commands and Machine Modes +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +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 :code:`G` codes for motion are also modal. If a :code:`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 is +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, :code:`G4` (dwell) +is non-modal. + +Modal Groups +------------ + +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 Table 4. + +For several modal groups, when a machining center is ready to accept commands, one member of the +group must be in effect. There are default settings for these modal groups. When the machining +center is turned on or otherwise re-initialized, the default values are automatically in effect. + +Group 1, the first group on the table, is a group of :code:`G` codes for motion. One of these is +always in effect. That one is called the current motion mode. + +It is an error to put a G-code from group 1 and a G-code from group 0 on the same line if both of +them use axis words. If an axis word-using G-code from group 1 is implicitly in effect on a line (by +having been activated on an earlier line), and a group 0 G-code that uses axis words appears on the +line, the activity of the group 1 G-code is suspended for that line. The axis word-using G-codes +from group 0 are :code:`G10`, :code:`G28`, :code:`G30`, and :code:`G92`. + +G and Input Codes +----------------- + +See ... + +.. + G codes of the RS274/NGC language are shown in Table 5 and described following that. + + In the command prototypes, three dots (...) stand for a real value. As described earlier, a real + value may be (1) an explicit number, 4, for example, (2) an expression, :code:`[2+2]`, for example, + (3) a parameter value, #88, for example, or (4) a unary function value, :code:`acos[0]`, for + example. In most cases, if axis words (any or all of X..., Y..., Z..., A..., B..., C...) are given, + they specify a destination point. Axis numbers are in the currently active coordinate system, unless + explicitly described as being in the absolute coordinate system. Where axis words are optional, any + omitted axes will have their current value. Any items in the command prototypes not explicitly + described as optional are required. It is an error if a required item is omitted. + + In the prototypes, the values following letters are often given as explicit numbers. Unless stated + otherwise, the explicit numbers can be real values. For example, :code:`G10 L2` could equally well + be written :code:`G[2*5] L[1+1]`. If the value of parameter 100 were 2, :code:`G10 L#100` would also + mean the same. Using real values which are not explicit numbers as just shown in the examples is + rarely useful. + + If L... is written in a prototype the “...” will often be referred to as the “L number”. Similarly the + “...” in H... may be called the “H number”, and so on for any other letter. + +Order of Execution +------------------ + +The order of execution of items on a line is critical to safe and effective machine operation. Items +are executed in a particular order if they occur on the same line. + +""" diff --git a/PythonicGcodeMachine/Gcode/Lexer.py b/PythonicGcodeMachine/Gcode/Rs274/Lexer.py similarity index 100% rename from PythonicGcodeMachine/Gcode/Lexer.py rename to PythonicGcodeMachine/Gcode/Rs274/Lexer.py diff --git a/PythonicGcodeMachine/Gcode/Parser.py b/PythonicGcodeMachine/Gcode/Rs274/Parser.py similarity index 100% rename from PythonicGcodeMachine/Gcode/Parser.py rename to PythonicGcodeMachine/Gcode/Rs274/Parser.py diff --git a/PythonicGcodeMachine/Gcode/Rs274/__init__.py b/PythonicGcodeMachine/Gcode/Rs274/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..37fdd45a0d6bed35fad763c9e5dbb87020fe76cb --- /dev/null +++ b/PythonicGcodeMachine/Gcode/Rs274/__init__.py @@ -0,0 +1,384 @@ +#################################################################################################### +# +# PythonicGcodeMachine - @licence_header_description@ +# Copyright (C) 2018 Fabrice Salvaire +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +#################################################################################################### + +"""Module to implement the G-code language. + +History +------- + +The G-code language, also called RS-274, is a programming language for numerical control. It was +developed by the EIA in the early 1960s, and finally standardised by ISO in February 1980 as RS274D +/ ISO 6983. + +The G-code language has several flavours and historical versions. A list of reference documents +follows : + +* The NIST RS274NGC Interpreter - Version 3, T. Kramer, F. Proctor, E. Messina, National Institute + of Standards and Technology, NISTIR 6556, August 17, 2000 +* The documentation of the `Linux CNC `_ project, formerly Enhanced Machine + Controller developed at NIST, +* EIA Standard RS-274-D Interchangeable Variable Block Data Format for Positioning, Contouring, and + Contouring/Positioning Numerically Controlled Machines, 2001 Eye Street, NW, Washington, + D.C. 20006: Electronic Industries Association, February 1979 + +Overview +-------- + +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. + +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, +:code:`G1 X3` is a valid line of code with two words. :code:`G1` is a command meaning “move in a +straight line at the programmed feed rate,” and :code:`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.” + +Language View of a Machining Center +----------------------------------- + +Parameters +~~~~~~~~~~ + +In the RS274/NGC language view, a machining center maintains an array of 5400 numerical +parameters. Many of them have specific uses. The parameter array should persist over time, even if +the machining center is powered down. + +Coordinate Systems +~~~~~~~~~~~~~~~~~~ + +In the RS274/NGC language view, a machining center has an absolute coordinate system and nine +program coordinate systems. + +You can set the offsets of the nine program coordinate systems using G10 L2 Pn (n is the number of +the coordinate system) with values for the axes in terms of the absolute coordinate system. + +You can select one of the nine systems by using G54, G55, G56, G57, G58, G59, G59.1, G59.2, or +G59.3. It is not possible to select the absolute coordinate system directly. You can offset the +current coordinate system using G92 or G92.3. This offset will then apply to all nine program +coordinate systems. This offset may be cancelled with G92.1 or G92.2. + +You can make straight moves in the absolute machine coordinate system by using G53 with either G0 or +G1. + +Data for coordinate systems is stored in parameters. + +During initialization, the coordinate system is selected that is specified by parameter 5220. A +value of 1 means the first coordinate system (the one G54 activates), a value of 2 means the second +coordinate system (the one G55 activates), and so on. It is an error for the value of parameter 5220 +to be anything but a whole number between one and nine. + +Format of a Line +---------------- + +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 block delete character, which is a slash :code:`/` . +#. an optional line number. +#. any number of words, parameter settings, and comments. +#. an end of line marker (carriage return or line feed or both). + +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 :code:`g0x +0. 12 34y +7` is equivalent to :code:`g0 x+0.1234 y7`, for example. + +Blank lines are allowed in the input. They are to be ignored. + +Input is case insensitive, except in comments, i.e., any letter outside a comment may be in upper or +lower case without changing the meaning of a line. + +Line Number +~~~~~~~~~~~ + +A line number is the letter :code:`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. + +Word +~~~~ + +A word is a letter other than :code:`N` followed by a real value. + +Words may begin with any of the letters shown in the following table. The table includes :code:`N` +for completeness, even though, as defined above, line numbers are not words. Several letters +(:code:`I`, :code:`J, K`, :code:`L`, :code:`P`, :code:`R`) may have different meanings in different +contexts. + +Table. Linux CNC Words and their meanings Letter + +====== ===================================================== +Letter Meaning +====== ===================================================== +A A axis of machine +B B axis of machine +C C axis of machine +D Tool radius compensation number +F Feed rate +G General function (See table Modal Groups) +H Tool length offset index +I X offset for arcs and G87 canned cycles +J Y offset for arcs and G87 canned cycles +K Z offset for arcs and G87 canned cycles. + Spindle-Motion Ratio for G33 synchronized movements. +L Generic parameter word for G10, M66 and others +M Miscellaneous function (See table Modal Groups) +N Line number +P Dwell time in canned cycles and with G4. + Key used with G10. +Q Feed increment in G73, G83 canned cycles +R Arc radius or canned cycle plane +S Spindle speed +T Tool selection +U U axis of machine +V V axis of machine +W W axis of machine +X X axis of machine +Y Y axis of machine +Z Z axis of machine +====== ===================================================== + +A real value is some collection of characters that can be processed to come up with a number. A real +value may be an explicit number (such as 341 or -0.8807), a parameter value, an expression, or a +unary operation value. + +Number +~~~~~ + +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. +* 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. + +Parameter Value +~~~~~~~~~~~~~~~ + +A parameter value is the pound character :code:`#` followed by a real value. The real value must +evaluate to an integer between 1 and 5399. The integer is a parameter number, and the value of the +parameter value is whatever number is stored in the numbered parameter. + +The :code:`#` character takes precedence over other operations, so that, for example, :code:`#1+2` +means the number found by adding 2 to the value of parameter 1, not the value found in parameter +3. Of course, :code:`#[1+2]` does mean the value found in parameter 3. The :code:`#` character may +be repeated; for example :code:`##2` means the value of the parameter whose index is the (integer) +value of parameter 2. + +Expressions and Binary Operations +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +An expression is a set of characters starting with a left bracket :code:`[` and ending with a +balancing right bracket :code:`]`. In between the brackets are numbers, parameter values, +mathematical operations, and other expressions. An expression may be evaluated to produce a +number. The expressions on a line are evaluated when the line is read, before anything on the line +is executed. An example of an expression is :code:`[ 1 + acos[0] - [#3 ** [4.0/2]]]`. + +Binary operations appear only inside expressions. Nine binary operations are defined. There are four +basic mathematical operations: addition :code:`+`, subtraction :code:`-`, multiplication :code:`*`, +and division :code:`/`. There are three logical operations: non-exclusive or :code:`OR`, exclusive +or :code:`XOR`, and logical and :code:`AND`. The eighth operation is the modulus operation +:code:`MOD`. The ninth operation is the “power” operation :code:`**` of raising the number on the +left of the operation to the power on the right. The binary operations are divided into three +groups. The first group is: power. The second group is: multiplication, division, and modulus. The +third group is: addition, subtraction, logical non- exclusive or, logical exclusive or, and logical +and. If operations are strung together (for example in the expression :code:`[2.0 / 3 * 1.5 - 5.5 / +11.0]`), operations in the first group are to be performed before operations in the second group and +operations in the second group before operations in the third group. If an expression contains more +than one operation from the same group (such as the first / and * in the example), the operation on +the left is performed first. Thus, the example is equivalent to: :code:`[((2.0 / 3) * 1.5) - (5.5 / +11.0)]`, which simplifies to :code:`[1.0 - 0.5]`, which is 0.5. + +The logical operations and modulus are to be performed on any real numbers, not just on integers. +The number zero is equivalent to logical false, and any non-zero number is equivalent to logical +true. + +Unary Operation Value +~~~~~~~~~~~~~~~~~~~~~ + +A unary operation value is either :code:`ATAN` followed by one expression divided by another +expression (for example :code:`ATAN[2]/[1+3]`) or any other unary operation name followed by an +expression (for example :code:`SIN[90]`). The unary operations are: :code:`ABS` (absolute value), +:code:`ACOS` (arc cosine), :code:`ASIN` (arc sine), :code:`ATAN` (arc tangent), :code:`COS` +(cosine), :code:`EXP` (e raised to the given power), :code:`FIX` (round down), :code:`FUP` (round +up), :code:`LN` (natural logarithm), :code:`ROUND` (round to the nearest whole number), :code:`SIN` +(sine), :code:`SQRT` (square root), and :code:`TAN` (tangent). Arguments to unary operations which +take angle measures (:code:`COS`, :code:`SIN`, and :code:`TAN`) are in degrees. Values returned by +unary operations which return angle measures (:code:`ACOS`, :code:`ASIN`, and :code:`ATAN`) are also +in degrees. + +The :code:`FIX` operation rounds towards the left (less positive or more negative) on a number line, +so that :code:`FIX[2.8] = 2` and :code:`FIX[-2.8] = -3`, for example. The :code:`FUP` operation +rounds towards the right (more positive or less negative) on a number line; :code:`FUP[2.8] = 3` and +:code:`FUP[-2.8] = -2`, for example. + +Parameter Setting +~~~~~~~~~~~~~~~~~ + +A parameter setting is the following four items one after the other: (1) a pound character +:code:`#`, (2) a real value which evaluates to an integer between 1 and 5399, (3) an equal sign +:code:`=`, and (4) a real value. For example :code:`#3 = 15` is a parameter setting meaning “set +parameter 3 to 15.” + +A parameter setting does not take effect until after all parameter values on the same line have +been found. For example, if parameter 3 has been previously set to 15 and the line :code:`#3=6 G1 +x#3` is interpreted, a straight move to a point where x equals 15 will occur and the value of +parameter 3 will be 6. + +Comments and Messages +~~~~~~~~~~~~~~~~~~~~~ + +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 is an example of a line containing a comment: +:code:`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. + +Item Repeats +~~~~~~~~~~~~ + +A line may have any number of :code:`G` words, but two :code:`G` words from the same modal group may +not appear on the same line. + +A line may have zero to four :code:`M` words. Two :code:`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. + +If a parameter setting of the same parameter is repeated on a line, :code:`#3=15 #3=6`, for example, +only the last setting will take effect. It is silly, but not illegal, to set the same parameter +twice on the same line. + +If more than one comment appears on a line, only the last one will be used; each of the other +comments will be read and its format will be checked, but it will be ignored thereafter. It is +expected that putting more than one comment on a line will be very rare. + +Item order +~~~~~~~~~~ + +The three types of item whose order may vary on a line (as given at the beginning of this section) +are word, parameter setting, and comment. Imagine that these three types of item are divided into +three groups by type. + +The first group (the words) may be reordered in any way without changing the meaning of the line. + +If the second group (the parameter settings) is reordered, there will be no change in the meaning of +the line unless the same parameter is set more than once. In this case, only the last setting of the +parameter will take effect. For example, after the line :code:`#3=15 #3=6` has been interpreted, the +value of parameter 3 will be 6. If the order is reversed to :code:`#3=6 #3=15` and the line is +interpreted, the value of parameter 3 will be 15. + +If the third group (the comments) contains more than one comment and is reordered, only the last +comment will be used. + +If each group is kept in order or reordered without changing the meaning of the line, then the three +groups may be interleaved in any way without changing the meaning of the line. For example, the line +:code:`g40 g1 #3=15 (foo) #4=-7.0` has five items and means exactly the same thing in any of the 120 +possible orders (such as :code:`#4=-7.0 g1 #3=15 g40 (foo)`) for the five items. + +Commands and Machine Modes +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +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 :code:`G` codes for motion are also modal. If a :code:`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 is +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, :code:`G4` (dwell) +is non-modal. + +Modal Groups +------------ + +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 Table 4. + +For several modal groups, when a machining center is ready to accept commands, one member of the +group must be in effect. There are default settings for these modal groups. When the machining +center is turned on or otherwise re-initialized, the default values are automatically in effect. + +Group 1, the first group on the table, is a group of :code:`G` codes for motion. One of these is +always in effect. That one is called the current motion mode. + +It is an error to put a G-code from group 1 and a G-code from group 0 on the same line if both of +them use axis words. If an axis word-using G-code from group 1 is implicitly in effect on a line (by +having been activated on an earlier line), and a group 0 G-code that uses axis words appears on the +line, the activity of the group 1 G-code is suspended for that line. The axis word-using G-codes +from group 0 are :code:`G10`, :code:`G28`, :code:`G30`, and :code:`G92`. + +G and Input Codes +----------------- + +See ... + +.. + G codes of the RS274/NGC language are shown in Table 5 and described following that. + + In the command prototypes, three dots (...) stand for a real value. As described earlier, a real + value may be (1) an explicit number, 4, for example, (2) an expression, :code:`[2+2]`, for example, + (3) a parameter value, #88, for example, or (4) a unary function value, :code:`acos[0]`, for + example. In most cases, if axis words (any or all of X..., Y..., Z..., A..., B..., C...) are given, + they specify a destination point. Axis numbers are in the currently active coordinate system, unless + explicitly described as being in the absolute coordinate system. Where axis words are optional, any + omitted axes will have their current value. Any items in the command prototypes not explicitly + described as optional are required. It is an error if a required item is omitted. + + In the prototypes, the values following letters are often given as explicit numbers. Unless stated + otherwise, the explicit numbers can be real values. For example, :code:`G10 L2` could equally well + be written :code:`G[2*5] L[1+1]`. If the value of parameter 100 were 2, :code:`G10 L#100` would also + mean the same. Using real values which are not explicit numbers as just shown in the examples is + rarely useful. + + If L... is written in a prototype the “...” will often be referred to as the “L number”. Similarly the + “...” in H... may be called the “H number”, and so on for any other letter. + +Order of Execution +------------------ + +The order of execution of items on a line is critical to safe and effective machine operation. Items +are executed in a particular order if they occur on the same line. + +""" diff --git a/PythonicGcodeMachine/Machine/data/make-yaml.py b/PythonicGcodeMachine/Gcode/Rs274/data/make-yaml.py similarity index 100% rename from PythonicGcodeMachine/Machine/data/make-yaml.py rename to PythonicGcodeMachine/Gcode/Rs274/data/make-yaml.py diff --git a/PythonicGcodeMachine/Machine/data/rs274-default-parameter-file.yaml b/PythonicGcodeMachine/Gcode/Rs274/data/rs274-default-parameter-file.yaml similarity index 100% rename from PythonicGcodeMachine/Machine/data/rs274-default-parameter-file.yaml rename to PythonicGcodeMachine/Gcode/Rs274/data/rs274-default-parameter-file.yaml diff --git a/PythonicGcodeMachine/Machine/data/rs274-execution-order.yaml b/PythonicGcodeMachine/Gcode/Rs274/data/rs274-execution-order.yaml similarity index 100% rename from PythonicGcodeMachine/Machine/data/rs274-execution-order.yaml rename to PythonicGcodeMachine/Gcode/Rs274/data/rs274-execution-order.yaml diff --git a/PythonicGcodeMachine/Machine/data/rs274-gcodes.yaml b/PythonicGcodeMachine/Gcode/Rs274/data/rs274-gcodes.yaml similarity index 100% rename from PythonicGcodeMachine/Machine/data/rs274-gcodes.yaml rename to PythonicGcodeMachine/Gcode/Rs274/data/rs274-gcodes.yaml diff --git a/PythonicGcodeMachine/Machine/data/rs274-modal-groups.yaml b/PythonicGcodeMachine/Gcode/Rs274/data/rs274-modal-groups.yaml similarity index 100% rename from PythonicGcodeMachine/Machine/data/rs274-modal-groups.yaml rename to PythonicGcodeMachine/Gcode/Rs274/data/rs274-modal-groups.yaml diff --git a/PythonicGcodeMachine/Machine/data/rs274-word-starting-letter.yaml b/PythonicGcodeMachine/Gcode/Rs274/data/rs274-word-starting-letter.yaml similarity index 100% rename from PythonicGcodeMachine/Machine/data/rs274-word-starting-letter.yaml rename to PythonicGcodeMachine/Gcode/Rs274/data/rs274-word-starting-letter.yaml