Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
####################################################################################################
#
# PythonicGcodeMachine - A Python G-code Toolkit
# 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 <http://www.gnu.org/licenses/>.
#
####################################################################################################
"""G-code documentation from NIST paper, see :ref:`rs-274-reference-page`.
.. warning::
Must be checked for PDF to rST errors.
.. note::
Class Name Format:
* G1_G2 for G1 and G2,
* G1_1 for G1.1,
* G1_to_G10 for G1 to G10.
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, [2+2], for example, (3) a
parameter value, #88, for example, or (4) a unary function value, 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, G10 L2 could equally well be
written G[2*5] L[1+1]. If the value of parameter 100 were 2, 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.
"""
####################################################################################################
class G0:
"""**Rapid Linear Motion — G0**
For rapid linear motion, program G0 X… Y… Z… A… B… C…, where all the axis words are optional,
except that at least one must be used. The G0 is optional if the current motion mode is G0. This
will produce coordinated linear motion to the destination point at the current traverse rate (or
slower if the machine will not go that fast). It is expected that cutting will not take place
when a G0 command is executing.
**It is an error if:**
* all axis words are omitted.
If cutter radius compensation is active, the motion will differ from the above; see Appendix
B. If G53 is programmed on the same line, the motion will also differ; see Section 3.5.12.
"""
####################################################################################################
class G1:
"""**Linear Motion at Feed Rate — G1**
For linear motion at feed rate (for cutting or not), program G1 X… Y… Z… A… B… C…, where all
the axis words are optional, except that at least one must be used. The G1 is optional if the
current motion mode is G1. This will produce coordinated linear motion to the destination point
at the current feed rate (or slower if the machine will not go that fast).
**It is an error if:**
* all axis words are omitted.
If cutter radius compensation is active, the motion will differ from the above; see Appendix
B. If G53 is programmed on the same line, the motion will also differ; see Section 3.5.12.
"""
####################################################################################################
class G2_G3:
"""**Arc at Feed Rate — G2 and G3**
A circular or helical arc is specified using either G2 (clockwise arc)
or G3 (counterclockwise arc).
The axis of the circle or helix must be parallel to the X, Y, or Z-axis of the machine
coordinate system. The axis (or, equivalently, the plane perpendicular to the axis) is selected
with G17 (Z-axis, XY-plane), G18 (Y-axis, XZ-plane), or G19 (X-axis, YZ-plane). If the arc is
circular, it lies in a plane parallel to the selected plane.
If a line of RS274/NGC code makes an arc and includes rotational axis motion, the rotational
axes turn at a constant rate so that the rotational motion starts and finishes when the XYZ
motion starts and finishes. Lines of this sort are hardly ever programmed.
If cutter radius compensation is active, the motion will differ from what is described here. See
Appendix B.
Two formats are allowed for specifying an arc. We will call these the center format and the
radius format. In both formats the G2 or G3 is optional if it is the current motion mode.
*Radius Format Arc*
In the radius format, the coordinates of the end point of the arc in the selected plane are
specified along with the radius of the arc. Program G2 X… Y… Z… A… B… C… R… (or use G3 instead
of G2). R is the radius. The axis words are all optional except that at least one of the two
words for the axes in the selected plane must be used. The R number is the radius. A positive
radius indicates that the arc turns through 180 degrees or less, while a negative radius
indicates a turn of 180 degrees to 359.999 degrees. If the arc is helical, the value of the end
point of the arc on the coordinate axis parallel to the axis of the helix is also specified.
**It is an error if:**
* both of the axis words for the axes of the selected plane are omitted,
* the end point of the arc is the same as the current point.
It is not good practice to program radius format arcs that are nearly full circles or are
semicircles (or nearly semicircles) because a small change in the location of the end point will
produce a much larger change in the location of the center of the circle (and, hence, the middle
of the arc).
The magnification effect is large enough that rounding error in a number can produce
out-of-tolerance cuts. Nearly full circles are outrageously bad, semicircles (and nearly so) are
only very bad. Other size arcs (in the range tiny to 165 degrees or 195 to 345 degrees) are OK.
Here is an example of a radius format command to mill an arc: G17 G2 x 10 y 15 r 20 z 5.
That means to make a clockwise (as viewed from the positive Z-axis) circular or helical arc
whose axis is parallel to the Z-axis, ending where X=10, Y=15, and Z=5, with a radius of 20. If
the starting value of Z is 5, this is an arc of a circle parallel to the XY-plane; otherwise it
is a helical arc.
*Center Format Arc*
In the center format, the coordinates of the end point of the arc in the selected plane are
specified along with the offsets of the center of the arc from the current location. In this
format, it is OK if the end point of the arc is the same as the current point.
**It is an error if:**
* when the arc is projected on the selected plane, the distance from the current point to the
center differs from the distance from the end point to the center by more than 0.0002 inch (if
inches are being used) or 0.002 millimeter (if millimeters are being used).
When the XY-plane is selected, program G2 X… Y… Z… A… B… C… I… J… (or use G3 instead of G2). The
axis words are all optional except that at least one of X and Y must be used. I and J are the
offsets from the current location (in the X and Y directions, respectively) of the center of the
circle. I and J are optional except that at least one of the two must be used.
**It is an error if:**
* X and Y are both omitted,
* I and J are both omitted.
When the XZ-plane is selected, program G2 X… Y… Z… A… B… C… I… K… (or use G3 instead of G2). The
axis words are all optional except that at least one of X and Z must be used. I and K are the
offsets from the current location (in the X and Z directions, respectively) of the center of the
circle. I and K are optional except that at least one of the two must be used.
**It is an error if:**
* X and Z are both omitted,
* I and K are both omitted.
When the YZ-plane is selected, program G2 X… Y… Z… A… B… C… J… K… (or use G3 instead of G2). The
axis words are all optional except that at least one of Y and Z must be used. J and K are the
offsets from the current location (in the Y and Z directions, respectively) of the center of the
circle. J and K are optional except that at least one of the two must be used.
**It is an error if:**
* Y and Z are both omitted,
* J and K are both omitted.
Here is an example of a center format command to mill an arc: G17 G2 x 10 y 16 i 3 j 4 z 9.
That means to make a clockwise (as viewed from the positive z-axis) circular or helical arc
whose axis is parallel to the Z-axis, ending where X=10, Y=16, and Z=9, with its center offset
in the X direction by 3 units from the current X location and offset in the Y direction by 4
units from the current Y location. If the current location has X=7, Y=7 at the outset, the
center will be at X=10, Y=11. If the starting value of Z is 9, this is a circular arc; otherwise
Loading full blame...