nc-gcode-interpreter 0.4.1__tar.gz → 0.4.2__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.
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/CHANGELOG.md +37 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/Cargo.lock +1 -1
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/Cargo.toml +1 -1
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/PKG-INFO +1 -1
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/README.md +1 -1
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/__init__.py +12 -8
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/_internal.pyi +1 -1
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_batch_variables.py +1 -1
- nc_gcode_interpreter-0.4.2/python/tests/test_frame_scale_mirror.py +244 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_frames.py +3 -3
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_g_groups.py +2 -2
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_start_inputs.py +2 -2
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_unsupported.py +18 -9
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/frame.rs +95 -21
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/grammar.pest +3 -2
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/interpret_rules.rs +226 -78
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/lib.rs +2 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/line_driver.rs +2 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/main.rs +1 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/start.rs +26 -21
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/state.rs +114 -39
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/tests/syntax_compatibility.rs +25 -1
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/.github/workflows/benchmark.yml +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/.github/workflows/build-and-release.yml +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/.gitignore +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/CONTRIBUTING.md +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/Development.md +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/LICENSE +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/TODO.md +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/benches/extensions.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/benches/fixtures.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/benches/workloads.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/build.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/build_backend/nc_build_backend.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/docs/resumable-interpretation-design.md +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/docs/sinumerik-execution-model.md +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/actual_position.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/actual_position.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/arc.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/arc.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/arrays.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/arrays.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/axis_index_assignment.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/axis_index_assignment.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/basic_math.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/basic_math.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/case.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/case.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/case_insensitive_variables.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/case_insensitive_variables.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/custom_vars.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/custom_vars.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/def_string.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/def_string.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/defaults.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/defaults.def +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/defaults.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/defaults_start.json +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/edge_cases.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/edge_cases.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/flattening/flatten_demo.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/flattening/flatten_demo_flattened.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/flattening/flatten_demo_raw.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/for_loop.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/for_loop.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/function_calls.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/function_calls.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/goto.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/goto.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/if_statement.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/if_statement.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/increment.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/increment.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/logic_operators.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/logic_operators.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/loop.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/loop.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/multiple_m_codes.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/multiple_m_codes.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/precedence.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/precedence.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/r_param.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/r_param.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/repeat.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/repeat.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/rot.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/rot.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/simple.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/simple.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/spline.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/spline.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/tool.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/tool.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/trans.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/trans.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/trans2.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/trans2.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/trans_ic.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/trans_ic.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/trans_reset.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/trans_reset.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/trig.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/trig.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/variables.csv +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/examples/variables.mpf +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/ggroups/generate_g_commands.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/pyproject.toml +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/example/minimal.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/example/streaming.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/cli.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/ggroups.json +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/py.typed +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/viz.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/nc_source.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_arithmetic_functions.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_batches.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_bspline_pl.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_build_backend.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_compare_benchmarks.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_diagnostics.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_expected_output.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_feed_check.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_feed_group.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_field_defects.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_flags.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_flatten.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_frame_columns.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_g_group_enum.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_g_vocabulary.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_jumps.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_preset.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_real_comparisons.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_stage1.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_streaming.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_string_operations.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_structured_errors.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_subprograms.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/rustfmt.toml +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/scripts/benchmark.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/scripts/compare_benchmarks.py +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/errors.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/flatten.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/interpreter.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/line_driver/experiments.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/modal_groups.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/output.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/structure_scan.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/subprogram.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/types.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/src/vm.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/tests/cli.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/tests/performance_contract.rs +0 -0
- {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/uv.lock +0 -0
|
@@ -4,6 +4,43 @@ Notable changes to **nc-gcode-interpreter**. The format loosely follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/); versions are git tags,
|
|
5
5
|
released to PyPI.
|
|
6
6
|
|
|
7
|
+
## [v0.4.2] - 2026-11-28
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Numeric literals accept the Siemens exponent notation `<mantissa>EX<exponent>`
|
|
12
|
+
(#117), for example `X=-.1EX-3`, `R1=1.874EX8` and `8.2EX-3`, in every place
|
|
13
|
+
a literal is accepted. A plain `E` exponent stays an error.
|
|
14
|
+
- `SCALE`/`ASCALE` and `MIRROR`/`AMIRROR` with arguments are interpreted for
|
|
15
|
+
the geometry axes X, Y, Z (#134). They chain onto the programmable frame as
|
|
16
|
+
machine XYZ = R * S * M * local XYZ + t, so an `ATRANS` after a scale is
|
|
17
|
+
scaled and an `AMIRROR` of a mirrored axis switches the mirror off (the
|
|
18
|
+
toggle behaviour of MD10612 = 0). The `rotation` in the final state and the
|
|
19
|
+
`frame_r11` to `frame_r33` columns hold the rotation with the scale and
|
|
20
|
+
mirror factors folded in. A circular arc is accepted under a frame that
|
|
21
|
+
keeps it a circle with the same direction (its `I`/`J`/`K` and `CR` are
|
|
22
|
+
scaled); an in-plane mirror or unequal in-plane factors under an arc raise
|
|
23
|
+
an error, as does a rotation chained after unequal scale factors.
|
|
24
|
+
- `SCALE`/`ASCALE` also scale every other configured axis, such as an
|
|
25
|
+
extruder axis `E` (#134; manual 3.12.2.6 scales all path, synchronized and
|
|
26
|
+
positioning axes): machine = factor * local + t, `ASCALE` multiplies the
|
|
27
|
+
factor, an `ATRANS` after it is scaled and an absolute frame instruction
|
|
28
|
+
resets it. The factors are in the final state as `axis_scale`, which
|
|
29
|
+
`start` accepts.
|
|
30
|
+
- `ROTS`/`AROTS`/`CROTS` with one solid angle, which is the same rotation as
|
|
31
|
+
`ROT`/`AROT` about that axis (#134). Two solid angles still raise an error,
|
|
32
|
+
because the manuals describe that form in two ways that give different
|
|
33
|
+
rotations.
|
|
34
|
+
- `start['rotation']` accepts a rotation with scale and mirror factors, so a
|
|
35
|
+
final state with an active `SCALE` or `MIRROR` can be resumed.
|
|
36
|
+
|
|
37
|
+
### Changed
|
|
38
|
+
|
|
39
|
+
- `TOFRAME`, `TOROT` (with their `X`/`Y`/`Z` variants) and `PAROT` raise an
|
|
40
|
+
"unsupported statement" error (#134). They were accepted without effect
|
|
41
|
+
before, so the blocks after them were read in the wrong frame without a
|
|
42
|
+
warning. `TOROTOF` and `PAROTOF` are still accepted.
|
|
43
|
+
|
|
7
44
|
## [v0.4.1] - 2026-11-24
|
|
8
45
|
|
|
9
46
|
### Added
|
|
@@ -11,7 +11,7 @@ The **NC-GCode-Interpreter** offers a streamlined and efficient solution for int
|
|
|
11
11
|
### Supported G-code Features
|
|
12
12
|
|
|
13
13
|
- **G Group Commands**: Recognizes G-code groups and modal G-code commands.
|
|
14
|
-
- **Programmable frames**: `TRANS`/`ATRANS` work offsets
|
|
14
|
+
- **Programmable frames**: `TRANS`/`ATRANS` work offsets, `ROT`/`AROT` rotations (`X.. Y.. Z..` RPY angles or `RPL=` in the active plane), `SCALE`/`ASCALE` factors for every configured axis, and `MIRROR`/`AMIRROR` for the geometry axes X, Y, Z; output coordinates are machine coordinates with the frame applied, and the final state reports the `translation`, the `rotation` (with the X, Y, Z scale and mirror folded in) and the `axis_scale` of the other axes. `ROTS`/`AROTS`/`CROTS` take one solid angle; two solid angles, `TOFRAME`, `TOROT` and `PAROT` raise an error.
|
|
15
15
|
- **Looping Constructs**: Handles loops using `WHILE`, `FOR`, `REPEAT ... UNTIL` and `LOOP ... ENDLOOP` statements.
|
|
16
16
|
- **Variable Handling**: Supports definition and manipulation of local variables.
|
|
17
17
|
- **Conditional Logic**: Implements conditional execution with `IF`, `ELSE`, and `ENDIF`.
|
{nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/__init__.py
RENAMED
|
@@ -167,7 +167,8 @@ def nc_to_dataframe(
|
|
|
167
167
|
start: Mapping | None, optional
|
|
168
168
|
The machine state at program start, in the shape of the returned state
|
|
169
169
|
dict, so a returned state can be passed back. Keys: ``axes`` and
|
|
170
|
-
``translation`` (dict[str, float]), ``rotation`` (3x3), ``
|
|
170
|
+
``translation`` (dict[str, float]), ``rotation`` (3x3), ``axis_scale``
|
|
171
|
+
(SCALE factor per non-geometry axis, dict[str, float]), ``symbol_table``
|
|
171
172
|
(dict[str, float]), ``string_table`` (dict[str, str]), ``g_groups``
|
|
172
173
|
(modal G group column to code, e.g. ``{"gg01_motion": "G1"}``),
|
|
173
174
|
``feed`` (float; pass the control's default feed SD42110
|
|
@@ -207,10 +208,13 @@ def nc_to_dataframe(
|
|
|
207
208
|
forward-filled; `dataframe_to_nc` ignores it. Default False (column
|
|
208
209
|
absent, output schema unchanged).
|
|
209
210
|
include_frame: bool, optional
|
|
210
|
-
If True, add the programmable frame (TRANS
|
|
211
|
-
active on each row as twelve Float64
|
|
212
|
-
`frame_r33`, the
|
|
213
|
-
`frame_tz`, the translation t, in machine XYZ
|
|
211
|
+
If True, add the programmable frame (TRANS, ROT, SCALE, MIRROR and
|
|
212
|
+
their additive forms) that is active on each row as twelve Float64
|
|
213
|
+
columns: `frame_r11` to `frame_r33`, the linear part R row by row, and
|
|
214
|
+
`frame_tx`, `frame_ty`, `frame_tz`, the translation t, in machine XYZ
|
|
215
|
+
= R * local XYZ + t. R is the rotation with the scale and mirror
|
|
216
|
+
factors folded in, so it is a pure rotation only while no SCALE or
|
|
217
|
+
MIRROR is active.
|
|
214
218
|
The values are written on the first row and on the first row after
|
|
215
219
|
each change, and forward-filled like the axis columns; with
|
|
216
220
|
`disable_forward_fill` the other rows are null. Programmed A/B/C
|
|
@@ -603,8 +607,8 @@ def nc_to_rows(
|
|
|
603
607
|
|
|
604
608
|
Errors raise ``ValueError`` from ``next()`` when reached. After the
|
|
605
609
|
iterator is exhausted, its ``state`` attribute holds the final
|
|
606
|
-
interpreter state (axes, symbol_table, translation, rotation,
|
|
607
|
-
g_groups, feed, tool, transformation, fgroup, fgref).
|
|
610
|
+
interpreter state (axes, symbol_table, translation, rotation, axis_scale,
|
|
611
|
+
string_table, g_groups, feed, tool, transformation, fgroup, fgref).
|
|
608
612
|
|
|
609
613
|
Example:
|
|
610
614
|
--------
|
|
@@ -645,7 +649,7 @@ class _BatchIterator:
|
|
|
645
649
|
no Python list of primitives materialized. ``pl.DataFrame`` wraps that
|
|
646
650
|
capsule directly (polars >= 1.3), so no ``pyarrow`` is involved. After
|
|
647
651
|
exhaustion its ``state`` attribute holds the final interpreter state (axes,
|
|
648
|
-
symbol_table, translation, rotation, string_table, g_groups, feed, tool,
|
|
652
|
+
symbol_table, translation, rotation, axis_scale, string_table, g_groups, feed, tool,
|
|
649
653
|
transformation, fgroup, fgref), like
|
|
650
654
|
the iterator returned by :func:`nc_to_rows`.
|
|
651
655
|
"""
|
{nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/_internal.pyi
RENAMED
|
@@ -66,7 +66,7 @@ def nc_to_batches(
|
|
|
66
66
|
"""Interpret an NC program into an iterator of columnar polars DataFrames.
|
|
67
67
|
|
|
68
68
|
The returned iterator exposes ``state`` (dict with ``axes``,
|
|
69
|
-
``symbol_table``, ``translation``, ``rotation``, ``string_table``,
|
|
69
|
+
``symbol_table``, ``translation``, ``rotation``, ``axis_scale``, ``string_table``,
|
|
70
70
|
``g_groups``, ``feed``, ``tool``, ``transformation``, ``fgroup`` and
|
|
71
71
|
``fgref``) once
|
|
72
72
|
exhausted, and
|
{nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.2}/python/tests/test_batch_variables.py
RENAMED
|
@@ -139,7 +139,7 @@ def test_string_table_round_trips_through_state_dict():
|
|
|
139
139
|
assert state["string_table"] == {"MSG": "HELLO WORLD", "TAG": "ABC"}
|
|
140
140
|
# The existing numeric sub-tables are untouched by the new key.
|
|
141
141
|
assert set(state) == {
|
|
142
|
-
"axes", "symbol_table", "translation", "rotation", "string_table", "g_groups", "feed",
|
|
142
|
+
"axes", "symbol_table", "translation", "rotation", "axis_scale", "string_table", "g_groups", "feed",
|
|
143
143
|
"tool", "transformation", "fgroup", "fgref",
|
|
144
144
|
}
|
|
145
145
|
# The string variable never leaks into the numeric symbol table.
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"""Programmable scaling, mirroring and solid-angle rotation.
|
|
2
|
+
|
|
3
|
+
Conventions under test (NC programming manual 3.12.2.5 to 3.12.2.7, Basic
|
|
4
|
+
Functions manual 4.5.2.11): machine XYZ = L * local XYZ + t with
|
|
5
|
+
L = rotation * scale * mirror; SCALE and MIRROR replace the whole programmable
|
|
6
|
+
frame, ASCALE and AMIRROR chain onto it; an offset programmed after a scale is
|
|
7
|
+
scaled; AMIRROR on a mirrored axis switches the mirror off (MD10612 = 0); one
|
|
8
|
+
solid angle is the same rotation as ROT about that axis.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import math
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
from nc_gcode_interpreter import nc_to_dataframe
|
|
15
|
+
from nc_source import nc_lines
|
|
16
|
+
|
|
17
|
+
IDENTITY = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
|
|
18
|
+
START = "G17 G1 X0 Y0 Z0 F1000"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@pytest.fixture(params=["0", "1"], autouse=True)
|
|
22
|
+
def stage1(request, monkeypatch):
|
|
23
|
+
monkeypatch.setenv("NC_STAGE1", request.param)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def run(*lines, **options):
|
|
27
|
+
return nc_to_dataframe(nc_lines(START, *lines), **options)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def xyz(df, row=-1):
|
|
31
|
+
return [df[axis][row] for axis in ("X", "Y", "Z")]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def flat(matrix):
|
|
35
|
+
return [value for row in matrix for value in row]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_scale_multiplies_the_programmed_coordinates():
|
|
39
|
+
df, state = run("SCALE X2 Y3", "G1 X1 Y1 Z1")
|
|
40
|
+
assert xyz(df) == pytest.approx([2.0, 3.0, 1.0])
|
|
41
|
+
assert state["rotation"] == [[2.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 1.0]]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_scale_is_absolute_and_ascale_is_additive():
|
|
45
|
+
df, _ = run("TRANS X10", "SCALE X2", "G1 X1", "ASCALE X3", "G1 X1", "SCALE X5", "G1 X1")
|
|
46
|
+
# SCALE deletes the TRANS; ASCALE multiplies the factor; SCALE replaces it.
|
|
47
|
+
assert df["X"].to_list()[1:] == pytest.approx([2.0, 6.0, 5.0])
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_scale_does_not_move_the_machine():
|
|
51
|
+
df, state = run("G1 X4 Y6", "SCALE X2 Y3", "G1 Z1")
|
|
52
|
+
assert xyz(df) == pytest.approx([4.0, 6.0, 1.0])
|
|
53
|
+
assert state["axes"]["X"] == pytest.approx(2.0)
|
|
54
|
+
assert state["axes"]["Y"] == pytest.approx(2.0)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_offset_after_a_scale_is_scaled():
|
|
58
|
+
# Manual 3.12.2.6, note "Work offset after scaling".
|
|
59
|
+
df, state = run("TRANS X10", "ASCALE X2", "ATRANS X5", "G1 X1")
|
|
60
|
+
assert df["X"][-1] == pytest.approx(10.0 + 2.0 * (5.0 + 1.0))
|
|
61
|
+
assert state["translation"]["X"] == pytest.approx(20.0)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_manual_example_offset_rotation_and_scale():
|
|
65
|
+
# Manual 3.12.2.6 example 2: TRANS X40 Y20, AROT RPL=35, ASCALE X0.7 Y0.7.
|
|
66
|
+
df, _ = run("TRANS X40 Y20", "AROT RPL=35", "ASCALE X0.7 Y0.7", "G1 X10 Y5")
|
|
67
|
+
c, s = math.cos(math.radians(35)), math.sin(math.radians(35))
|
|
68
|
+
assert xyz(df)[:2] == pytest.approx([40 + 0.7 * (10 * c - 5 * s), 20 + 0.7 * (10 * s + 5 * c)])
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_rotation_after_equal_factors_is_accepted():
|
|
72
|
+
df, _ = run("SCALE X2 Y2", "AROT Z90", "G1 X1 Y0")
|
|
73
|
+
assert xyz(df)[:2] == pytest.approx([0.0, 2.0], abs=1e-12)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@pytest.mark.parametrize("block", ["SCALE X0", "SCALE X-1", "ASCALE Y0"])
|
|
77
|
+
def test_scale_factor_must_be_positive(block):
|
|
78
|
+
with pytest.raises(ValueError, match="must be greater than 0"):
|
|
79
|
+
run(block, "G1 X1")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_mirror_reverses_the_programmed_axis():
|
|
83
|
+
df, state = run("MIRROR X0", "G1 X1 Y2 Z3")
|
|
84
|
+
assert xyz(df) == pytest.approx([-1.0, 2.0, 3.0])
|
|
85
|
+
assert state["rotation"] == [[-1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_mirror_value_is_not_evaluated():
|
|
89
|
+
df, _ = run("MIRROR X1 Y=5", "G1 X1 Y2")
|
|
90
|
+
assert xyz(df)[:2] == pytest.approx([-1.0, -2.0])
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def test_manual_example_four_mirrored_contours():
|
|
94
|
+
# Manual 3.12.2.7 example 1: MIRROR X0, AMIRROR Y0, MIRROR Y0, MIRROR.
|
|
95
|
+
df, state = run(
|
|
96
|
+
"G1 X1 Y2", "MIRROR X0", "G1 X1 Y2", "AMIRROR Y0", "G1 X1 Y2", "MIRROR Y0", "G1 X1 Y2", "MIRROR", "G1 X1 Y2"
|
|
97
|
+
)
|
|
98
|
+
points = list(zip(df["X"].to_list()[1:], df["Y"].to_list()[1:], strict=True))
|
|
99
|
+
assert points == [(1.0, 2.0), (-1.0, 2.0), (-1.0, -2.0), (1.0, -2.0), (1.0, 2.0)]
|
|
100
|
+
assert state["rotation"] == IDENTITY
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_second_amirror_switches_the_mirror_off():
|
|
104
|
+
df, state = run("MIRROR X0", "AMIRROR X0", "G1 X1")
|
|
105
|
+
assert df["X"][-1] == pytest.approx(1.0)
|
|
106
|
+
assert state["rotation"] == IDENTITY
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_manual_example_mirror_then_offset():
|
|
110
|
+
# Manual 3.12.2.7 example 2: TRANS X0 Z600, AMIRROR Z0, ATRANS Z120.
|
|
111
|
+
df, _ = run("TRANS X0 Z600", "AMIRROR Z0", "ATRANS Z120", "G1 Z10")
|
|
112
|
+
assert df["Z"][-1] == pytest.approx(600.0 - 120.0 - 10.0)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def test_rotation_after_a_mirror_turns_the_other_way():
|
|
116
|
+
# Manual 3.12.2.7, note on AROT after MIRROR: Mx * Rz(a) = Rz(-a) * Mx.
|
|
117
|
+
mirrored_first, _ = run("MIRROR X0", "AROT Z30", "G1 X1 Y2 Z3")
|
|
118
|
+
rotated_first, _ = run("ROT Z-30", "AMIRROR X0", "G1 X1 Y2 Z3")
|
|
119
|
+
assert xyz(mirrored_first) == pytest.approx(xyz(rotated_first), abs=1e-12)
|
|
120
|
+
same_sign, _ = run("ROT Z30", "AMIRROR X0", "G1 X1 Y2 Z3")
|
|
121
|
+
assert xyz(mirrored_first) != pytest.approx(xyz(same_sign), abs=1e-6)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@pytest.mark.parametrize("op", ["ROTS", "CROTS"])
|
|
125
|
+
@pytest.mark.parametrize("word", ["X30", "Y-40", "Z=25"])
|
|
126
|
+
def test_one_solid_angle_equals_rot(op, word):
|
|
127
|
+
solid, state = run("TRANS X10", f"{op} {word}", "G1 X1 Y2 Z3")
|
|
128
|
+
plain, expected = run("TRANS X10", f"ROT {word}", "G1 X1 Y2 Z3")
|
|
129
|
+
assert xyz(solid) == pytest.approx(xyz(plain), abs=1e-12)
|
|
130
|
+
assert flat(state["rotation"]) == pytest.approx(flat(expected["rotation"]), abs=1e-12)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def test_arots_chains_onto_the_frame():
|
|
134
|
+
solid, _ = run("TRANS X10", "AROT Z20", "AROTS X30", "G1 X1 Y2 Z3")
|
|
135
|
+
plain, _ = run("TRANS X10", "AROT Z20", "AROT X30", "G1 X1 Y2 Z3")
|
|
136
|
+
assert xyz(solid) == pytest.approx(xyz(plain), abs=1e-12)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def test_three_solid_angles_are_rejected():
|
|
140
|
+
with pytest.raises(ValueError, match="at most two solid angles"):
|
|
141
|
+
run("ROTS X10 Y10 Z10", "G1 X1")
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@pytest.mark.parametrize("block", ["ASCALE", "AMIRROR", "AROTS"])
|
|
145
|
+
def test_bare_additive_instruction_keeps_the_frame(block):
|
|
146
|
+
df, _ = run("TRANS X10", block, "G1 X5")
|
|
147
|
+
assert df["X"][-1] == pytest.approx(15.0)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
@pytest.mark.parametrize("block", ["SCALE", "MIRROR", "ROTS", "CROTS"])
|
|
151
|
+
def test_bare_absolute_instruction_deletes_the_frame(block):
|
|
152
|
+
df, state = run("TRANS X10", "ASCALE X2", block, "G1 X5")
|
|
153
|
+
assert df["X"][-1] == pytest.approx(5.0)
|
|
154
|
+
assert state["rotation"] == IDENTITY
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def test_combined_chain_matches_the_composed_matrices():
|
|
158
|
+
df, state = run("TRANS X10 Y20", "AROT Z90", "ASCALE X2 Y2 Z3", "AMIRROR Y0", "ATRANS X1 Y1 Z1", "G1 X1 Y1 Z1")
|
|
159
|
+
# L = Rz(90) * diag(2, 2, 3) * diag(1, -1, 1), t = (10, 20, 0) + L * (1, 1, 1).
|
|
160
|
+
assert flat(state["rotation"]) == pytest.approx([0, 2, 0, 2, 0, 0, 0, 0, 3], abs=1e-12)
|
|
161
|
+
assert xyz(df) == pytest.approx([10 + 2 * 2, 20 + 2 * 2, 3 * 2], abs=1e-12)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def test_frame_columns_hold_scale_and_mirror():
|
|
165
|
+
df, _ = run("SCALE X2", "AMIRROR Y0", "G1 X1 Y1", include_frame=True)
|
|
166
|
+
row = df.row(-1, named=True)
|
|
167
|
+
assert [row["frame_r11"], row["frame_r22"], row["frame_r33"]] == [2.0, -1.0, 1.0]
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def test_final_state_with_scale_and_mirror_resumes():
|
|
171
|
+
_, state = run("TRANS X10", "ASCALE X2", "AMIRROR Y0", "G1 X1 Y1")
|
|
172
|
+
df, _ = nc_to_dataframe("G1 X3 Y3", start=state)
|
|
173
|
+
assert (df["X"][-1], df["Y"][-1]) == pytest.approx((16.0, -3.0))
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def test_arc_under_a_uniform_scale_scales_centre_and_radius():
|
|
177
|
+
df, _ = run("SCALE X2 Y2", "G1 X1 Y0", "G2 X3 Y0 I1 J0", "G2 X5 Y0 CR=1")
|
|
178
|
+
assert (df["I"][-2], df["J"][-2]) == pytest.approx((2.0, 0.0))
|
|
179
|
+
assert df["X"][-2] == pytest.approx(6.0)
|
|
180
|
+
assert df["CR"][-1] == pytest.approx(2.0)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
@pytest.mark.parametrize(
|
|
184
|
+
"frame",
|
|
185
|
+
["SCALE X2", "SCALE X2 Y3", "MIRROR X0", "MIRROR Y0"],
|
|
186
|
+
)
|
|
187
|
+
def test_arc_under_a_distorting_or_mirroring_frame_errors(frame):
|
|
188
|
+
with pytest.raises(ValueError, match="tilts, mirrors or unevenly scales the G17 plane"):
|
|
189
|
+
run(frame, "G1 X1 Y0", "G2 X3 Y0 I1 J0")
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def test_arc_ignores_scale_and_mirror_of_the_plane_normal():
|
|
193
|
+
df, _ = run("SCALE Z3", "AMIRROR Z0", "G1 X1 Y0 Z1", "G2 X3 Y0 I1 J0")
|
|
194
|
+
assert (df["X"][-1], df["I"][-1], df["Z"][-1]) == pytest.approx((3.0, 1.0, -3.0))
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def test_scaled_square_program():
|
|
198
|
+
# Manual 3.12.2.6: the contour is enlarged by the factors of the programmed axes.
|
|
199
|
+
square = ["G1 X10 Y0", "G1 X10 Y10", "G1 X0 Y10", "G1 X0 Y0"]
|
|
200
|
+
df, _ = run("TRANS X5 Y5", "ASCALE X2 Y2", *square)
|
|
201
|
+
points = list(zip(df["X"].to_list()[-4:], df["Y"].to_list()[-4:], strict=True))
|
|
202
|
+
assert points == [(25, 5), (25, 25), (5, 25), (5, 5)]
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def test_scale_applies_to_a_non_geometry_axis():
|
|
206
|
+
# Manual 3.12.2.6 scales all path, synchronized and positioning axes, not only X, Y, Z.
|
|
207
|
+
df, state = run("G1 E0", "SCALE E1.5", "G1 X1 E10", "G1 E=IC(2)", "G1 E4")
|
|
208
|
+
assert df["E"].to_list()[-3:] == pytest.approx([15.0, 18.0, 6.0])
|
|
209
|
+
assert df["X"][-3] == pytest.approx(1.0)
|
|
210
|
+
assert state["axes"]["E"] == pytest.approx(4.0)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def test_ascale_multiplies_and_bare_scale_resets_a_non_geometry_axis():
|
|
214
|
+
df, _ = run("SCALE E2", "G1 E1", "ASCALE E3", "G1 E1", "SCALE", "G1 E1")
|
|
215
|
+
assert df["E"].to_list()[-3:] == pytest.approx([2.0, 6.0, 1.0])
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def test_offset_after_a_scale_is_scaled_on_a_non_geometry_axis():
|
|
219
|
+
df, state = run("TRANS E10", "ASCALE E2", "ATRANS E5", "G1 E1")
|
|
220
|
+
assert df["E"][-1] == pytest.approx(10.0 + 2.0 * (5.0 + 1.0))
|
|
221
|
+
assert state["translation"]["E"] == pytest.approx(20.0)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def test_scale_does_not_move_a_non_geometry_axis():
|
|
225
|
+
df, state = run("G1 E6", "SCALE E2", "G1 X1")
|
|
226
|
+
assert df["E"][-1] == pytest.approx(6.0)
|
|
227
|
+
assert state["axes"]["E"] == pytest.approx(3.0)
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def test_scale_of_an_unknown_axis_errors():
|
|
231
|
+
with pytest.raises(ValueError, match="not a configured axis"):
|
|
232
|
+
run("SCALE ELX=2", "G1 X1")
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def test_final_state_with_a_non_geometry_scale_resumes():
|
|
236
|
+
_, state = run("TRANS E1", "ASCALE E2", "G1 E3")
|
|
237
|
+
assert state["axis_scale"] == {"E": pytest.approx(2.0)}
|
|
238
|
+
df, _ = nc_to_dataframe("G1 E4", start=state)
|
|
239
|
+
assert df["E"][-1] == pytest.approx(9.0)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def test_start_axis_scale_rejects_a_geometry_axis():
|
|
243
|
+
with pytest.raises(ValueError, match="start\\['rotation'\\]"):
|
|
244
|
+
nc_to_dataframe("G1 X1 F100", start={"axis_scale": {"X": 2.0}})
|
|
@@ -287,17 +287,17 @@ def test_cr_arc_under_an_in_plane_rotation_matches_the_baked_arc():
|
|
|
287
287
|
def test_arc_under_a_tilting_rotation_errors(arc):
|
|
288
288
|
"""An arc whose plane no longer coincides with the machine plane is not
|
|
289
289
|
modeled; it must fail instead of flattening a wrong arc."""
|
|
290
|
-
with pytest.raises(ValueError, match="
|
|
290
|
+
with pytest.raises(ValueError, match="unevenly scales the G17 plane"):
|
|
291
291
|
nc_to_dataframe(nc_lines("G1 F1000 X0 Y0 Z0 F100", "AROT X30", arc))
|
|
292
292
|
# A half turn keeps the plane parallel but reverses it: also unsupported.
|
|
293
|
-
with pytest.raises(ValueError, match="
|
|
293
|
+
with pytest.raises(ValueError, match="unevenly scales the G17 plane"):
|
|
294
294
|
nc_to_dataframe(nc_lines("G1 F1000 X0 Y0 Z0 F100", "AROT Y180", arc))
|
|
295
295
|
|
|
296
296
|
|
|
297
297
|
def test_arc_in_another_plane_checks_that_plane():
|
|
298
298
|
# In G18 the normal is Y, so an RPL (about Y) is fine and an X tilt is not.
|
|
299
299
|
nc_to_dataframe(nc_lines("G18 G1 X0 Y0 Z0 F100", "AROT RPL=30", "G2 X10 Z0 I5 K0"))
|
|
300
|
-
with pytest.raises(ValueError, match="
|
|
300
|
+
with pytest.raises(ValueError, match="unevenly scales the G18 plane"):
|
|
301
301
|
nc_to_dataframe(nc_lines("G18 G1 X0 Y0 Z0 F100", "AROT X30", "G2 X10 Z0 I5 K0"))
|
|
302
302
|
|
|
303
303
|
|
|
@@ -49,12 +49,12 @@ def test_group_numbers_follow_the_manual() -> None:
|
|
|
49
49
|
def test_renamed_and_added_commands_reach_their_columns() -> None:
|
|
50
50
|
from nc_gcode_interpreter import nc_to_dataframe
|
|
51
51
|
|
|
52
|
-
program = "DYNFINISH\nWALCS1\
|
|
52
|
+
program = "DYNFINISH\nWALCS1\nTOROTOF\nTOWWCS\nG646\nCOMPPATH\nORIAXESFR\nCUT3DCP\nSPIF2\nG1 X1 F100\n"
|
|
53
53
|
df, _ = nc_to_dataframe(program)
|
|
54
54
|
last = df.row(-1, named=True)
|
|
55
55
|
assert last["gg59_dyn_resp_path"] == "DYNFINISH"
|
|
56
56
|
assert last["gg60_area_limit"] == "WALCS1"
|
|
57
|
-
assert last["gg53_frame_rot_tool"] == "
|
|
57
|
+
assert last["gg53_frame_rot_tool"] == "TOROTOF"
|
|
58
58
|
assert last["gg56_tool_wear"] == "TOWWCS"
|
|
59
59
|
assert last["gg10_exact_stop_mode"] == "G646"
|
|
60
60
|
assert last["gg30_nc_compress"] == "COMPPATH"
|
|
@@ -135,8 +135,8 @@ def test_start_seeds_every_entry_point():
|
|
|
135
135
|
{"g_groups": {"gg02_wait": "G4"}},
|
|
136
136
|
{"g_groups": {"motion": "G1"}},
|
|
137
137
|
{"axes": {"Q": 1.0}},
|
|
138
|
-
{"rotation": [[
|
|
139
|
-
{"rotation": [[
|
|
138
|
+
{"rotation": [[1, 1, 0], [0, 1, 0], [0, 0, 1]]},
|
|
139
|
+
{"rotation": [[0, 0, 0], [0, 1, 0], [0, 0, 1]]},
|
|
140
140
|
],
|
|
141
141
|
)
|
|
142
142
|
def test_invalid_start_values_are_errors(start):
|
|
@@ -5,25 +5,34 @@ from nc_gcode_interpreter import nc_to_dataframe
|
|
|
5
5
|
@pytest.mark.parametrize(
|
|
6
6
|
"program",
|
|
7
7
|
[
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
8
|
+
"ROTS X30 Y10\nX2", # two solid angles: the manuals disagree on the rotation
|
|
9
|
+
"CROTS X30 Y10\nX2",
|
|
10
|
+
"MIRROR A0\nX2",
|
|
11
|
+
"SCALE X2\nAROT Z30\nX2", # a rotation after unequal factors shears the frame
|
|
12
|
+
"TOFRAME\nX2", # frame rotations that follow the tool or workpiece orientation
|
|
13
|
+
"TOFRAMEZ\nX2",
|
|
14
|
+
"TOROT\nX2",
|
|
15
|
+
"torotx\nX2",
|
|
16
|
+
"PAROT\nX2",
|
|
17
|
+
"G1 F100 X1 TOROT",
|
|
15
18
|
],
|
|
16
|
-
ids=lambda p: p.splitlines()[
|
|
19
|
+
ids=lambda p: " / ".join(p.splitlines()[:-1]) or p,
|
|
17
20
|
)
|
|
18
21
|
def test_unsupported_statements_error_loudly(program):
|
|
19
22
|
"""
|
|
20
23
|
Statements that would silently corrupt the output (unmodeled frame
|
|
21
24
|
transformations) must raise instead of being ignored.
|
|
22
25
|
"""
|
|
23
|
-
with pytest.raises(ValueError, match="not supported"):
|
|
26
|
+
with pytest.raises(ValueError, match=r"not supported|geometry axes X, Y, Z only"):
|
|
24
27
|
nc_to_dataframe(program)
|
|
25
28
|
|
|
26
29
|
|
|
30
|
+
def test_switching_an_orientation_frame_off_is_accepted():
|
|
31
|
+
df, _state = nc_to_dataframe("TOROTOF\nPAROTOF\nX2")
|
|
32
|
+
assert df["gg53_frame_rot_tool"][-1] == "TOROTOF"
|
|
33
|
+
assert df["gg52_frame_rot_wp"][-1] == "PAROTOF"
|
|
34
|
+
|
|
35
|
+
|
|
27
36
|
@pytest.mark.parametrize(
|
|
28
37
|
"program",
|
|
29
38
|
[
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
//! Programmable frame rotation (ROT/AROT/RPL
|
|
1
|
+
//! Programmable frame rotation, scaling and mirroring (ROT/AROT/RPL,
|
|
2
|
+
//! SCALE/ASCALE, MIRROR/AMIRROR) for the geometry axes X, Y, Z.
|
|
2
3
|
//!
|
|
3
|
-
//! The frame is a
|
|
4
|
-
//! `State`: machine XYZ =
|
|
4
|
+
//! The frame is a linear part `L` plus the per-axis translation kept in
|
|
5
|
+
//! `State`: machine XYZ = L * local XYZ + t, with L = R * S * M (Basic
|
|
6
|
+
//! Functions manual 4.5.2.11). Only the geometry axes are transformed;
|
|
5
7
|
//! every other axis (A, B, C, E, ...) gets a translation at most, so programmed
|
|
6
8
|
//! orientation axes stay what the program wrote. The conventions here follow
|
|
7
9
|
//! the Sinumerik frame chapters cited at each function.
|
|
8
10
|
|
|
9
|
-
/// Row-major 3x3
|
|
11
|
+
/// Row-major 3x3 matrix over the geometry axes (0 = X, 1 = Y, 2 = Z).
|
|
10
12
|
pub type Matrix3 = [[f64; 3]; 3];
|
|
11
13
|
|
|
12
14
|
pub const IDENTITY: Matrix3 = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]];
|
|
@@ -84,23 +86,70 @@ pub fn apply(r: &Matrix3, v: [f64; 3]) -> [f64; 3] {
|
|
|
84
86
|
out
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
pub fn determinant(m: &Matrix3) -> f64 {
|
|
90
|
+
m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])
|
|
91
|
+
+ m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0])
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/// The inverse by cofactors, or `None` for a singular matrix (a zero scale).
|
|
95
|
+
pub fn inverse(m: &Matrix3) -> Option<Matrix3> {
|
|
96
|
+
let det = determinant(m);
|
|
97
|
+
if !det.is_finite() || det.abs() <= EPS {
|
|
98
|
+
return None;
|
|
92
99
|
}
|
|
93
|
-
out
|
|
100
|
+
let mut out = [[0.0; 3]; 3];
|
|
101
|
+
for (i, row) in out.iter_mut().enumerate() {
|
|
102
|
+
for (j, cell) in row.iter_mut().enumerate() {
|
|
103
|
+
let (r0, r1) = ((j + 1) % 3, (j + 2) % 3);
|
|
104
|
+
let (c0, c1) = ((i + 1) % 3, (i + 2) % 3);
|
|
105
|
+
*cell = (m[r0][c0] * m[r1][c1] - m[r0][c1] * m[r1][c0]) / det;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
Some(out)
|
|
94
109
|
}
|
|
95
110
|
|
|
96
|
-
|
|
97
|
-
|
|
111
|
+
/// Scaling (and, with a negative factor, mirroring) along the geometry axes.
|
|
112
|
+
pub fn scaling(factors: [f64; 3]) -> Matrix3 {
|
|
113
|
+
[[factors[0], 0.0, 0.0], [0.0, factors[1], 0.0], [0.0, 0.0, factors[2]]]
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/// True when the columns are mutually orthogonal, so the matrix is a rotation
|
|
117
|
+
/// times per-axis scale and mirror factors: the form R * S * M a Sinumerik
|
|
118
|
+
/// frame holds. A rotation chained after unequal scale factors shears the
|
|
119
|
+
/// axes and fails this.
|
|
120
|
+
pub fn columns_orthogonal(m: &Matrix3) -> bool {
|
|
121
|
+
(0..3).all(|a| {
|
|
122
|
+
(a + 1..3).all(|b| {
|
|
123
|
+
let dot: f64 = (0..3).map(|k| m[k][a] * m[k][b]).sum();
|
|
124
|
+
let scale: f64 = (0..3).map(|k| m[k][a].abs().max(m[k][b].abs())).fold(1.0, f64::max);
|
|
125
|
+
dot.abs() <= EPS * scale * scale
|
|
126
|
+
})
|
|
127
|
+
})
|
|
98
128
|
}
|
|
99
129
|
|
|
100
|
-
/// True when the
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
130
|
+
/// True when the frame mixes geometry axis `axis` with another one, in either direction.
|
|
131
|
+
pub fn couples_axis(m: &Matrix3, axis: usize) -> bool {
|
|
132
|
+
(0..3).any(|other| other != axis && (m[axis][other].abs() > EPS || m[other][axis].abs() > EPS))
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/// The scale factor of the plane with normal `normal` when the frame maps that
|
|
136
|
+
/// plane onto itself by a rotation and one positive factor, so a circle stays
|
|
137
|
+
/// a circle with the same sense of rotation. `None` for a tilted plane,
|
|
138
|
+
/// unequal in-plane factors or an in-plane mirror.
|
|
139
|
+
pub fn plane_similarity(m: &Matrix3, normal: usize) -> Option<f64> {
|
|
140
|
+
if couples_axis(m, normal) {
|
|
141
|
+
return None;
|
|
142
|
+
}
|
|
143
|
+
let (a, b) = ((normal + 1) % 3, (normal + 2) % 3);
|
|
144
|
+
let (p, q, r, s) = (m[a][a], m[a][b], m[b][a], m[b][b]);
|
|
145
|
+
let scale = (p * p + r * r).sqrt();
|
|
146
|
+
let tolerance = EPS * scale.max(1.0);
|
|
147
|
+
let similar = (p - s).abs() <= tolerance && (q + r).abs() <= tolerance;
|
|
148
|
+
(similar && scale > EPS).then_some(scale)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
pub fn is_identity(r: &Matrix3) -> bool {
|
|
152
|
+
(0..3).all(|i| (0..3).all(|j| (r[i][j] - IDENTITY[i][j]).abs() <= EPS))
|
|
104
153
|
}
|
|
105
154
|
|
|
106
155
|
/// Rotation about one geometry axis by `degrees`, right-hand rule: positive
|
|
@@ -176,12 +225,37 @@ mod tests {
|
|
|
176
225
|
}
|
|
177
226
|
|
|
178
227
|
#[test]
|
|
179
|
-
fn
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
// A half turn about X
|
|
183
|
-
|
|
228
|
+
fn plane_similarity_accepts_only_rotation_and_one_positive_factor() {
|
|
229
|
+
assert_eq!(plane_similarity(&axis_rotation(2, 33.0), 2), Some(1.0));
|
|
230
|
+
assert_eq!(plane_similarity(&axis_rotation(0, 33.0), 2), None);
|
|
231
|
+
// A half turn about X reverses the sense of rotation in the X/Y plane.
|
|
232
|
+
assert_eq!(plane_similarity(&axis_rotation(0, 180.0), 2), None);
|
|
233
|
+
let scaled = multiply(&axis_rotation(2, 20.0), &scaling([2.0, 2.0, 5.0]));
|
|
234
|
+
assert!((plane_similarity(&scaled, 2).unwrap() - 2.0).abs() < 1e-12);
|
|
235
|
+
assert_eq!(plane_similarity(&scaling([2.0, 3.0, 1.0]), 2), None);
|
|
236
|
+
assert_eq!(plane_similarity(&scaling([-1.0, 1.0, 1.0]), 2), None);
|
|
237
|
+
// Mirroring the normal axis leaves the plane itself untouched.
|
|
238
|
+
assert_eq!(plane_similarity(&scaling([1.0, 1.0, -1.0]), 2), Some(1.0));
|
|
184
239
|
assert!(is_identity(&rpy_rotation(0.0, 0.0, 0.0)));
|
|
185
240
|
assert!(is_identity(&axis_rotation(1, 360.0)));
|
|
186
241
|
}
|
|
242
|
+
|
|
243
|
+
#[test]
|
|
244
|
+
fn inverse_undoes_rotation_scale_and_mirror() {
|
|
245
|
+
let m = multiply(&rpy_rotation(10.0, 20.0, 30.0), &scaling([2.0, -0.5, 3.0]));
|
|
246
|
+
assert!(is_identity(&multiply(&m, &inverse(&m).unwrap())));
|
|
247
|
+
assert!(inverse(&scaling([1.0, 0.0, 1.0])).is_none());
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
#[test]
|
|
251
|
+
fn a_rotation_after_unequal_scale_factors_shears() {
|
|
252
|
+
let scale = scaling([2.0, 1.0, 1.0]);
|
|
253
|
+
assert!(columns_orthogonal(&multiply(&axis_rotation(2, 30.0), &scale)));
|
|
254
|
+
assert!(!columns_orthogonal(&multiply(&scale, &axis_rotation(2, 30.0))));
|
|
255
|
+
// Equal factors in the rotated plane commute with the rotation.
|
|
256
|
+
assert!(columns_orthogonal(&multiply(
|
|
257
|
+
&scaling([2.0, 2.0, 5.0]),
|
|
258
|
+
&axis_rotation(2, 30.0)
|
|
259
|
+
)));
|
|
260
|
+
}
|
|
187
261
|
}
|