nc-gcode-interpreter 0.1.7__cp311-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ from .nc_gcode_interpreter import nc_to_dataframe as _nc_to_dataframe
2
+ from .nc_gcode_interpreter import __doc__ # noqa: F401
3
+
4
+ __all__ = ["nc_to_dataframe"]
5
+
6
+
7
+ # nc_gcode_interpreter.pyi
8
+ import polars as pl
9
+ from typing import Protocol
10
+
11
+
12
+ class TextFileLike(Protocol):
13
+ def read(self) -> str: ...
14
+
15
+
16
+ def nc_to_dataframe(
17
+ input: TextFileLike | str,
18
+ initial_state: TextFileLike | str | None = None,
19
+ axis_identifiers: list[str] | None = None,
20
+ extra_axes: list[str] | None = None,
21
+ iteration_limit: int = 10000,
22
+ ) -> tuple[pl.DataFrame, dict]:
23
+ if input is None:
24
+ raise ValueError("input cannot be None")
25
+ if not isinstance(input, str):
26
+ input = input.read()
27
+ if initial_state is not None and not isinstance(initial_state, str):
28
+ initial_state = initial_state.read()
29
+
30
+ df, state = _nc_to_dataframe(
31
+ input, initial_state, axis_identifiers, extra_axes, iteration_limit
32
+ )
33
+ return df, state
@@ -0,0 +1,174 @@
1
+ Metadata-Version: 2.3
2
+ Name: nc-gcode-interpreter
3
+ Version: 0.1.7
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Programming Language :: Python :: 3.12
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
10
+ Requires-Dist: maturin >=1.7.4
11
+ Requires-Dist: polars >=1.9.0
12
+ Requires-Dist: jupyter >=1.1.1 ; extra == 'dev'
13
+ Requires-Dist: pytest >=8.3.3 ; extra == 'test'
14
+ Provides-Extra: dev
15
+ Provides-Extra: test
16
+ License-File: LICENSE
17
+ Summary: A interpreter for NC (Numerical Control) code
18
+ Author-email: CEAD Group <software@ceadgroup.com>
19
+ Requires-Python: >=3.11
20
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
21
+ Project-URL: Homepage, https://github.com/CEAD-group/nc-gcode-interpreter
22
+ Project-URL: Repository, https://github.com/CEAD-group/nc-gcode-interpreter.git
23
+ Project-URL: Documentation, https://github.com/CEAD-group/nc-gcode-interpreter/blob/main/README.md
24
+
25
+ # NC-GCode-Interpreter
26
+
27
+ A robust interpreter tailored for processing Sinumerik-flavored NC G-code, designed to convert MPF files into CSV outputs or Polars dataframes when used with Python bindings.
28
+
29
+ ## Overview
30
+
31
+ The NC-GCode-Interpreter provides a streamlined and efficient solution for interpreting G-code specifically designed with Sinumerik specifications in mind. This tool caters to both CLI users and those preferring a Python environment, ensuring versatility and ease of use in processing NC programming commands into structured formats like CSV files or Polars dataframes.
32
+
33
+ ## Features
34
+
35
+ ### Supported G-code Features
36
+
37
+ - **G Group Commands**: Recognizes G-code groups and modal gcode commands.
38
+ - **Global Translations**: Supports commands like TRANS and ATRANS for adjusting coordinates globally.
39
+ - **Looping Constructs**: Handles loops using WHILE and FOR statements.
40
+ - **Variable Handling**: Supports definition and manipulation of local variables.
41
+ - **Conditional Logic**: Implements conditional execution with IF, ELSE, and ENDIF.
42
+ - **Arithmetic Operations**: Basic operations such as addition, subtraction, multiplication, and division are supported.
43
+ - **Array Operations**: Manages arrays and allows operations on them.
44
+ - **Incremental Changes**: Facilitates incremental changes in axes positions like X=IC(2).
45
+
46
+ ### Additional Functionality
47
+
48
+ - **Custom Axes**: Allows users to define additional axes beyond the standard X, Y, Z.
49
+ - **Initial State Configuration**: Enables the use of an initial state MPF file to set default values for multiple runs.
50
+ - **CLI Options**: Numerous command-line options to customize the processing like axis overriding, loop limits, and more.
51
+
52
+
53
+
54
+ ## Example Usage
55
+
56
+
57
+ Consider this example program to generate a square in two layers:
58
+ ```scheme
59
+ ;Example.MPF
60
+ DEF INT n_layers = 2, layer=1
61
+ DEF REAL size = 100 ;size of the square
62
+ DEF REAL layer_height = 4 ;size of the square
63
+ TRANS Z = 0.5 ; move up all z coordinates by 0.5
64
+ G1 F=1000; Set feed rate in millimeters per minute
65
+ G1 X0 Y500 Z0 ; move to the starting point
66
+ WHILE (layer <= n_layers)
67
+ X=IC(size)
68
+ Y=IC(size)
69
+ X=IC(-size)
70
+ Y=IC(-size) Z=IC(layer_height)
71
+ layer = layer + 1
72
+ ENDWHILE
73
+ M31; end of program
74
+ ```
75
+
76
+
77
+ ### CLI Usage
78
+ ```bash
79
+ > cargo run -- --help
80
+ A G-code interpreter
81
+
82
+ Usage: nc-gcode-interpreter [OPTIONS] <input>
83
+
84
+ Arguments:
85
+ <input> Input G-code file (.mpf)
86
+
87
+ Options:
88
+ -a, --axes <AXIS> Override default axis identifiers (comma-separated, e.g., "X,Y,Z")
89
+ -e, --extra-axes <EXTRA_AXIS> Add extra axis identifiers (comma-separated, e.g., "RA1,RA2")
90
+ -i, --initial_state <INITIAL_STATE> Optional initial_state file to initialize state
91
+ -l, --iteration_limit <LIMIT> Maximum number of iterations for loops [default: 10000]
92
+ -f, --disable-forward-fill Disable forward-filling of null values in axes columns
93
+ -h, --help Print help
94
+ -V, --version Print version
95
+
96
+ > cargo run -- Example.MPF
97
+ ```
98
+
99
+ ```csv
100
+ X ,Y ,Z ,F ,M ,gg01_motion ,comment
101
+ , , , , , ,;size of the square
102
+ , , , , , ,;size of the square
103
+ , , , , , ,; move up all z coordinates by 0.5
104
+ , , ,1000.000 , ,G1 ,; Set feed rate in millimeters per minute
105
+ 0.000 ,500.000 ,0.500 ,1000.000 , ,G1 ,; move to the starting point
106
+ 100.000 ,500.000 ,0.500 ,1000.000 , ,G1 ,
107
+ 100.000 ,600.000 ,0.500 ,1000.000 , ,G1 ,
108
+ 0.000 ,600.000 ,0.500 ,1000.000 , ,G1 ,
109
+ 0.000 ,500.000 ,5.000 ,1000.000 , ,G1 ,
110
+ 100.000 ,500.000 ,5.000 ,1000.000 , ,G1 ,
111
+ 100.000 ,600.000 ,5.000 ,1000.000 , ,G1 ,
112
+ 0.000 ,600.000 ,5.000 ,1000.000 , ,G1 ,
113
+ 0.000 ,500.000 ,9.500 ,1000.000 , ,G1 ,
114
+ 0.000 ,500.000 ,9.500 ,1000.000 ,M31 ,G1 ,; end of program
115
+ ```
116
+
117
+
118
+ ### python example
119
+
120
+ ```bash
121
+ python -c "\
122
+ from nc_gcode_interpreter import nc_to_dataframe; \
123
+ from pathlib import Path; \
124
+ df, state = nc_to_dataframe(Path('Example.MPF').open()); \
125
+ print(df)"
126
+ shape: (14, 7)
127
+ ┌───────┬───────┬──────┬────────┬───────────┬─────────────┬─────────────────────────────────┐
128
+ │ X ┆ Y ┆ Z ┆ F ┆ M ┆ gg01_motion ┆ comment │
129
+ │ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
130
+ │ f32 ┆ f32 ┆ f32 ┆ f32 ┆ list[str] ┆ str ┆ str │
131
+ ╞═══════╪═══════╪══════╪════════╪═══════════╪═════════════╪═════════════════════════════════╡
132
+ │ null ┆ null ┆ null ┆ null ┆ null ┆ null ┆ ;size of the square │
133
+ │ null ┆ null ┆ null ┆ null ┆ null ┆ null ┆ ;size of the square │
134
+ │ null ┆ null ┆ null ┆ null ┆ null ┆ null ┆ ; move up all z coordinates by… │
135
+ │ null ┆ null ┆ null ┆ 1000.0 ┆ null ┆ G1 ┆ ; Set feed rate in millimeters… │
136
+ │ 0.0 ┆ 500.0 ┆ 0.5 ┆ 1000.0 ┆ null ┆ G1 ┆ ; move to the starting point │
137
+ │ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
138
+ │ 100.0 ┆ 500.0 ┆ 5.0 ┆ 1000.0 ┆ null ┆ G1 ┆ null │
139
+ │ 100.0 ┆ 600.0 ┆ 5.0 ┆ 1000.0 ┆ null ┆ G1 ┆ null │
140
+ │ 0.0 ┆ 600.0 ┆ 5.0 ┆ 1000.0 ┆ null ┆ G1 ┆ null │
141
+ │ 0.0 ┆ 500.0 ┆ 9.5 ┆ 1000.0 ┆ null ┆ G1 ┆ null │
142
+ │ 0.0 ┆ 500.0 ┆ 9.5 ┆ 1000.0 ┆ ["M31"] ┆ G1 ┆ ; end of program │
143
+ └───────┴───────┴──────┴────────┴───────────┴─────────────┴─────────────────────────────────┘
144
+ ```
145
+
146
+
147
+ ```bash
148
+ target/release/nc-gcode-interpreter --help
149
+ A G-code interpreter
150
+
151
+ Usage: nc-gcode-interpreter [OPTIONS] <input>
152
+
153
+ Arguments:
154
+ <input> Input G-code file (.mpf)
155
+
156
+ Options:
157
+ -a, --axes <AXIS> Override default axis identifiers (comma-separated, e.g., "X,Y,Z")
158
+ -e, --extra-axes <EXTRA_AXIS> Add extra axis identifiers (comma-separated, e.g., "RA1,RA2")
159
+ -i, --initial_state <INITIAL_STATE> Optional initial_state file to initialize state
160
+ -l, --iteration_limit <LIMIT> Maximum number of iterations for loops [default: 10000]
161
+ -f, --disable-forward-fill Disable forward-filling of null values in axes columns
162
+ -h, --help Print help
163
+ -V, --version Print version
164
+ ```
165
+
166
+ ## Why?
167
+
168
+ The Sinumerik NC programming guide is extensive, and some of it's functionality can be very convenient for making on the fly improvements to cde. However to better uderstand, visualize and simulate the code, it is often necessary to convert it to a more structured format like CSV or a dataframe. This tool aims to provide a simple and efficient way to convert Sinumerik-flavored G-code to a structured format, making it easier to analyze and visualize the code.
169
+
170
+ Only a limited subset is supported, but the tool is designed to be easily extensible to support more features in the future.
171
+
172
+ ## Contributing
173
+ We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for more details on how to get started.
174
+
@@ -0,0 +1,6 @@
1
+ nc_gcode_interpreter-0.1.7.dist-info/METADATA,sha256=QVU9W8NrlUP6ZQ6n6nx2taeR11_A3TZ3diYaPqiFiq0,9144
2
+ nc_gcode_interpreter-0.1.7.dist-info/WHEEL,sha256=bNtRK4IG-ZINiRwRhIvmsDSb0Vife_pt6vsyhyhjHi8,95
3
+ nc_gcode_interpreter-0.1.7.dist-info/licenses/LICENSE,sha256=HrtIztCN6SpmSpwVnrA2SVGeEcM-zoZgUkFWlt-1ikw,1082
4
+ nc_gcode_interpreter/__init__.py,sha256=WqXk0BgTWrJ18rv6eQsImkWTZ0p7-gsJuG4yxj7dQjI,982
5
+ nc_gcode_interpreter/nc_gcode_interpreter.cp311-win_amd64.pyd,sha256=mks-rCRiHJagbV31PO8_dybfyfga8Cr12ISenVRAY18,14203904
6
+ nc_gcode_interpreter-0.1.7.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.7.4)
3
+ Root-Is-Purelib: false
4
+ Tag: cp311-none-win_amd64
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 CEAD
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.