nc-gcode-interpreter 0.1.7__tar.gz → 0.1.9__tar.gz

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.
Files changed (70) hide show
  1. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/.github/workflows/build-and-release.yml +2 -1
  2. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/Cargo.lock +3 -3
  3. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/Cargo.toml +1 -1
  4. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/Development.md +1 -1
  5. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/PKG-INFO +45 -28
  6. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/README.md +40 -25
  7. nc_gcode_interpreter-0.1.9/examples/function_calls.csv +3 -0
  8. nc_gcode_interpreter-0.1.9/examples/function_calls.mpf +2 -0
  9. nc_gcode_interpreter-0.1.9/examples/if_statement.mpf +13 -0
  10. nc_gcode_interpreter-0.1.9/examples/loop.csv +321 -0
  11. nc_gcode_interpreter-0.1.9/examples/multiple_m_codes.csv +10 -0
  12. nc_gcode_interpreter-0.1.9/examples/simple.csv +6 -0
  13. nc_gcode_interpreter-0.1.9/examples/tool.csv +2 -0
  14. nc_gcode_interpreter-0.1.9/ggroups/generate_modal_ggroups.py +29 -0
  15. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/ggroups/generate_pest.py +1 -1
  16. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/pyproject.toml +13 -9
  17. nc_gcode_interpreter-0.1.9/python/nc_gcode_interpreter/__init__.py +259 -0
  18. nc_gcode_interpreter-0.1.9/python/nc_gcode_interpreter/_internal.pyi +62 -0
  19. nc_gcode_interpreter-0.1.9/python/nc_gcode_interpreter/py.typed +0 -0
  20. nc_gcode_interpreter-0.1.9/python/tests/test_expected_output.py +68 -0
  21. nc_gcode_interpreter-0.1.9/python/tests/test_g_groups.py +23 -0
  22. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/src/interpret_rules.rs +2 -1
  23. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/src/interpreter.rs +104 -51
  24. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/src/lib.rs +17 -1
  25. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/src/main.rs +1 -1
  26. {nc_gcode_interpreter-0.1.7/ggroups → nc_gcode_interpreter-0.1.9/src}/modal_groups.rs +9 -1
  27. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/uv.lock +188 -72
  28. nc_gcode_interpreter-0.1.7/Example.MPF +0 -14
  29. nc_gcode_interpreter-0.1.7/examples/if_statement.mpf +0 -13
  30. nc_gcode_interpreter-0.1.7/examples/loop.csv +0 -321
  31. nc_gcode_interpreter-0.1.7/examples/multiple_m_codes.csv +0 -10
  32. nc_gcode_interpreter-0.1.7/examples/simple.csv +0 -6
  33. nc_gcode_interpreter-0.1.7/examples/tool.csv +0 -2
  34. nc_gcode_interpreter-0.1.7/ggroups/generate_modal_ggroups.py +0 -21
  35. nc_gcode_interpreter-0.1.7/python/nc_gcode_interpreter/__init__.py +0 -33
  36. nc_gcode_interpreter-0.1.7/python/tests/test_expected_output.py +0 -40
  37. nc_gcode_interpreter-0.1.7/src/modal_groups.rs +0 -57
  38. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/.gitignore +0 -0
  39. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/CONTRIBUTING.md +0 -0
  40. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/LICENSE +0 -0
  41. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/TODO.md +0 -0
  42. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/arrays.csv +0 -0
  43. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/arrays.mpf +0 -0
  44. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/basic_math.csv +0 -0
  45. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/basic_math.mpf +0 -0
  46. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/custom_vars.csv +0 -0
  47. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/custom_vars.mpf +0 -0
  48. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/defaults.csv +0 -0
  49. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/defaults.mpf +0 -0
  50. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/for_loop.csv +0 -0
  51. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/for_loop.mpf +0 -0
  52. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/if_statement.csv +0 -0
  53. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/increment.csv +0 -0
  54. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/increment.mpf +0 -0
  55. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/loop.mpf +0 -0
  56. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/multiple_m_codes.mpf +0 -0
  57. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/simple.mpf +0 -0
  58. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/tool.mpf +0 -0
  59. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/trans.csv +0 -0
  60. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/trans.mpf +0 -0
  61. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/variables.csv +0 -0
  62. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/examples/variables.mpf +0 -0
  63. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/ggroups/ggroups.pest +0 -0
  64. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/python/example/minimal.py +0 -0
  65. {nc_gcode_interpreter-0.1.7/ggroups → nc_gcode_interpreter-0.1.9/python/nc_gcode_interpreter}/ggroups.json +0 -0
  66. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/rustfmt.toml +0 -0
  67. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/src/errors.rs +0 -0
  68. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/src/grammar.pest +0 -0
  69. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/src/state.rs +0 -0
  70. {nc_gcode_interpreter-0.1.7 → nc_gcode_interpreter-0.1.9}/src/types.rs +0 -0
@@ -89,7 +89,8 @@ jobs:
89
89
  pip install "${WHL_FILE}[test]"
90
90
  - name: Run tests with pytest
91
91
  run: pytest
92
-
92
+ - name: Type checking with mypy
93
+ run: mypy python
93
94
  linux:
94
95
  if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
95
96
  needs: [lint, test]
@@ -724,7 +724,7 @@ dependencies = [
724
724
 
725
725
  [[package]]
726
726
  name = "nc-gcode-interpreter"
727
- version = "0.1.7"
727
+ version = "0.1.9"
728
728
  dependencies = [
729
729
  "clap",
730
730
  "csv",
@@ -819,9 +819,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
819
819
 
820
820
  [[package]]
821
821
  name = "pest"
822
- version = "2.7.13"
822
+ version = "2.7.14"
823
823
  source = "registry+https://github.com/rust-lang/crates.io-index"
824
- checksum = "fdbef9d1d47087a895abd220ed25eb4ad973a5e26f6a4367b038c25e28dfc2d9"
824
+ checksum = "879952a81a83930934cbf1786752d6dedc3b1f29e8f8fb2ad1d0a36f377cf442"
825
825
  dependencies = [
826
826
  "memchr",
827
827
  "thiserror",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "nc-gcode-interpreter"
3
- version = "0.1.7"
3
+ version = "0.1.9"
4
4
  edition = "2021"
5
5
 
6
6
  [lib]
@@ -42,5 +42,5 @@ rm **/*.csv && cargo build --release && find examples -name "*.mpf" -type f -pri
42
42
  ## python test
43
43
 
44
44
  ```bash
45
- maturin develop --release && pytest
45
+ maturin develop --release --uv && pytest
46
46
  ```
@@ -1,20 +1,22 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: nc-gcode-interpreter
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Programming Language :: Python :: 3.11
6
7
  Classifier: Programming Language :: Python :: 3.12
7
8
  Classifier: License :: OSI Approved :: MIT License
8
9
  Classifier: Operating System :: OS Independent
9
10
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
10
11
  Requires-Dist: maturin >=1.7.4
11
- Requires-Dist: polars >=1.9.0
12
+ Requires-Dist: polars[pyarrow] >=1.9.0
12
13
  Requires-Dist: jupyter >=1.1.1 ; extra == 'dev'
13
14
  Requires-Dist: pytest >=8.3.3 ; extra == 'test'
15
+ Requires-Dist: mypy ; extra == 'test'
14
16
  Provides-Extra: dev
15
17
  Provides-Extra: test
16
18
  License-File: LICENSE
17
- Summary: A interpreter for NC (Numerical Control) code
19
+ Summary: A interpreter for NC (Numerical Control) GCode
18
20
  Author-email: CEAD Group <software@ceadgroup.com>
19
21
  Requires-Python: >=3.11
20
22
  Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
@@ -24,44 +26,42 @@ Project-URL: Documentation, https://github.com/CEAD-group/nc-gcode-interpreter/b
24
26
 
25
27
  # NC-GCode-Interpreter
26
28
 
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.
29
+ A robust interpreter designed for processing Sinumerik-flavored NC G-code, capable of converting MPF files into CSV outputs or Polars DataFrames via Python bindings.
28
30
 
29
31
  ## Overview
30
32
 
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.
33
+ The **NC-GCode-Interpreter** offers a streamlined and efficient solution for interpreting G-code specifically tailored to Sinumerik specifications. This tool caters to both command-line interface (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
34
 
33
35
  ## Features
34
36
 
35
37
  ### Supported G-code Features
36
38
 
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.
39
+ - **G Group Commands**: Recognizes G-code groups and modal G-code commands.
40
+ - **Global Transformations**: Supports commands like `TRANS` and `ATRANS` for adjusting coordinates globally.
41
+ - **Looping Constructs**: Handles loops using `WHILE` and `FOR` statements.
40
42
  - **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
+ - **Conditional Logic**: Implements conditional execution with `IF`, `ELSE`, and `ENDIF`.
44
+ - **Arithmetic Operations**: Supports basic operations such as addition, subtraction, multiplication, and division.
43
45
  - **Array Operations**: Manages arrays and allows operations on them.
44
- - **Incremental Changes**: Facilitates incremental changes in axes positions like X=IC(2).
46
+ - **Incremental Changes**: Facilitates incremental changes in axes positions like `X=IC(2)`.
45
47
 
46
48
  ### Additional Functionality
47
49
 
48
- - **Custom Axes**: Allows users to define additional axes beyond the standard X, Y, Z.
50
+ - **Custom Axes**: Allows users to define additional axes beyond the standard `X`, `Y`, `Z`.
49
51
  - **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
-
52
+ - **CLI Options**: Numerous command-line options to customize the processing, such as axis overriding, loop limits, and more.
53
53
 
54
54
  ## Example Usage
55
55
 
56
-
57
56
  Consider this example program to generate a square in two layers:
57
+
58
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
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 ; height of each layer
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
65
  G1 X0 Y500 Z0 ; move to the starting point
66
66
  WHILE (layer <= n_layers)
67
67
  X=IC(size)
@@ -70,13 +70,12 @@ WHILE (layer <= n_layers)
70
70
  Y=IC(-size) Z=IC(layer_height)
71
71
  layer = layer + 1
72
72
  ENDWHILE
73
- M31; end of program
74
- ```
73
+ M31 ; end of program
75
74
 
76
75
 
77
76
  ### CLI Usage
78
77
  ```bash
79
- > cargo run -- --help
78
+ $ cargo run -- --help
80
79
  A G-code interpreter
81
80
 
82
81
  Usage: nc-gcode-interpreter [OPTIONS] <input>
@@ -87,13 +86,13 @@ Arguments:
87
86
  Options:
88
87
  -a, --axes <AXIS> Override default axis identifiers (comma-separated, e.g., "X,Y,Z")
89
88
  -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
89
+ -i, --initial_state <INITIAL_STATE> Optional initial state file to e.g. define global variables or set axis positions
91
90
  -l, --iteration_limit <LIMIT> Maximum number of iterations for loops [default: 10000]
92
91
  -f, --disable-forward-fill Disable forward-filling of null values in axes columns
93
92
  -h, --help Print help
94
93
  -V, --version Print version
95
94
 
96
- > cargo run -- Example.MPF
95
+ $ cargo run -- Example.MPF
97
96
  ```
98
97
 
99
98
  ```csv
@@ -117,6 +116,13 @@ X ,Y ,Z ,F ,M ,gg01_motion ,comment
117
116
 
118
117
  ### python example
119
118
 
119
+ To install the Python bindings, run:
120
+ ```bash
121
+ pip install nc-gcode-interpreter
122
+ ```
123
+
124
+ Then, you can use the Python bindings to convert an MPF file to a DataFrame:
125
+
120
126
  ```bash
121
127
  python -c "\
122
128
  from nc_gcode_interpreter import nc_to_dataframe; \
@@ -143,6 +149,17 @@ shape: (14, 7)
143
149
  └───────┴───────┴──────┴────────┴───────────┴─────────────┴─────────────────────────────────┘
144
150
  ```
145
151
 
152
+ The Python bindings also return the state of the program after execution, which can be used for inspection.
153
+
154
+ Additionally, conversion from a Polars DataFrame back to an MPF (NC) program is also supported:
155
+
156
+ ```bash
157
+ python -c "\
158
+ from nc_gcode_interpreter import nc_to_dataframe, dataframe_to_nc; \
159
+ from pathlib import Path; \
160
+ df, state = nc_to_dataframe(Path('Example.MPF').open(), extra_axes=['ELX']); \
161
+ dataframe_to_nc(df, Path('Example_out.MPF').open('w'))"
162
+ ```
146
163
 
147
164
  ```bash
148
165
  target/release/nc-gcode-interpreter --help
@@ -165,7 +182,7 @@ Options:
165
182
 
166
183
  ## Why?
167
184
 
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.
185
+ The Sinumerik NC programming guide is extensive, and some of its functionality can be very convenient for making on-the-fly improvements to code. However, to better understand, 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.
169
186
 
170
187
  Only a limited subset is supported, but the tool is designed to be easily extensible to support more features in the future.
171
188
 
@@ -1,43 +1,41 @@
1
1
  # NC-GCode-Interpreter
2
2
 
3
- 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.
3
+ A robust interpreter designed for processing Sinumerik-flavored NC G-code, capable of converting MPF files into CSV outputs or Polars DataFrames via Python bindings.
4
4
 
5
5
  ## Overview
6
6
 
7
- 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.
7
+ The **NC-GCode-Interpreter** offers a streamlined and efficient solution for interpreting G-code specifically tailored to Sinumerik specifications. This tool caters to both command-line interface (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.
8
8
 
9
9
  ## Features
10
10
 
11
11
  ### Supported G-code Features
12
12
 
13
- - **G Group Commands**: Recognizes G-code groups and modal gcode commands.
14
- - **Global Translations**: Supports commands like TRANS and ATRANS for adjusting coordinates globally.
15
- - **Looping Constructs**: Handles loops using WHILE and FOR statements.
13
+ - **G Group Commands**: Recognizes G-code groups and modal G-code commands.
14
+ - **Global Transformations**: Supports commands like `TRANS` and `ATRANS` for adjusting coordinates globally.
15
+ - **Looping Constructs**: Handles loops using `WHILE` and `FOR` statements.
16
16
  - **Variable Handling**: Supports definition and manipulation of local variables.
17
- - **Conditional Logic**: Implements conditional execution with IF, ELSE, and ENDIF.
18
- - **Arithmetic Operations**: Basic operations such as addition, subtraction, multiplication, and division are supported.
17
+ - **Conditional Logic**: Implements conditional execution with `IF`, `ELSE`, and `ENDIF`.
18
+ - **Arithmetic Operations**: Supports basic operations such as addition, subtraction, multiplication, and division.
19
19
  - **Array Operations**: Manages arrays and allows operations on them.
20
- - **Incremental Changes**: Facilitates incremental changes in axes positions like X=IC(2).
20
+ - **Incremental Changes**: Facilitates incremental changes in axes positions like `X=IC(2)`.
21
21
 
22
22
  ### Additional Functionality
23
23
 
24
- - **Custom Axes**: Allows users to define additional axes beyond the standard X, Y, Z.
24
+ - **Custom Axes**: Allows users to define additional axes beyond the standard `X`, `Y`, `Z`.
25
25
  - **Initial State Configuration**: Enables the use of an initial state MPF file to set default values for multiple runs.
26
- - **CLI Options**: Numerous command-line options to customize the processing like axis overriding, loop limits, and more.
27
-
28
-
26
+ - **CLI Options**: Numerous command-line options to customize the processing, such as axis overriding, loop limits, and more.
29
27
 
30
28
  ## Example Usage
31
29
 
32
-
33
30
  Consider this example program to generate a square in two layers:
31
+
34
32
  ```scheme
35
- ;Example.MPF
36
- DEF INT n_layers = 2, layer=1
37
- DEF REAL size = 100 ;size of the square
38
- DEF REAL layer_height = 4 ;size of the square
39
- TRANS Z = 0.5 ; move up all z coordinates by 0.5
40
- G1 F=1000; Set feed rate in millimeters per minute
33
+ ; Example.MPF
34
+ DEF INT n_layers = 2, layer = 1
35
+ DEF REAL size = 100 ; size of the square
36
+ DEF REAL layer_height = 4 ; height of each layer
37
+ TRANS Z = 0.5 ; move up all Z coordinates by 0.5
38
+ G1 F=1000 ; Set feed rate in millimeters per minute
41
39
  G1 X0 Y500 Z0 ; move to the starting point
42
40
  WHILE (layer <= n_layers)
43
41
  X=IC(size)
@@ -46,13 +44,12 @@ WHILE (layer <= n_layers)
46
44
  Y=IC(-size) Z=IC(layer_height)
47
45
  layer = layer + 1
48
46
  ENDWHILE
49
- M31; end of program
50
- ```
47
+ M31 ; end of program
51
48
 
52
49
 
53
50
  ### CLI Usage
54
51
  ```bash
55
- > cargo run -- --help
52
+ $ cargo run -- --help
56
53
  A G-code interpreter
57
54
 
58
55
  Usage: nc-gcode-interpreter [OPTIONS] <input>
@@ -63,13 +60,13 @@ Arguments:
63
60
  Options:
64
61
  -a, --axes <AXIS> Override default axis identifiers (comma-separated, e.g., "X,Y,Z")
65
62
  -e, --extra-axes <EXTRA_AXIS> Add extra axis identifiers (comma-separated, e.g., "RA1,RA2")
66
- -i, --initial_state <INITIAL_STATE> Optional initial_state file to initialize state
63
+ -i, --initial_state <INITIAL_STATE> Optional initial state file to e.g. define global variables or set axis positions
67
64
  -l, --iteration_limit <LIMIT> Maximum number of iterations for loops [default: 10000]
68
65
  -f, --disable-forward-fill Disable forward-filling of null values in axes columns
69
66
  -h, --help Print help
70
67
  -V, --version Print version
71
68
 
72
- > cargo run -- Example.MPF
69
+ $ cargo run -- Example.MPF
73
70
  ```
74
71
 
75
72
  ```csv
@@ -93,6 +90,13 @@ X ,Y ,Z ,F ,M ,gg01_motion ,comment
93
90
 
94
91
  ### python example
95
92
 
93
+ To install the Python bindings, run:
94
+ ```bash
95
+ pip install nc-gcode-interpreter
96
+ ```
97
+
98
+ Then, you can use the Python bindings to convert an MPF file to a DataFrame:
99
+
96
100
  ```bash
97
101
  python -c "\
98
102
  from nc_gcode_interpreter import nc_to_dataframe; \
@@ -119,6 +123,17 @@ shape: (14, 7)
119
123
  └───────┴───────┴──────┴────────┴───────────┴─────────────┴─────────────────────────────────┘
120
124
  ```
121
125
 
126
+ The Python bindings also return the state of the program after execution, which can be used for inspection.
127
+
128
+ Additionally, conversion from a Polars DataFrame back to an MPF (NC) program is also supported:
129
+
130
+ ```bash
131
+ python -c "\
132
+ from nc_gcode_interpreter import nc_to_dataframe, dataframe_to_nc; \
133
+ from pathlib import Path; \
134
+ df, state = nc_to_dataframe(Path('Example.MPF').open(), extra_axes=['ELX']); \
135
+ dataframe_to_nc(df, Path('Example_out.MPF').open('w'))"
136
+ ```
122
137
 
123
138
  ```bash
124
139
  target/release/nc-gcode-interpreter --help
@@ -141,7 +156,7 @@ Options:
141
156
 
142
157
  ## Why?
143
158
 
144
- 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.
159
+ The Sinumerik NC programming guide is extensive, and some of its functionality can be very convenient for making on-the-fly improvements to code. However, to better understand, 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.
145
160
 
146
161
  Only a limited subset is supported, but the tool is designed to be easily extensible to support more features in the future.
147
162
 
@@ -0,0 +1,3 @@
1
+ gg01_motion,X,function_call
2
+ ,,SETAL(12345)
3
+ G1,1.000,
@@ -0,0 +1,2 @@
1
+ SETAL(12345)
2
+ G1 X1
@@ -0,0 +1,13 @@
1
+ DEF INT aa=1
2
+ IF TRUE
3
+ X1
4
+ ELSE
5
+ IF aa
6
+ X5
7
+ ELSE
8
+ X3
9
+ Y32
10
+ ENDIF
11
+ ENDIF
12
+
13
+