Files
cnc_wams/项目分析/5axis-xyzbc-trt-sim执行流程图.md
2026-07-05 22:13:40 -04:00

339 lines
9.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 5axis-xyzbc-trt-sim 执行流程图
本文档用 Mermaid 描述 `configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzbc-trt.ini` 的主要执行流程。
## 1. 总体启动流程
```mermaid
flowchart TD
A["xyzbc-trt.desktop"] --> B["scripts/rip-environment"]
B --> C["scripts/linuxcnc xyzbc-trt.ini"]
C --> D["读取 INI 配置"]
D --> D1["[TASK] TASK = milltask"]
D --> D2["[HAL] HALUI = halui"]
D --> D3["[HAL] HALFILE = LIB:basic_sim.tcl"]
D --> D4["[DISPLAY] DISPLAY = axis"]
D --> D5["[KINS] KINEMATICS = xyzbc-trt-kins sparm=identityfirst"]
C --> E["启动 linuxcncsvr"]
E --> F["启动 realtime / HAL"]
F --> G["loadrt tpmod / homemod"]
G --> H["启动 milltask"]
H --> I["启动 halui"]
I --> J["执行 basic_sim.tcl"]
J --> K["执行 INI 中的 HALCMD"]
K --> L["halcmd start 启动实时线程"]
L --> M["启动 AXIS GUI"]
M --> N["加载 PyVCP: xyzbc-trt.xml"]
N --> O["执行 POSTGUI_HALFILE: switchkins_postgui.hal"]
```
## 2. basic_sim.tcl 与仿真 HAL 建立流程
```mermaid
flowchart TD
A["[HAL] HALFILE = LIB:basic_sim.tcl"] --> B["basic_sim.tcl"]
B --> C["读取 TRAJ.COORDINATES = XYZBC"]
B --> D["读取 KINS.JOINTS = 5"]
B --> E["读取 EMCMOT.SERVO_PERIOD = 1000000"]
C --> F["core_sim axes=xyzbc joints=5"]
D --> F
E --> F
F --> G["setup_kins"]
G --> H["loadrt xyzbc-trt-kins sparm=identityfirst"]
F --> I["loadrt motmod num_joints=5 servo_period_nsec=1000000"]
I --> J["addf motion-command-handler servo-thread"]
I --> K["addf motion-controller servo-thread"]
F --> L["loadrt pid names=J0_pid..J4_pid"]
F --> M["loadrt mux2 names=J0_mux..J4_mux"]
F --> N["loadrt sim_home_switch"]
F --> O["loadusr hal_manualtoolchange"]
F --> P["loadrt sim_spindle / limit2 / lowpass / near / scale"]
L --> Q["joint.N.motor-pos-cmd -> JN_pid.command"]
Q --> R["JN_pid.output -> JN_mux.in1"]
R --> S["JN_mux.out -> joint.N.motor-pos-fb"]
S --> T["形成理想伺服仿真闭环"]
```
## 3. switchkins 初始化流程
```mermaid
flowchart TD
A["loadrt xyzbc-trt-kins sparm=identityfirst"] --> B["rtapi_app_main in switchkins.c"]
B --> C["调用 xyzbc-trt-kins.c:switchkinsSetup"]
C --> D{"sparm 包含 identityfirst?"}
D -- 是 --> E["type 0 = identity"]
D -- 是 --> F["type 1 = xyzbc TRT"]
D -- 是 --> G["type 2 = userk"]
D -- 否 --> H["type 0 = xyzbc TRT"]
D -- 否 --> I["type 1 = identity"]
D -- 否 --> J["type 2 = userk"]
E --> K["创建 HAL pin: kinstype.is-0/1/2"]
F --> K
G --> K
H --> K
I --> K
J --> K
K --> L["创建 TRT 几何 HAL pin"]
L --> L1["x/y/z-rot-point"]
L --> L2["x/y/z-offset"]
L --> L3["tool-offset"]
L --> L4["conventional-directions"]
L --> M["switchkins_type = 0"]
M --> N["kinematicsSwitch(0)"]
N --> O["启动默认状态: identity kinematics"]
```
## 4. PyVCP 按钮到运动学切换流程
```mermaid
flowchart TD
A["AXIS 加载 xyzbc-trt.xml"] --> B["创建 PyVCP SWITCHKINS 面板"]
B --> C1["按钮: IDENTITY"]
B --> C2["按钮: TCP:XYZBC"]
B --> C3["按钮: userk"]
A --> D["执行 switchkins_postgui.hal"]
C1 --> E1["pyvcp.type0-button"]
C2 --> E2["pyvcp.type1-button"]
C3 --> E3["pyvcp.type2-button"]
E1 --> F1["halui.mdi-command-00"]
E2 --> F2["halui.mdi-command-01"]
E3 --> F3["halui.mdi-command-02"]
F1 --> G1["M429"]
F2 --> G2["M428"]
F3 --> G3["M430"]
G1 --> H1["429remap.ngc: kinstype = 0"]
G2 --> H2["428remap.ngc: kinstype = 1"]
G3 --> H3["430remap.ngc: kinstype = 2"]
H1 --> I1["M68 E3 Q0"]
H2 --> I2["M68 E3 Q1"]
H3 --> I3["M68 E3 Q2"]
I1 --> J["motion.analog-out-03"]
I2 --> J
I3 --> J
J --> K["HAL net :kinstype-select"]
K --> L["motion.switchkins-type"]
L --> M["servo thread: handle_kinematicsSwitch()"]
M --> N["kinematicsSwitch(type)"]
N --> O1["type 0: identity"]
N --> O2["type 1: xyzbc TRT"]
N --> O3["type 2: userk"]
N --> P["kinstype.is-N 更新"]
P --> Q["PyVCP multilabel 显示当前类型"]
```
## 5. M68 到 motion.switchkins-type 的内部路径
```mermaid
flowchart TD
A["G-code: M68 E3 Q<type>"] --> B["RS274NGC interpreter"]
B --> C["interp_convert.cc"]
C --> D["SET_AUX_OUTPUT_VALUE(3, type)"]
D --> E["emccanon.cc 创建 EMC_MOTION_SET_AOUT"]
E --> F["taskintf.cc: emcMotionSetAout"]
F --> G["motion command: EMCMOT_SET_AOUT"]
G --> H["command.c: emcmotAioWrite(3, type)"]
H --> I["motion.analog-out-03 = type"]
I --> J["HAL net :kinstype-select"]
J --> K["motion.switchkins-type = type"]
```
## 6. 运动执行数据流
```mermaid
flowchart TD
A["G-code XYZBC"] --> B["RS274NGC interpreter"]
B --> C["milltask"]
C --> D["motion trajectory planner"]
D --> E["emcmotStatus->carte_pos_cmd"]
E --> F{"当前 switchkins type"}
F -- "type 0" --> G["identityKinematicsInverse"]
F -- "type 1" --> H["xyzbcKinematicsInverse"]
F -- "type 2" --> I["userkKinematicsInverse"]
H --> H1["读取 x-offset = -20"]
H --> H2["读取 z-offset = -15"]
H --> H3["读取 tool-offset = motion.tooloffset.z"]
H --> H4["读取 B/C 角度和旋转中心"]
G --> J["joint target positions"]
H1 --> J
H2 --> J
H3 --> J
H4 --> J
I --> J
J --> K["joint.N.coarse_pos"]
K --> L["joint.N.motor-pos-cmd"]
L --> M["仿真 PID / mux2"]
M --> N["joint.N.motor-pos-fb"]
N --> O["motion 状态反馈"]
N --> P["Vismach xyzbc-trt-gui"]
```
## 7. Vismach 显示数据流
```mermaid
flowchart TD
A["joint.0.pos-fb"] --> B["xyzbc-trt-gui.table-x"]
C["joint.1.pos-fb"] --> D["xyzbc-trt-gui.saddle-y"]
E["joint.2.pos-fb"] --> F["xyzbc-trt-gui.spindle-z"]
G["joint.3.pos-fb"] --> H["xyzbc-trt-gui.tilt-b"]
I["joint.4.pos-fb"] --> J["xyzbc-trt-gui.rotate-c"]
K["xyzbc-trt-kins.x-offset"] --> L["xyzbc-trt-gui.x-offset"]
M["xyzbc-trt-kins.z-offset"] --> N["xyzbc-trt-gui.z-offset"]
O["motion.tooloffset.z"] --> P["xyzbc-trt-kins.tool-offset"]
P --> Q["xyzbc-trt-gui.tool-offset"]
B --> R["Vismach 机床模型"]
D --> R
F --> R
H --> R
J --> R
L --> R
N --> R
Q --> R
```
## 8. 演示 G-code 执行流程
```mermaid
flowchart TD
A["AXIS OPEN_FILE: demos/xyzbc_switchkins.ngc"] --> B["调用 xyzbc_switchkins_sub"]
B --> C["参数: zmax=10 zmin=5 r=10 frate=1000 n=3 b=20 c=45 dist=20"]
C --> D["象限 I"]
C --> E["象限 II"]
C --> F["象限 III"]
C --> G["象限 IV"]
D --> H["M429: identity"]
E --> H
F --> H
G --> H
H --> I["G53 G0 X0 Y0 Zzmax B0 C0"]
I --> J["G10 L20 P0 重设 G54"]
J --> K["G0 移动到当前象限中心"]
K --> L["调用 helix_bc"]
L --> M["M429: identity"]
M --> N["调整 X 到圆弧起点"]
N --> O["G10 L20 P0 重设坐标"]
O --> P["M428: xyzbc TRT"]
P --> Q["G0 B#<b> C#<c>"]
Q --> R["G2 I#<r> Z#<zmin> P#<n> 螺旋插补"]
R --> S["M429: identity"]
S --> T["回安全位置"]
T --> U["M428: xyzbc TRT"]
U --> V{"四个象限完成?"}
V -- 否 --> H
V -- 是 --> W["最终 M429 回 identity 并复位"]
```
## 9. 核心关系简图
```mermaid
flowchart LR
A["INI: xyzbc-trt.ini"] --> B["HAL: basic_sim.tcl"]
A --> C["KINS: xyzbc-trt-kins"]
A --> D["GUI: axis"]
A --> E["Vismach: xyzbc-trt-gui"]
A --> F["PyVCP: xyzbc-trt.xml"]
A --> G["Remap: M428/M429/M430"]
B --> H["motmod + servo-thread + sim feedback"]
C --> I["switchkins type 0/1/2"]
D --> F
F --> G
G --> J["motion.switchkins-type"]
J --> I
I --> K["inverse / forward kinematics"]
K --> H
H --> E
```
## 10. LinuxCNC 数据系统核心原理图
高清 PNG
```text
项目分析/LinuxCNC数据系统核心原理高清流程图.png
```
可编辑 SVG
```text
项目分析/LinuxCNC数据系统核心原理高清流程图.svg
```
对应原理文档:
```text
项目分析/LinuxCNC数据系统核心原理.md
```
```mermaid
flowchart TD
A["INI 配置数据"] --> B["scripts/linuxcnc 启动装配"]
B --> C["linuxcncsvr / NML channels"]
B --> D["HAL: loadrt/loadusr/HALFILE/HALCMD"]
B --> E["milltask"]
B --> F["GUI: AXIS / halui"]
F --> G["NML emcCommand"]
G --> E
E --> H["Interpreter / Canonical Commands"]
H --> I["taskintf.cc"]
I --> J["Motion Shared Memory: emcmot_command_t"]
J --> K["Realtime motion servo cycle"]
K --> L["HAL pins/signals"]
L --> M["驱动 / 仿真组件 / Vismach / halui"]
M --> L
K --> N["emcmot_status_t"]
N --> E
E --> O["EMC_STAT: task + motion + io"]
O --> P["NML emcStatus"]
P --> F
Q["emcError"] --> F
E --> Q
K --> Q
```
核心区分:
```text
NML: 系统命令、系统状态、错误信息。
HAL: 实时机器信号、pin/signal/parameter、servo-thread 函数顺序。
Motion shared memory: task 和 realtime motion 的命令/状态边界。
INI: 启动装配数据,不是实时数据通道。
```