满庭芳·源流归一

结论:LinuxCNC rs274ngc 源码移植边界继续收拢。已将 rs274ngc 头文件纳入 manifest 跟踪,core 编译组仍只包含可编译源文件;启用 CNC_SIM_ENABLE_LINUXCNC_RS274_BACKEND 时 API 默认使用 LinuxCNC rs274 后端;M428/M429/M430 与 5axis/TRT/TDR/RTCP 相关路径继续保持来自 LinuxCNC 源码或 remap 配置的薄桥接。

验证:./test-linuxcnc-source-syntax.sh;./test-linuxcnc-api-native.sh;./test-native.sh;./test-linuxcnc-source-link.sh。
This commit is contained in:
cnc
2026-05-28 18:00:53 +08:00
parent 40a63c76f7
commit b40914747d
65 changed files with 5189 additions and 1117 deletions

View File

@@ -18,6 +18,9 @@ The event callback emits normalized `CncSimEvent` records. JavaScript can transf
## LinuxCNC integration plan
Functional behavior must come from LinuxCNC source code, not independently
designed project code. See `docs/linuxcnc-source-policy.md`.
1. Build a native `CanonEventSink` that implements all functions declared in `canon.hh`.
2. Link the sink with `src/emc/rs274ngc` and `src/emc/nml_intf` instead of the task controller.
3. Stub or remove Python remap support for the first browser target.
@@ -58,10 +61,18 @@ Feature parity needs more than G-code parsing:
## Five-axis and RTCP
The first RTCP implementation is a geometry kernel, not the full LinuxCNC motion
controller. It treats programmed XYZ as the tool-center point, applies A/B/C
orientation to a local tool vector, and computes the compensated pivot/spindle
point needed to keep the tool tip fixed.
RTCP pivot events are emitted only for known LinuxCNC switchkins modes. These
paths must use formulas copied from LinuxCNC source code, not independently
derived geometry. The current source mapping is:
- `M428` / `XYZBC_TRT`: `linuxcnc/src/emc/kinematics/trtfuncs.c`,
`xyzbcKinematicsForward()` and `xyzbcKinematicsInverse()`
- `M430` / `USERK_IDENTITY`: `linuxcnc/src/emc/kinematics/userkfuncs.c`,
delegating to `identityKinematicsForward()` and
`identityKinematicsInverse()` in `kins_util.c`
- The retained `5axiskins` helpers map to
`linuxcnc/src/emc/kinematics/5axiskins.c`,
`fiveaxis_KinematicsForward()` and `fiveaxis_KinematicsInverse()`
RTCP is opt-in through config JSON. When enabled, the original motion events
remain programmed tool-tip motion and an additional `rtcp-pivot` event is emitted
@@ -74,7 +85,5 @@ Current files:
- `core/src/rtcp_kinematics.cpp`
- `core/tests/rtcp_kinematics_smoke.cpp`
The next integration step is to add machine configuration for rotary topology,
pivot offsets, tool length sources, and rotation order, then apply RTCP
compensation while converting LinuxCNC Canon motion events into renderable
machine/tool-tip trajectories.
The next integration step is to add more LinuxCNC source-backed kinematics for
additional switchkins or machine topologies.

View File

@@ -19,7 +19,7 @@ g++ -std=c++17 -I core/include core/src/cnc_sim_api.cpp core/tests/cnc_sim_api_s
Status: in progress.
This parser only exists to test the ABI and UI before Emscripten and LinuxCNC are wired in. It currently handles:
This parser only exists to test the ABI and UI before Emscripten and LinuxCNC are wired in. It is not a production feature implementation. Do not extend it with independently designed G-code behavior; when a behavior needs to change, first locate the LinuxCNC source implementation and either route to that source-backed backend or port the corresponding source logic. It currently handles:
- multiple G/M words on one line
- `G0`, `G1`, `G2`, `G3`
@@ -39,7 +39,7 @@ This parser only exists to test the ABI and UI before Emscripten and LinuxCNC ar
- canned cycles `G73`, `G74`, `G81`, `G82`, `G83`, `G84`, `G85`, `G86`, `G87`, `G88`, `G89` with `G80`, `G98`, `G99`, `L`
- coordinate offset events for `G10 L2`, `G10 L20`, `G54`-`G59.3`, `G52`, `G92`, `G92.1`, `G92.2`, and `G92.3`
It is not the production interpreter.
It is not the production interpreter. Any remaining smoke-only behavior is technical debt to replace with LinuxCNC source-backed code.
## Step 2: Canon event sink

View File

@@ -0,0 +1,32 @@
# LinuxCNC Source Policy
The simulator must not grow independently designed functional behavior.
Functional behavior must come from LinuxCNC source code.
Allowed project code:
- Thin adapters between LinuxCNC source code and the simulator C API.
- Platform shims needed to compile LinuxCNC code for native tests or wasm.
- Event serialization, test fixtures, build scripts, and documentation.
- Temporary smoke scaffolding only when it is explicitly marked as temporary.
Not allowed as final behavior:
- Hand-written G-code interpretation semantics.
- Hand-derived kinematics, RTCP, coordinate transform, cutter compensation, canned cycle, modal, parameter, or expression behavior.
- Behavior copied from documentation, controller intuition, or examples without checking the LinuxCNC implementation.
Required workflow for every functional change:
1. Identify the LinuxCNC source file and function that defines the behavior.
2. Add or update a test that demonstrates the LinuxCNC behavior.
3. Port, wrap, or route to that LinuxCNC implementation.
4. Record the source file/function in code comments or nearby documentation when the mapping is not obvious.
5. Run `./test-native.sh` and `./test-linuxcnc-source-link.sh`.
Current temporary exceptions:
- The smoke parser exists only to exercise the public API and UI while the LinuxCNC RS274 backend is being wired in.
- RTCP pivot behavior is limited to LinuxCNC source-backed switchkins paths; unsupported switchkins types must not fall back to hand-derived geometry.
Both exceptions should shrink over time. New functional behavior should not be added to them unless it is directly copied from, or routed to, LinuxCNC source code.