Skip to content

Commit 63ce88d

Browse files
authored
Merge pull request #15 from plottertools/tatarize/G20-corrections
G20 units in defaults are imperial rather than mm
2 parents 58a1cdb + 5fb2b1a commit 63ce88d

4 files changed

Lines changed: 69 additions & 15 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ All of the options below default to an empty text which means no output is gener
9797
### Segment formatting
9898
`gwrite` uses `.format()` encoding which means that data elements must be encapsulated in `{}` brackets. This provides a particular syntax token which differs from between elements.
9999
For example every element except `layer_join` and `segment_join` accepts the value of `index`. You would encode that in the text as `{index:d}` the d denotes an integer value. If you need to have a `{` value in your text you would encode that as `{{` likewise you would encode a `}` as `}}`.
100-
- `layer_start`: Accepts `index` the current layer number and `layer_id` as vpype layer ID.
101-
- `layer_end`: Accepts `index` the current layer number and `layer_id` as vpype layer ID.
102-
- `line_start`: Accepts `index` the current line number.
103-
- `line_end`: Accepts `index` the current line number.
100+
- `layer_start`: Accepts `index` the current layer index starting from 0, `index1` the current layer number starting from 1, and `layer_id` as vpype layer ID.
101+
- `layer_end`: Accepts `index` the current layer index starting from 0, `index1` the current layer number starting from 1, and `layer_id` as vpype layer ID.
102+
- `line_start`: Accepts `index` the current line number starting from 0, `index1` the current line number starting from 1, and `layer_index`, `layer_index1`, and `layer_id` values for the current layer this line is within.
103+
- `line_end`: Accepts `index` the current line number starting from 0, `index1` the current line number starting from 1, and `layer_index`, `layer_index1`, and `layer_id` values for the current layer this line is within.
104104

105105
The segments accept a lot of values that may be useful statistics for various formats:
106106
* `index`: index of the particular coordinate pair. eg `{index:d}`

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="vpype-gcode",
8-
version="0.8.2",
8+
version="0.9.0",
99
description="vpype gcode plugin",
1010
long_description=readme,
1111
long_description_content_type="text/markdown",

vpype_gcode/bundled_configs.toml

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
[gwrite.ninja]
1+
2+
[gwrite.gcode]
23
document_start = "G20\nG17\nG90\n"
3-
segment_first = "M380\nG00 X{x:.4f} Y{y:.4f}\nM381\n"
4+
segment_first = "G00 X{x:.4f} Y{y:.4f}\n"
45
segment = "G01 X{x:.4f} Y{y:.4f}\n"
56
document_end = "M2\n"
6-
unit = "mm"
7+
unit = "in"
78

8-
[gwrite.gcode]
9-
document_start = "G20\nG17\nG90\n"
9+
[gwrite.gcodemm]
10+
document_start = "G21\nG17\nG90\n"
1011
segment_first = "G00 X{x:.4f} Y{y:.4f}\n"
1112
segment = "G01 X{x:.4f} Y{y:.4f}\n"
1213
document_end = "M2\n"
@@ -17,7 +18,7 @@ document_start = "G20\nG17\nG91\n"
1718
segment_first = "G00 X{dx:.4f} Y{dy:.4f}\n"
1819
segment = "G01 X{dx:.4f} Y{dy:.4f}\n"
1920
document_end = "M2\n"
20-
unit = "mm"
21+
unit = "in"
2122

2223
[gwrite.csv]
2324
document_start = "#Operation, X-value, Y-value\n"
@@ -48,3 +49,34 @@ segment_first = "{ix:d} {iy:d} l"
4849
segment = "{idx:d} {idy:d} "
4950
line_end = '"/>'
5051
layer_end = "</g>"
52+
53+
[gwrite.BBC-GL]
54+
document_start = ""
55+
layer_start = "F{index1:d}\n"
56+
segment_first = "C{x:.0f},{y:.0f};HK\n"
57+
segment = "C{x:.0f},{y:.0f};IK\n"
58+
document_end = "F0\n"
59+
scale_x = 10
60+
scale_y = 10
61+
unit = "mm"
62+
63+
[gwrite.ninja]
64+
document_start = "G21\nG17\nG90\nG28\n"
65+
segment_first = "G1 Z3 F10000\nG0 X{x:.4f} Y{y:.4f} F15000\nG1 Z6 F6000\n"
66+
segment = "G1 X{x:.4f} Y{y:.4f} F10000\n"
67+
document_end = "\nG1 Z0 F1000\nG1 X0 Y0 F1000\nM2\n"
68+
unit = "mm"
69+
70+
[gwrite.step_motor]
71+
document_start = "$H (unlock by homing)\nG21 (unit is mm)\nG17 (work in XY plane)\n"
72+
segment_first = "G91 Z-10 (pen up)\nG90 X{x:.4f} Y{y:.4f} (travel)\nG91 Z+13 (pen down)\nG90 (absolute position)\n"
73+
segment = "G01 X{x:.4f} Y{y:.4f} (draw)\n"
74+
document_end = "G91 Z-10 (pen up)\nG90 X0 Y0 (travel)\nM2 (end)\n"
75+
unit = "mm"
76+
77+
[gwrite.step_motor_relative]
78+
document_start = "$H (unlock by homing)\nG21 (unit is mm)\nG17 (work in XY plane)\nG91 (relative position)\n"
79+
segment_first = "G01 Z-10 (pen up)\nG00 X{dx:.4f} Y{dy:.4f} (travel)\nG01 Z+13 (pen down)\n"
80+
segment = "G01 X{dx:.4f} Y{dy:.4f} Z+0.01 (draw with minimum pressure)\n"
81+
document_end = "G01 Z-10 (pen up)\nG90 X0 Y0 (travel to origin)\nM2 (end)\n"
82+
unit = "mm"

vpype_gcode/gwrite.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,23 @@ def gwrite(document: vp.Document, output: typing.TextIO, profile: str):
8585
for layer_index, layer_id in enumerate(document.layers):
8686
layer = document.layers[layer_id]
8787
if layer_start is not None:
88-
output.write(layer_start.format(index=layer_index, layer_id=layer_id))
88+
output.write(
89+
layer_start.format(
90+
index=layer_index, index1=layer_index + 1, layer_id=layer_id
91+
)
92+
)
8993
lastlines_index = len(layer) - 1
9094
for lines_index, line in enumerate(layer):
9195
if line_start is not None:
92-
output.write(line_start.format(index=lines_index))
96+
output.write(
97+
line_start.format(
98+
index=lines_index,
99+
index1=lines_index + 1,
100+
layer_index=layer_index,
101+
layer_index1=layer_index + 1,
102+
layer_id=layer_id,
103+
)
104+
)
93105
segment_last_index = len(line) - 1
94106
for segment_index, seg in enumerate(line):
95107
x = seg.real
@@ -127,11 +139,21 @@ def gwrite(document: vp.Document, output: typing.TextIO, profile: str):
127139
last_x = x
128140
last_y = y
129141
if line_end is not None:
130-
output.write(line_end.format(index=lines_index))
142+
output.write(
143+
line_end.format(
144+
index=lines_index,
145+
index1=lines_index + 1,
146+
layer_index=layer_index,
147+
layer_index1=layer_index + 1,
148+
layer_id=layer_id,
149+
)
150+
)
131151
if line_join is not None and lines_index != lastlines_index:
132152
output.write(line_join)
133153
if layer_end is not None:
134-
output.write(layer_end.format(index=layer_index, layer_id=layer_id))
154+
output.write(
155+
layer_end.format(index=layer_index, index1=layer_index + 1, layer_id=layer_id)
156+
)
135157
if layer_join is not None and layer_index != lastlayer_index:
136158
output.write(layer_join)
137159
if document_end is not None:

0 commit comments

Comments
 (0)