@inneranimalmedia/primetech-procedures 0.0.0-stage → 2.6.18
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.
- package/.codex-plugin/plugin.json +39 -0
- package/LICENSE +110 -0
- package/README.md +181 -2
- package/agents/openai.yaml +6 -0
- package/agentsam.package.json +80 -0
- package/assets/architect-icon.svg +10 -0
- package/assets/primetech-design-studio.svg +7 -0
- package/companion.json +40 -0
- package/package.json +56 -4
- package/plugin.README.md +37 -0
- package/plugin.json +43 -0
- package/procedures/arch.assembly.calculate/procedure.json +83 -0
- package/procedures/cad.motor-bearing-end-plate/README.md +21 -0
- package/procedures/cad.motor-bearing-end-plate/build_freecad.py +514 -0
- package/procedures/cad.motor-bearing-end-plate/finalize_bundle.py +26 -0
- package/procedures/cad.motor-bearing-end-plate/generate_assets.py +284 -0
- package/procedures/cad.motor-bearing-end-plate/generate_toolpaths.py +715 -0
- package/procedures/cad.motor-bearing-end-plate/package_artifacts.py +154 -0
- package/procedures/cad.motor-bearing-end-plate/parameters.json +51 -0
- package/procedures/cad.motor-bearing-end-plate/procedure.json +101 -0
- package/procedures/cad.motor-bearing-end-plate/render_preview.py +98 -0
- package/procedures/cad.motor-bearing-end-plate/run.py +214 -0
- package/procedures/cad.motor-bearing-end-plate/test_generate_toolpaths.py +50 -0
- package/procedures/media.asset.preflight/procedure.json +85 -0
- package/procedures/media.image.optimize-asset/procedure.json +102 -0
- package/procedures/primetech.assets.package/procedure.json +63 -0
- package/procedures/primetech.design-system.package/procedure.json +58 -0
- package/procedures/primetech.ebook.package/procedure.json +53 -0
- package/procedures/primetech.icon-family.build/procedure.json +101 -0
- package/procedures/primetech.production-board.manage/procedure.json +156 -0
- package/procedures/primetech.sprite-atlas.build/procedure.json +86 -0
- package/procedures/primetech.typeface.package/procedure.json +61 -0
- package/procedures/primetech.visuals.compare/procedure.json +74 -0
- package/procedures/repo.asset.inventory/procedure.json +65 -0
- package/procedures/repo.asset.inventory/run.py +116 -0
- package/procedures/repo.asset.inventory/run.sh +11 -0
- package/procedures/repo.git.status/procedure.json +58 -0
- package/procedures/repo.git.status/run.sh +10 -0
- package/profiles/PRIMETECH_PROCEDURE_ENGINEER.md +25 -0
- package/scripts/generate-procedures.py +112 -0
- package/scripts/generate-skills.py +425 -0
- package/scripts/package-openai-plugin.py +94 -0
- package/skills/primetech-brand-kit/SKILL.md +40 -0
- package/skills/primetech-brand-kit/agentsam.skill.json +64 -0
- package/skills/primetech-character-sprites/SKILL.md +40 -0
- package/skills/primetech-character-sprites/agentsam.skill.json +64 -0
- package/skills/primetech-creative-delivery/SKILL.md +39 -0
- package/skills/primetech-creative-delivery/agentsam.skill.json +57 -0
- package/skills/primetech-design-systems/SKILL.md +43 -0
- package/skills/primetech-design-systems/agentsam.skill.json +57 -0
- package/skills/primetech-digital-publishing/SKILL.md +39 -0
- package/skills/primetech-digital-publishing/agentsam.skill.json +52 -0
- package/skills/primetech-iconography/SKILL.md +40 -0
- package/skills/primetech-iconography/agentsam.skill.json +53 -0
- package/skills/primetech-type-design/SKILL.md +40 -0
- package/skills/primetech-type-design/agentsam.skill.json +53 -0
- package/skills/primetech-ui-ux-prototypes/SKILL.md +43 -0
- package/skills/primetech-ui-ux-prototypes/agentsam.skill.json +64 -0
- package/skills/primetech-visual-qa/SKILL.md +39 -0
- package/skills/primetech-visual-qa/agentsam.skill.json +56 -0
- package/src/creative/asset-package.js +42 -0
- package/src/creative/design-system.js +107 -0
- package/src/creative/ebook.js +88 -0
- package/src/creative/icon-family.js +125 -0
- package/src/creative/index.d.ts +157 -0
- package/src/creative/index.js +7 -0
- package/src/creative/paths.js +64 -0
- package/src/creative/sprite-atlas.js +100 -0
- package/src/creative/typeface.js +154 -0
- package/src/creative/visual-qa.js +88 -0
- package/src/index.d.ts +160 -0
- package/src/index.js +656 -0
- package/src/production-board.d.ts +103 -0
- package/src/production-board.js +181 -0
- package/src/skills.d.ts +48 -0
- package/src/skills.js +101 -0
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Generate deterministic cutter-center paths, review-only generic G-code, and evidence."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import hashlib
|
|
7
|
+
import html
|
|
8
|
+
import json
|
|
9
|
+
import math
|
|
10
|
+
import re
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
SCHEMA = "inneranimalmedia.cam.toolpath.v1"
|
|
14
|
+
DIALECT = "generic_fanuc_style"
|
|
15
|
+
TOP_Z = -0.5
|
|
16
|
+
CLEARANCE_Z = 2.0
|
|
17
|
+
SAFE_Z = 5.0
|
|
18
|
+
BREAKTHROUGH_Z = -13.0
|
|
19
|
+
RAPID_MM_MIN = 3000.0
|
|
20
|
+
|
|
21
|
+
def sha256(path: Path) -> str:
|
|
22
|
+
digest = hashlib.sha256()
|
|
23
|
+
with path.open("rb") as stream:
|
|
24
|
+
for chunk in iter(lambda: stream.read(1024 * 1024), b""):
|
|
25
|
+
digest.update(chunk)
|
|
26
|
+
return digest.hexdigest()
|
|
27
|
+
|
|
28
|
+
def rounded_rect_points(half_l: float, half_w: float, radius: float, segments: int = 12):
|
|
29
|
+
"""Closed rounded-rectangle centerline, counter-clockwise."""
|
|
30
|
+
cx = half_l - radius
|
|
31
|
+
cy = half_w - radius
|
|
32
|
+
pts = [(-cx, -half_w), (cx, -half_w)]
|
|
33
|
+
corners = [
|
|
34
|
+
(cx, -cy, -90.0, 0.0),
|
|
35
|
+
(cx, cy, 0.0, 90.0),
|
|
36
|
+
(-cx, cy, 90.0, 180.0),
|
|
37
|
+
(-cx, -cy, 180.0, 270.0),
|
|
38
|
+
]
|
|
39
|
+
for index, (x, y, a0, a1) in enumerate(corners):
|
|
40
|
+
for step in range(1, segments + 1):
|
|
41
|
+
a = math.radians(a0 + (a1 - a0) * step / segments)
|
|
42
|
+
pts.append((x + radius * math.cos(a), y + radius * math.sin(a)))
|
|
43
|
+
if index == 0:
|
|
44
|
+
pts.append((half_l, cy))
|
|
45
|
+
pts.append((half_l, cy))
|
|
46
|
+
elif index == 1:
|
|
47
|
+
pts.append((-cx, half_w))
|
|
48
|
+
elif index == 2:
|
|
49
|
+
pts.append((-half_l, -cy))
|
|
50
|
+
# Remove consecutive duplicates, then close exactly.
|
|
51
|
+
cleaned = []
|
|
52
|
+
for pt in pts:
|
|
53
|
+
if not cleaned or math.dist(cleaned[-1], pt) > 1e-7:
|
|
54
|
+
cleaned.append(pt)
|
|
55
|
+
if math.dist(cleaned[0], cleaned[-1]) > 1e-7:
|
|
56
|
+
cleaned.append(cleaned[0])
|
|
57
|
+
return cleaned
|
|
58
|
+
|
|
59
|
+
def pocket_transform(x: float, y: float, p: dict):
|
|
60
|
+
theta = math.radians(p["pocket_angle_deg"] + 90.0)
|
|
61
|
+
center = p["pocket_center_radius_mm"] / math.sqrt(2.0)
|
|
62
|
+
return (
|
|
63
|
+
center + x * math.cos(theta) - y * math.sin(theta),
|
|
64
|
+
center + x * math.sin(theta) + y * math.cos(theta),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
def fmt(v: float) -> str:
|
|
68
|
+
if abs(v) < 0.0005:
|
|
69
|
+
v = 0.0
|
|
70
|
+
return f"{v:.3f}"
|
|
71
|
+
|
|
72
|
+
class Program:
|
|
73
|
+
def __init__(self):
|
|
74
|
+
self.lines = [
|
|
75
|
+
"%",
|
|
76
|
+
"(CAM MODEL 01 - MOTOR / BEARING END PLATE)",
|
|
77
|
+
"(CANDIDATE B - 150 MM OD; NOT APPROVED FOR MANUFACTURE)",
|
|
78
|
+
"(GENERIC FANUC-STYLE OUTPUT - UNVERIFIED FOR ANY MACHINE)",
|
|
79
|
+
"(PRECONDITION: TOP FACE ESTABLISHED AT Z-0.500; G54 Z0 IS RAW STOCK TOP)",
|
|
80
|
+
"(DEMO OPERATIONS ONLY: POCKET, CLEARANCE DRILLING, PILOT, BORE, COUNTERBORE)",
|
|
81
|
+
"(FACE, OUTSIDE PROFILE, CHAMFER, FIXTURE AND SECOND SETUP ARE NOT INCLUDED)",
|
|
82
|
+
"G21 G17 G90 G94",
|
|
83
|
+
"G54",
|
|
84
|
+
"G40 G49 G80",
|
|
85
|
+
]
|
|
86
|
+
self.moves = []
|
|
87
|
+
self.current = {"x": 0.0, "y": 0.0, "z": SAFE_Z}
|
|
88
|
+
self.tool = None
|
|
89
|
+
self.operation = "setup"
|
|
90
|
+
self.tool_changes = 0
|
|
91
|
+
|
|
92
|
+
def comment(self, value: str):
|
|
93
|
+
self.lines.append(f"({value})")
|
|
94
|
+
|
|
95
|
+
def _record(self, kind, start, end, op, feed=None, center=None, direction=None, code=None):
|
|
96
|
+
dx = end["x"] - start["x"]
|
|
97
|
+
dy = end["y"] - start["y"]
|
|
98
|
+
dz = end["z"] - start["z"]
|
|
99
|
+
if kind in ("arc_ccw", "arc_cw") and center:
|
|
100
|
+
radius = math.hypot(start["x"] - center["x"], start["y"] - center["y"])
|
|
101
|
+
a0 = math.atan2(start["y"] - center["y"], start["x"] - center["x"])
|
|
102
|
+
a1 = math.atan2(end["y"] - center["y"], end["x"] - center["x"])
|
|
103
|
+
delta = (a1 - a0) % (2 * math.pi) if kind == "arc_ccw" else (a0 - a1) % (2 * math.pi)
|
|
104
|
+
if delta < 1e-8 and math.hypot(dx, dy) < 1e-8:
|
|
105
|
+
delta = 2 * math.pi
|
|
106
|
+
xy_length = radius * delta
|
|
107
|
+
length = math.hypot(xy_length, dz)
|
|
108
|
+
else:
|
|
109
|
+
length = math.sqrt(dx * dx + dy * dy + dz * dz)
|
|
110
|
+
if length < 1e-8:
|
|
111
|
+
return
|
|
112
|
+
row = {
|
|
113
|
+
"index": len(self.moves) + 1,
|
|
114
|
+
"operation_id": op,
|
|
115
|
+
"motion": kind,
|
|
116
|
+
"start_mm": {k: round(v, 5) for k, v in start.items()},
|
|
117
|
+
"end_mm": {k: round(v, 5) for k, v in end.items()},
|
|
118
|
+
"length_mm": round(length, 5),
|
|
119
|
+
"gcode": code,
|
|
120
|
+
}
|
|
121
|
+
if feed is not None:
|
|
122
|
+
row["feed_mm_min"] = feed
|
|
123
|
+
if center:
|
|
124
|
+
row["center_mm"] = {"x": round(center["x"], 5), "y": round(center["y"], 5)}
|
|
125
|
+
if direction:
|
|
126
|
+
row["direction"] = direction
|
|
127
|
+
self.moves.append(row)
|
|
128
|
+
|
|
129
|
+
def rapid(self, op, x=None, y=None, z=None):
|
|
130
|
+
start = dict(self.current)
|
|
131
|
+
end = dict(self.current)
|
|
132
|
+
axes = []
|
|
133
|
+
for key, value in (("x", x), ("y", y), ("z", z)):
|
|
134
|
+
if value is not None:
|
|
135
|
+
end[key] = float(value)
|
|
136
|
+
axes.append(f"{key.upper()}{fmt(float(value))}")
|
|
137
|
+
if not axes:
|
|
138
|
+
return
|
|
139
|
+
code = "G0 " + " ".join(axes)
|
|
140
|
+
self.lines.append(code)
|
|
141
|
+
self._record("rapid", start, end, op, code=code)
|
|
142
|
+
self.current = end
|
|
143
|
+
|
|
144
|
+
def feed(self, op, feed, x=None, y=None, z=None):
|
|
145
|
+
start = dict(self.current)
|
|
146
|
+
end = dict(self.current)
|
|
147
|
+
axes = []
|
|
148
|
+
for key, value in (("x", x), ("y", y), ("z", z)):
|
|
149
|
+
if value is not None:
|
|
150
|
+
end[key] = float(value)
|
|
151
|
+
axes.append(f"{key.upper()}{fmt(float(value))}")
|
|
152
|
+
if not axes:
|
|
153
|
+
return
|
|
154
|
+
axes.append(f"F{float(feed):.1f}")
|
|
155
|
+
code = "G1 " + " ".join(axes)
|
|
156
|
+
self.lines.append(code)
|
|
157
|
+
self._record("feed", start, end, op, float(feed), code=code)
|
|
158
|
+
self.current = end
|
|
159
|
+
|
|
160
|
+
def arc(self, op, direction, feed, x, y, z, i, j):
|
|
161
|
+
start = dict(self.current)
|
|
162
|
+
end = {"x": float(x), "y": float(y), "z": float(z)}
|
|
163
|
+
center = {"x": start["x"] + float(i), "y": start["y"] + float(j)}
|
|
164
|
+
cmd = "G3" if direction == "ccw" else "G2"
|
|
165
|
+
code = (
|
|
166
|
+
f"{cmd} X{fmt(end['x'])} Y{fmt(end['y'])} Z{fmt(end['z'])} "
|
|
167
|
+
f"I{fmt(float(i))} J{fmt(float(j))} F{float(feed):.1f}"
|
|
168
|
+
)
|
|
169
|
+
self.lines.append(code)
|
|
170
|
+
kind = "arc_ccw" if direction == "ccw" else "arc_cw"
|
|
171
|
+
self._record(kind, start, end, op, float(feed), center, direction, code)
|
|
172
|
+
self.current = end
|
|
173
|
+
|
|
174
|
+
def tool_change(self, number, rpm, label):
|
|
175
|
+
if self.current["z"] < SAFE_Z:
|
|
176
|
+
self.rapid(self.operation, z=SAFE_Z)
|
|
177
|
+
if self.tool is not None:
|
|
178
|
+
self.lines.append("M5")
|
|
179
|
+
self.lines.append(f"(T{number} - {label})")
|
|
180
|
+
self.lines.append(f"T{number} M6")
|
|
181
|
+
self.lines.append(f"S{int(rpm)} M3")
|
|
182
|
+
self.tool = number
|
|
183
|
+
self.tool_changes += 1
|
|
184
|
+
|
|
185
|
+
def pocket_x_limit(y: float, half_l: float, half_w: float, radius: float, offset: float):
|
|
186
|
+
side_x = half_l - offset
|
|
187
|
+
corner_x = half_l - radius
|
|
188
|
+
corner_y = half_w - radius
|
|
189
|
+
effective_r = radius - offset
|
|
190
|
+
ay = abs(y)
|
|
191
|
+
if ay <= corner_y:
|
|
192
|
+
return side_x
|
|
193
|
+
if ay > corner_y + effective_r + 1e-7:
|
|
194
|
+
return None
|
|
195
|
+
return corner_x + math.sqrt(max(0.0, effective_r * effective_r - (ay - corner_y) ** 2))
|
|
196
|
+
|
|
197
|
+
def generate_paths(params: dict, out: Path):
|
|
198
|
+
p = params["candidate"]
|
|
199
|
+
prog = Program()
|
|
200
|
+
tool_definitions = [
|
|
201
|
+
{"number": 1, "diameter_mm": 6.0, "flutes": 3, "type": "carbide flat end mill", "stickout_mm": 18, "rpm": 10000, "feed_mm_min": 400, "ramp_feed_mm_min": 150, "status": "starting value; verify vendor data and machine rigidity"},
|
|
202
|
+
{"number": 2, "diameter_mm": 6.6, "flutes": 2, "type": "drill", "stickout_mm": 28, "rpm": 4000, "feed_mm_min": 160, "peck_depth_mm": 2.0, "status": "starting value; verify vendor data and machine rigidity"},
|
|
203
|
+
{"number": 3, "diameter_mm": 12.0, "flutes": 2, "type": "drill", "stickout_mm": 30, "rpm": 2500, "feed_mm_min": 100, "peck_depth_mm": 2.0, "status": "starting value; verify vendor data and machine rigidity"},
|
|
204
|
+
{"number": 4, "diameter_mm": 10.0, "flutes": 2, "type": "90-degree chamfer mill", "stickout_mm": 25, "rpm": 6000, "feed_mm_min": 120, "status": "starting value; tool geometry and chamfer compensation unverified"},
|
|
205
|
+
{"number": 5, "diameter_mm": 10.0, "flutes": 3, "type": "carbide flat end mill for facing and outside profile", "stickout_mm": 25, "rpm": 8000, "feed_mm_min": 350, "stepover_mm": 6.0, "status": "starting value; verify vendor data and workholding"},
|
|
206
|
+
]
|
|
207
|
+
op_meta = []
|
|
208
|
+
def begin(op, description):
|
|
209
|
+
prog.operation = op
|
|
210
|
+
prog.comment("OPERATION " + op + " - " + description)
|
|
211
|
+
|
|
212
|
+
# Operation 1/2: rough pocket raster with 0.3 mm radial stock left for a wall finish.
|
|
213
|
+
begin("pocket-rough", "rounded pocket roughing; 0.3 mm wall stock left")
|
|
214
|
+
prog.tool_change(1, 10000, "6 mm 3-flute carbide end mill")
|
|
215
|
+
tool_r = 3.0
|
|
216
|
+
offset = tool_r + 0.3
|
|
217
|
+
half_l = p["pocket_length_mm"] / 2.0
|
|
218
|
+
half_w = p["pocket_width_mm"] / 2.0
|
|
219
|
+
radius = p["pocket_corner_radius_mm"]
|
|
220
|
+
effective_half_w = half_w - offset
|
|
221
|
+
stepover = 2.4
|
|
222
|
+
lane_count = math.ceil((2 * effective_half_w) / stepover)
|
|
223
|
+
lane_step = (2 * effective_half_w) / lane_count
|
|
224
|
+
lane_ys = [-effective_half_w + i * lane_step for i in range(lane_count + 1)]
|
|
225
|
+
pocket_center = pocket_transform(0, 0, p)
|
|
226
|
+
pocket_depths = [-1.5, -2.5, -3.5, -4.5]
|
|
227
|
+
for depth in pocket_depths:
|
|
228
|
+
for y_local in lane_ys:
|
|
229
|
+
xlim = pocket_x_limit(y_local, half_l, half_w, radius, offset)
|
|
230
|
+
if xlim is None:
|
|
231
|
+
continue
|
|
232
|
+
sx, sy = pocket_transform(-15.0, y_local, p)
|
|
233
|
+
ex, ey = pocket_transform(15.0, y_local, p)
|
|
234
|
+
rx, ry = pocket_transform(xlim, y_local, p)
|
|
235
|
+
lx, ly = pocket_transform(-xlim, y_local, p)
|
|
236
|
+
prog.rapid("pocket-rough", z=SAFE_Z)
|
|
237
|
+
prog.rapid("pocket-rough", x=sx, y=sy, z=CLEARANCE_Z)
|
|
238
|
+
prog.feed("pocket-rough", 120, z=TOP_Z)
|
|
239
|
+
prog.feed("pocket-rough", 150, x=ex, y=ey, z=depth)
|
|
240
|
+
prog.feed("pocket-rough", 400, x=rx, y=ry, z=depth)
|
|
241
|
+
prog.feed("pocket-rough", 400, x=lx, y=ly, z=depth)
|
|
242
|
+
prog.rapid("pocket-rough", z=CLEARANCE_Z)
|
|
243
|
+
op_meta.append({
|
|
244
|
+
"id": "pocket-rough", "status": "generated", "tool": 1, "strategy": "linear ramp-in plus serpentine raster",
|
|
245
|
+
"depths_z_mm": pocket_depths, "stepdown_mm": 1.0, "stepover_mm": round(lane_step, 4),
|
|
246
|
+
"stock_to_leave_radial_mm": 0.3, "corner_radius_mm": radius,
|
|
247
|
+
"tool_radius_mm": tool_r, "corner_access_check": radius >= tool_r,
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
begin("pocket-finish", "rounded pocket wall finish at final depth")
|
|
251
|
+
prog.rapid("pocket-finish", z=SAFE_Z)
|
|
252
|
+
prog.rapid("pocket-finish", x=pocket_center[0], y=pocket_center[1], z=CLEARANCE_Z)
|
|
253
|
+
prog.feed("pocket-finish", 100, z=TOP_Z)
|
|
254
|
+
prog.feed("pocket-finish", 100, z=-p["pocket_depth_mm"] - 0.5)
|
|
255
|
+
finish_pts = rounded_rect_points(half_l - tool_r, half_w - tool_r, radius - tool_r, 16)
|
|
256
|
+
world_pts = [pocket_transform(x, y, p) for x, y in finish_pts]
|
|
257
|
+
for x, y in world_pts:
|
|
258
|
+
prog.feed("pocket-finish", 250, x=x, y=y)
|
|
259
|
+
prog.rapid("pocket-finish", z=SAFE_Z)
|
|
260
|
+
op_meta.append({
|
|
261
|
+
"id": "pocket-finish", "status": "generated", "tool": 1, "strategy": "closed rounded-rectangle contour",
|
|
262
|
+
"final_depth_z_mm": -p["pocket_depth_mm"] - 0.5, "stock_to_leave_radial_mm": 0.0,
|
|
263
|
+
"centerline_corner_radius_mm": radius - tool_r,
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
# Operation 3: explicit peck-drill moves for the four clearance holes.
|
|
267
|
+
def peck_drill(op, tool, rpm, feed, points, label):
|
|
268
|
+
begin(op, label)
|
|
269
|
+
prog.tool_change(tool, rpm, f"T{tool} drill")
|
|
270
|
+
peck_depth = 2.0
|
|
271
|
+
pecks = [-2.0, -4.0, -6.0, -8.0, -10.0, -12.0, BREAKTHROUGH_Z]
|
|
272
|
+
for x, y in points:
|
|
273
|
+
prog.rapid(op, z=SAFE_Z)
|
|
274
|
+
prog.rapid(op, x=x, y=y, z=CLEARANCE_Z)
|
|
275
|
+
prog.feed(op, 100, z=0.0)
|
|
276
|
+
previous = 0.0
|
|
277
|
+
for index, depth in enumerate(pecks):
|
|
278
|
+
if index:
|
|
279
|
+
prog.rapid(op, z=CLEARANCE_Z)
|
|
280
|
+
prog.rapid(op, z=previous + 0.5)
|
|
281
|
+
prog.feed(op, feed, z=depth)
|
|
282
|
+
previous = depth
|
|
283
|
+
prog.rapid(op, z=SAFE_Z)
|
|
284
|
+
return pecks
|
|
285
|
+
bolt_radius = p["bolt_circle_diameter_mm"] / 2.0
|
|
286
|
+
hole_points = [
|
|
287
|
+
(bolt_radius * math.cos(math.radians(a)), bolt_radius * math.sin(math.radians(a)))
|
|
288
|
+
for a in p["bolt_hole_angles_deg"]
|
|
289
|
+
]
|
|
290
|
+
hole_pecks = peck_drill("clearance-drill", 2, 4000, 160, hole_points, "four 6.6 mm clearance holes; explicit peck moves")
|
|
291
|
+
op_meta.append({
|
|
292
|
+
"id": "clearance-drill", "status": "generated", "tool": 2, "strategy": "explicit peck drilling",
|
|
293
|
+
"hole_count": len(hole_points), "diameter_mm": p["hole_diameter_mm"],
|
|
294
|
+
"bolt_circle_diameter_mm": p["bolt_circle_diameter_mm"], "peck_depth_mm": 2.0,
|
|
295
|
+
"final_z_mm": BREAKTHROUGH_Z,
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
pilot_pecks = peck_drill("bore-pilot", 3, 2500, 100, [(0.0, 0.0)], "12 mm center pilot hole for circular interpolation")
|
|
299
|
+
op_meta.append({
|
|
300
|
+
"id": "bore-pilot", "status": "generated", "tool": 3, "strategy": "explicit peck drilling",
|
|
301
|
+
"diameter_mm": 12.0, "peck_depth_mm": 2.0, "final_z_mm": BREAKTHROUGH_Z,
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
# Operation 4: helical entry and concentric passes for the 40 mm through bore.
|
|
305
|
+
begin("bore-interpolate", "40 mm nominal through bore; H7 still requires qualified finishing and inspection")
|
|
306
|
+
prog.tool_change(1, 10000, "6 mm 3-flute carbide end mill (reloaded)")
|
|
307
|
+
bore_depths = []
|
|
308
|
+
z = -1.5
|
|
309
|
+
while z > BREAKTHROUGH_Z + 1e-8:
|
|
310
|
+
bore_depths.append(round(z, 3))
|
|
311
|
+
z -= 1.0
|
|
312
|
+
if not bore_depths or abs(bore_depths[-1] - BREAKTHROUGH_Z) > 1e-8:
|
|
313
|
+
bore_depths.append(BREAKTHROUGH_Z)
|
|
314
|
+
bore_radii = [8.0, 10.0, 12.0, 14.0, 16.0, 17.0]
|
|
315
|
+
previous_z = TOP_Z
|
|
316
|
+
for depth in bore_depths:
|
|
317
|
+
prog.rapid("bore-interpolate", z=SAFE_Z)
|
|
318
|
+
prog.rapid("bore-interpolate", x=8.0, y=0.0, z=CLEARANCE_Z)
|
|
319
|
+
prog.feed("bore-interpolate", 120, z=previous_z)
|
|
320
|
+
mid = (previous_z + depth) / 2.0
|
|
321
|
+
prog.arc("bore-interpolate", "ccw", 120, -8.0, 0.0, mid, -8.0, 0.0)
|
|
322
|
+
prog.arc("bore-interpolate", "ccw", 120, 8.0, 0.0, depth, 8.0, 0.0)
|
|
323
|
+
for r in bore_radii[1:]:
|
|
324
|
+
prog.feed("bore-interpolate", 180, x=r, y=0.0)
|
|
325
|
+
prog.arc("bore-interpolate", "ccw", 180, -r, 0.0, depth, -r, 0.0)
|
|
326
|
+
prog.arc("bore-interpolate", "ccw", 180, r, 0.0, depth, r, 0.0)
|
|
327
|
+
previous_z = depth
|
|
328
|
+
prog.rapid("bore-interpolate", z=SAFE_Z)
|
|
329
|
+
op_meta.append({
|
|
330
|
+
"id": "bore-interpolate", "status": "generated", "tool": 1, "strategy": "helical entry plus concentric interpolation passes",
|
|
331
|
+
"nominal_diameter_mm": p["bore_diameter_mm"], "centerline_radii_mm": bore_radii,
|
|
332
|
+
"stepdown_mm": 1.0, "final_z_mm": BREAKTHROUGH_Z,
|
|
333
|
+
"tolerance_status": "nominal path only; H7 is not certified by this toolpath",
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
# Operation 5: counterbore annulus uses the through-bore wall as its inner boundary.
|
|
337
|
+
begin("counterbore-interpolate", "52 mm counterbore; 4 mm below finished top face")
|
|
338
|
+
prog.rapid("counterbore-interpolate", z=SAFE_Z)
|
|
339
|
+
prog.rapid("counterbore-interpolate", x=23.0, y=0.0, z=CLEARANCE_Z)
|
|
340
|
+
prog.feed("counterbore-interpolate", 100, z=TOP_Z)
|
|
341
|
+
previous_z = TOP_Z
|
|
342
|
+
final_cb_z = TOP_Z - p["counterbore_depth_mm"]
|
|
343
|
+
while previous_z > final_cb_z + 1e-8:
|
|
344
|
+
next_z = max(final_cb_z, previous_z - 0.5)
|
|
345
|
+
mid = (previous_z + next_z) / 2.0
|
|
346
|
+
prog.arc("counterbore-interpolate", "ccw", 120, -23.0, 0.0, mid, -23.0, 0.0)
|
|
347
|
+
prog.arc("counterbore-interpolate", "ccw", 120, 23.0, 0.0, next_z, 23.0, 0.0)
|
|
348
|
+
previous_z = next_z
|
|
349
|
+
# Finish circle at the final counterbore depth.
|
|
350
|
+
prog.arc("counterbore-interpolate", "ccw", 100, -23.0, 0.0, final_cb_z, -23.0, 0.0)
|
|
351
|
+
prog.arc("counterbore-interpolate", "ccw", 100, 23.0, 0.0, final_cb_z, 23.0, 0.0)
|
|
352
|
+
prog.rapid("counterbore-interpolate", z=SAFE_Z)
|
|
353
|
+
op_meta.append({
|
|
354
|
+
"id": "counterbore-interpolate", "status": "generated", "tool": 1, "strategy": "helical circular interpolation",
|
|
355
|
+
"diameter_mm": p["counterbore_diameter_mm"], "depth_mm": p["counterbore_depth_mm"],
|
|
356
|
+
"centerline_radius_mm": 23.0, "axial_stepdown_mm": 0.5,
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
prog.lines.extend(["M5", "G0 Z5.000", "M30", "%"])
|
|
360
|
+
gcode_path = out / "toolpath-unverified.nc"
|
|
361
|
+
gcode_path.write_text("\n".join(prog.lines) + "\n", encoding="utf-8")
|
|
362
|
+
|
|
363
|
+
# Validate the emitted path independently of the CAD builder.
|
|
364
|
+
stock_radius = p["outer_diameter_mm"] / 2.0 + 2.0
|
|
365
|
+
finite = all(
|
|
366
|
+
math.isfinite(v)
|
|
367
|
+
for move in prog.moves
|
|
368
|
+
for point_key in ("start_mm", "end_mm")
|
|
369
|
+
for v in move[point_key].values()
|
|
370
|
+
)
|
|
371
|
+
max_radius = max(
|
|
372
|
+
math.hypot(move[key]["x"], move[key]["y"])
|
|
373
|
+
for move in prog.moves
|
|
374
|
+
for key in ("start_mm", "end_mm")
|
|
375
|
+
)
|
|
376
|
+
min_z = min(move[key]["z"] for move in prog.moves for key in ("start_mm", "end_mm"))
|
|
377
|
+
max_z = max(move[key]["z"] for move in prog.moves for key in ("start_mm", "end_mm"))
|
|
378
|
+
gcode_text = gcode_path.read_text(encoding="utf-8")
|
|
379
|
+
motion_lines = [line for line in prog.lines if re.match(r"^G[0123]\s", line)]
|
|
380
|
+
# Parse the emitted NC text independently of the in-memory move writer.
|
|
381
|
+
parsed_position = {"x": 0.0, "y": 0.0, "z": 0.0}
|
|
382
|
+
parsed_positions = [dict(parsed_position)]
|
|
383
|
+
parsed_arc_errors = []
|
|
384
|
+
parsed_finite = True
|
|
385
|
+
for line in gcode_text.splitlines():
|
|
386
|
+
command_match = re.match(r"^(G[0123])(?:\s|$)", line)
|
|
387
|
+
if not command_match:
|
|
388
|
+
continue
|
|
389
|
+
words = {key.upper(): float(value) for key, value in re.findall(
|
|
390
|
+
r"([XYZIJKF])([-+]?(?:\d+(?:\.\d*)?|\.\d+))", line
|
|
391
|
+
)}
|
|
392
|
+
if any(not math.isfinite(value) for value in words.values()):
|
|
393
|
+
parsed_finite = False
|
|
394
|
+
continue
|
|
395
|
+
start = dict(parsed_position)
|
|
396
|
+
command = command_match.group(1)
|
|
397
|
+
if command in ("G2", "G3"):
|
|
398
|
+
if "I" not in words or "J" not in words:
|
|
399
|
+
parsed_arc_errors.append({"line": line, "error": "arc_center_missing"})
|
|
400
|
+
else:
|
|
401
|
+
center_x = start["x"] + words["I"]
|
|
402
|
+
center_y = start["y"] + words["J"]
|
|
403
|
+
end_x = words.get("X", start["x"])
|
|
404
|
+
end_y = words.get("Y", start["y"])
|
|
405
|
+
start_radius = math.hypot(start["x"] - center_x, start["y"] - center_y)
|
|
406
|
+
end_radius = math.hypot(end_x - center_x, end_y - center_y)
|
|
407
|
+
if abs(start_radius - end_radius) > 0.02:
|
|
408
|
+
parsed_arc_errors.append({
|
|
409
|
+
"line": line,
|
|
410
|
+
"start_radius_mm": round(start_radius, 6),
|
|
411
|
+
"end_radius_mm": round(end_radius, 6),
|
|
412
|
+
"error": "arc_radius_mismatch",
|
|
413
|
+
})
|
|
414
|
+
for axis in ("X", "Y", "Z"):
|
|
415
|
+
if axis in words:
|
|
416
|
+
parsed_position[axis.lower()] = words[axis]
|
|
417
|
+
parsed_positions.append(dict(parsed_position))
|
|
418
|
+
parsed_max_radius = max(math.hypot(point["x"], point["y"]) for point in parsed_positions)
|
|
419
|
+
parsed_min_z = min(point["z"] for point in parsed_positions)
|
|
420
|
+
parsed_max_z = max(point["z"] for point in parsed_positions)
|
|
421
|
+
parsed_arc_count = sum(1 for line in motion_lines if line.startswith(("G2 ", "G3 ")))
|
|
422
|
+
parsed_motion_count = len(motion_lines)
|
|
423
|
+
checks = [
|
|
424
|
+
{"check": "geometry_verification_precondition", "expected": True, "actual": json.loads((out / "verification.json").read_text())["all_checks_pass"], "pass": json.loads((out / "verification.json").read_text())["all_checks_pass"]},
|
|
425
|
+
{"check": "required_operations_generated", "expected": ["pocket-rough", "clearance-drill", "bore-interpolate"], "actual": sorted({m["operation_id"] for m in prog.moves} & {"pocket-rough", "clearance-drill", "bore-interpolate"}), "pass": all(x in {m["operation_id"] for m in prog.moves} for x in ["pocket-rough", "clearance-drill", "bore-interpolate"])},
|
|
426
|
+
{"check": "all_coordinates_finite", "expected": True, "actual": finite, "pass": finite},
|
|
427
|
+
{"check": "tool_center_within_stock_envelope", "expected": f"<= {stock_radius:g} mm radius", "actual": round(max_radius, 5), "pass": max_radius <= stock_radius + 1e-5},
|
|
428
|
+
{"check": "z_limits", "expected": {"min_mm": BREAKTHROUGH_Z, "max_mm": SAFE_Z}, "actual": {"min_mm": round(min_z, 5), "max_mm": round(max_z, 5)}, "pass": min_z >= BREAKTHROUGH_Z - 1e-5 and max_z <= SAFE_Z + 1e-5},
|
|
429
|
+
{"check": "gcode_has_metric_absolute_setup", "expected": True, "actual": all(x in gcode_text for x in ["G21 G17 G90 G94", "G54"]), "pass": all(x in gcode_text for x in ["G21 G17 G90 G94", "G54"])},
|
|
430
|
+
{"check": "gcode_has_program_end", "expected": "M30", "actual": "M30" in gcode_text, "pass": "M30" in gcode_text},
|
|
431
|
+
{"check": "gcode_marked_unverified", "expected": True, "actual": "UNVERIFIED" in gcode_text and "NOT APPROVED" in gcode_text, "pass": "UNVERIFIED" in gcode_text and "NOT APPROVED" in gcode_text},
|
|
432
|
+
{"check": "gcode_motion_text_parses", "expected": True, "actual": parsed_finite and parsed_motion_count > 100, "pass": parsed_finite and parsed_motion_count > 100},
|
|
433
|
+
{"check": "gcode_arc_radii_consistent", "expected": "all emitted G2/G3 arcs have matching start/end radii within 0.02 mm", "actual": {"arc_count": parsed_arc_count, "errors": parsed_arc_errors[:10]}, "pass": parsed_arc_count > 0 and not parsed_arc_errors},
|
|
434
|
+
{"check": "gcode_coordinate_envelope", "expected": {"stock_radius_mm": stock_radius, "min_z_mm": BREAKTHROUGH_Z, "max_z_mm": SAFE_Z}, "actual": {"max_tool_center_radius_mm": round(parsed_max_radius, 5), "min_z_mm": round(parsed_min_z, 5), "max_z_mm": round(parsed_max_z, 5)}, "pass": parsed_max_radius <= stock_radius + 1e-5 and parsed_min_z >= BREAKTHROUGH_Z - 1e-5 and parsed_max_z <= SAFE_Z + 1e-5},
|
|
435
|
+
{"check": "nonempty_motion_program", "expected": "> 100 motion commands", "actual": len(motion_lines), "pass": len(motion_lines) > 100},
|
|
436
|
+
]
|
|
437
|
+
all_pass = all(row["pass"] for row in checks)
|
|
438
|
+
if not all_pass:
|
|
439
|
+
raise RuntimeError("toolpath_verification_failed: " + json.dumps([row for row in checks if not row["pass"]]))
|
|
440
|
+
|
|
441
|
+
# Generate a backplot from the same moves consumed by the NC writer.
|
|
442
|
+
W = H = 1000
|
|
443
|
+
cx = cy = 450.0
|
|
444
|
+
scale = 3.6
|
|
445
|
+
def sx(x): return cx + x * scale
|
|
446
|
+
def sy(y): return cy - y * scale
|
|
447
|
+
def esc(value): return html.escape(str(value), quote=True)
|
|
448
|
+
svg = [
|
|
449
|
+
f'<svg xmlns="http://www.w3.org/2000/svg" width="{W}" height="{H}" viewBox="0 0 {W} {H}" role="img" aria-label="Generated toolpath backplot">',
|
|
450
|
+
'<rect width="100%" height="100%" fill="#f4f5f1"/>',
|
|
451
|
+
'<text x="50" y="48" font-family="Arial, sans-serif" font-size="17" font-weight="700" letter-spacing="2" fill="#526b62">CAM MODEL 01 / GENERATED TOOLPATH</text>',
|
|
452
|
+
'<text x="50" y="78" font-family="Arial, sans-serif" font-size="26" font-weight="700" fill="#203b34">Cutter-center backplot · Candidate B</text>',
|
|
453
|
+
f'<circle cx="{cx}" cy="{cy}" r="{p["outer_diameter_mm"]/2*scale:.2f}" fill="#fffdfa" stroke="#314b45" stroke-width="2.6"/>',
|
|
454
|
+
f'<circle cx="{cx}" cy="{cy}" r="{p["bolt_circle_diameter_mm"]/2*scale:.2f}" fill="none" stroke="#b4bdb7" stroke-width="1.5" stroke-dasharray="6 7"/>',
|
|
455
|
+
f'<circle cx="{cx}" cy="{cy}" r="{p["counterbore_diameter_mm"]/2*scale:.2f}" fill="none" stroke="#85968c" stroke-width="2" stroke-dasharray="7 5"/>',
|
|
456
|
+
f'<circle cx="{cx}" cy="{cy}" r="{p["bore_diameter_mm"]/2*scale:.2f}" fill="none" stroke="#85968c" stroke-width="2"/>',
|
|
457
|
+
]
|
|
458
|
+
for x, y in hole_points:
|
|
459
|
+
svg.append(f'<circle cx="{sx(x):.2f}" cy="{sy(y):.2f}" r="{p["hole_diameter_mm"]/2*scale:.2f}" fill="#fffdfa" stroke="#314b45" stroke-width="1.8"/>')
|
|
460
|
+
pocket_boundary = rounded_rect_points(p["pocket_length_mm"]/2, p["pocket_width_mm"]/2, p["pocket_corner_radius_mm"], 12)
|
|
461
|
+
pb = [pocket_transform(x, y, p) for x, y in pocket_boundary]
|
|
462
|
+
svg.append('<path d="' + " ".join(("M" if i == 0 else "L") + f"{sx(x):.2f},{sy(y):.2f}" for i, (x, y) in enumerate(pb)) + ' Z" fill="none" stroke="#7d9388" stroke-width="1.5"/>')
|
|
463
|
+
|
|
464
|
+
def arc_points(move, segments=20):
|
|
465
|
+
start = move["start_mm"]
|
|
466
|
+
end = move["end_mm"]
|
|
467
|
+
center = move.get("center_mm")
|
|
468
|
+
if not center:
|
|
469
|
+
return [(start["x"], start["y"]), (end["x"], end["y"])]
|
|
470
|
+
r = math.hypot(start["x"] - center["x"], start["y"] - center["y"])
|
|
471
|
+
a0 = math.atan2(start["y"] - center["y"], start["x"] - center["x"])
|
|
472
|
+
a1 = math.atan2(end["y"] - center["y"], end["x"] - center["x"])
|
|
473
|
+
delta = (a1 - a0) % (2 * math.pi) if move["motion"] == "arc_ccw" else (a0 - a1) % (2 * math.pi)
|
|
474
|
+
if delta < 1e-8 and math.hypot(end["x"] - start["x"], end["y"] - start["y"]) < 1e-8:
|
|
475
|
+
delta = 2 * math.pi
|
|
476
|
+
sign = 1 if move["motion"] == "arc_ccw" else -1
|
|
477
|
+
return [(center["x"] + r * math.cos(a0 + sign * delta * i / segments),
|
|
478
|
+
center["y"] + r * math.sin(a0 + sign * delta * i / segments)) for i in range(segments + 1)]
|
|
479
|
+
|
|
480
|
+
for move in prog.moves:
|
|
481
|
+
start = move["start_mm"]
|
|
482
|
+
end = move["end_mm"]
|
|
483
|
+
if math.hypot(end["x"] - start["x"], end["y"] - start["y"]) < 1e-6:
|
|
484
|
+
continue
|
|
485
|
+
pts = arc_points(move) if move["motion"].startswith("arc_") else [(start["x"], start["y"]), (end["x"], end["y"])]
|
|
486
|
+
points = " ".join(f"{sx(x):.2f},{sy(y):.2f}" for x, y in pts)
|
|
487
|
+
if move["motion"] == "rapid":
|
|
488
|
+
color, dash, width = "#c08b45", ' stroke-dasharray="6 5"', 1.25
|
|
489
|
+
elif move["motion"].startswith("arc_"):
|
|
490
|
+
color, dash, width = "#315f9b", "", 1.6
|
|
491
|
+
else:
|
|
492
|
+
color, dash, width = "#2d7771", "", 1.35
|
|
493
|
+
svg.append(f'<polyline points="{points}" fill="none" stroke="{color}" stroke-width="{width}"{dash} opacity="0.76" stroke-linecap="round" stroke-linejoin="round"/>')
|
|
494
|
+
svg.extend([
|
|
495
|
+
'<rect x="720" y="150" width="235" height="215" rx="5" fill="#fffdfa" stroke="#d6ddd6"/>',
|
|
496
|
+
'<text x="745" y="185" font-family="Arial, sans-serif" font-size="14" font-weight="700" fill="#203b34">MOTION LEGEND</text>',
|
|
497
|
+
'<line x1="745" y1="220" x2="795" y2="220" stroke="#c08b45" stroke-width="3" stroke-dasharray="6 5"/><text x="810" y="225" font-family="Arial, sans-serif" font-size="13" fill="#203b34">Rapid / reposition</text>',
|
|
498
|
+
'<line x1="745" y1="255" x2="795" y2="255" stroke="#2d7771" stroke-width="3"/><text x="810" y="260" font-family="Arial, sans-serif" font-size="13" fill="#203b34">Feed / cut</text>',
|
|
499
|
+
'<line x1="745" y1="290" x2="795" y2="290" stroke="#315f9b" stroke-width="3"/><text x="810" y="295" font-family="Arial, sans-serif" font-size="13" fill="#203b34">Arc / helix</text>',
|
|
500
|
+
f'<text x="745" y="335" font-family="Arial, sans-serif" font-size="12" fill="#61736c">{len(prog.moves)} recorded moves</text>',
|
|
501
|
+
'<rect x="720" y="390" width="235" height="190" rx="5" fill="#fffdfa" stroke="#d6ddd6"/>',
|
|
502
|
+
'<text x="745" y="425" font-family="Arial, sans-serif" font-size="14" font-weight="700" fill="#203b34">PROGRAM LIMITS</text>',
|
|
503
|
+
'<text x="745" y="455" font-family="Arial, sans-serif" font-size="12" fill="#61736c">Z0 = raw stock top</text>',
|
|
504
|
+
'<text x="745" y="478" font-family="Arial, sans-serif" font-size="12" fill="#61736c">Finished top = Z-0.5</text>',
|
|
505
|
+
f'<text x="745" y="501" font-family="Arial, sans-serif" font-size="12" fill="#61736c">Through cut = Z{BREAKTHROUGH_Z:g}</text>',
|
|
506
|
+
'<text x="745" y="536" font-family="Arial, sans-serif" font-size="12" font-weight="700" fill="#9b593c">UNVERIFIED POST</text>',
|
|
507
|
+
'<text x="50" y="950" font-family="Arial, sans-serif" font-size="14" fill="#9b593c">Review artifact only — no machine, fixture, collision simulation, or controller qualification.</text>',
|
|
508
|
+
'</svg>',
|
|
509
|
+
])
|
|
510
|
+
(out / "toolpath-preview.svg").write_text("\n".join(svg) + "\n", encoding="utf-8")
|
|
511
|
+
(out / "toolpath-preview.html").write_text(
|
|
512
|
+
'<!doctype html><html><head><meta charset="utf-8"><title>Toolpath backplot</title><style>body{margin:0;background:#e8ece7;display:grid;place-items:center;min-height:100vh}img{width:min(96vw,1100px);height:auto;background:#f4f5f1;box-shadow:0 18px 60px #132b241a}</style></head><body><img src="toolpath-preview.svg" alt="Generated toolpath backplot"></body></html>\n',
|
|
513
|
+
encoding="utf-8",
|
|
514
|
+
)
|
|
515
|
+
|
|
516
|
+
feed_seconds = sum(m["length_mm"] / m["feed_mm_min"] * 60 for m in prog.moves if m.get("feed_mm_min"))
|
|
517
|
+
rapid_seconds = sum(m["length_mm"] / RAPID_MM_MIN * 60 for m in prog.moves if m["motion"] == "rapid")
|
|
518
|
+
overhead_seconds = prog.tool_changes * 10.0 + 20.0
|
|
519
|
+
estimated_seconds = feed_seconds + rapid_seconds + overhead_seconds
|
|
520
|
+
gcode_sha = sha256(gcode_path)
|
|
521
|
+
toolpath_doc = {
|
|
522
|
+
"schema": SCHEMA,
|
|
523
|
+
"part_id": params["part_id"],
|
|
524
|
+
"revision": params["revision"],
|
|
525
|
+
"design_status": "proposal_not_approved",
|
|
526
|
+
"dialect": DIALECT,
|
|
527
|
+
"post_status": "UNVERIFIED",
|
|
528
|
+
"units": "mm",
|
|
529
|
+
"wcs": {
|
|
530
|
+
"coordinate_system": "G54",
|
|
531
|
+
"origin": "center of raw stock top",
|
|
532
|
+
"x0_mm": 0.0, "y0_mm": 0.0, "z0_mm": 0.0,
|
|
533
|
+
"finished_top_z_mm": TOP_Z,
|
|
534
|
+
"finished_bottom_z_mm": -12.5,
|
|
535
|
+
"through_breakthrough_z_mm": BREAKTHROUGH_Z,
|
|
536
|
+
},
|
|
537
|
+
"tooling": tool_definitions,
|
|
538
|
+
"operations": op_meta,
|
|
539
|
+
"moves": prog.moves,
|
|
540
|
+
"summary": {
|
|
541
|
+
"move_count": len(prog.moves),
|
|
542
|
+
"gcode_motion_line_count": len(motion_lines),
|
|
543
|
+
"feed_motion_seconds": round(feed_seconds, 2),
|
|
544
|
+
"rapid_motion_seconds_at_assumed_rate": round(rapid_seconds, 2),
|
|
545
|
+
"tool_change_allowance_seconds": round(prog.tool_changes * 10.0, 2),
|
|
546
|
+
"other_allowance_seconds": 20.0,
|
|
547
|
+
"estimated_cycle_time_seconds": round(estimated_seconds, 2),
|
|
548
|
+
"estimated_cycle_time_basis": "feed and rapid distance estimate plus explicit 10 s per tool change and 20 s other allowance; excludes machine acceleration, actual controller behavior, probing, coolant, setup, and ungenerated face/profile/chamfer operations",
|
|
549
|
+
"gcode_file": gcode_path.name,
|
|
550
|
+
"gcode_sha256": gcode_sha,
|
|
551
|
+
},
|
|
552
|
+
}
|
|
553
|
+
(out / "toolpath.json").write_text(json.dumps(toolpath_doc, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
554
|
+
|
|
555
|
+
verification = {
|
|
556
|
+
"schema": "inneranimalmedia.cam.toolpath-verification.v1",
|
|
557
|
+
"part_id": params["part_id"],
|
|
558
|
+
"revision": params["revision"],
|
|
559
|
+
"design_status": "proposal_not_approved",
|
|
560
|
+
"dialect": DIALECT,
|
|
561
|
+
"post_status": "UNVERIFIED",
|
|
562
|
+
"checks": checks,
|
|
563
|
+
"all_checks_pass": all_pass,
|
|
564
|
+
"limits": {
|
|
565
|
+
"stock_radius_mm": stock_radius,
|
|
566
|
+
"max_tool_center_radius_mm": round(max_radius, 5),
|
|
567
|
+
"min_z_mm": round(min_z, 5),
|
|
568
|
+
"max_z_mm": round(max_z, 5),
|
|
569
|
+
"gcode_parsed_max_tool_center_radius_mm": round(parsed_max_radius, 5),
|
|
570
|
+
"gcode_parsed_min_z_mm": round(parsed_min_z, 5),
|
|
571
|
+
"gcode_parsed_max_z_mm": round(parsed_max_z, 5),
|
|
572
|
+
"gcode_parsed_arc_count": parsed_arc_count,
|
|
573
|
+
"gcode_motion_line_count": len(motion_lines),
|
|
574
|
+
},
|
|
575
|
+
"not_verified": [
|
|
576
|
+
"No machine-specific postprocessor or controller dialect selected.",
|
|
577
|
+
"No machine, fixture, clamp, or workholding collision simulation.",
|
|
578
|
+
"No cutting load, tool deflection, chip evacuation, or spindle power simulation.",
|
|
579
|
+
"Feeds and speeds are starting values only and require tool-vendor and machine verification.",
|
|
580
|
+
"Ø40 H7 is not certified by nominal interpolation; use qualified finish process and inspect the bore.",
|
|
581
|
+
"The generic program does not include stock facing, outside profile finishing, chamfering, or the second setup.",
|
|
582
|
+
],
|
|
583
|
+
}
|
|
584
|
+
(out / "gcode-verification.json").write_text(json.dumps(verification, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
585
|
+
|
|
586
|
+
# Enrich the operation plan generated by the presentation/drawing stage.
|
|
587
|
+
plan_path = out / "cam-plan.json"
|
|
588
|
+
if plan_path.exists():
|
|
589
|
+
plan = json.loads(plan_path.read_text(encoding="utf-8"))
|
|
590
|
+
else:
|
|
591
|
+
plan = {"schema": "inneranimalmedia.cam.plan.v1", "part_id": params["part_id"], "revision": params["revision"]}
|
|
592
|
+
plan.update({
|
|
593
|
+
"design_status": "proposal_not_approved",
|
|
594
|
+
"execution_mode": "generated_generic_toolpath_review",
|
|
595
|
+
"machine_ready": False,
|
|
596
|
+
"controller_output": {
|
|
597
|
+
"generated": True,
|
|
598
|
+
"dialect": DIALECT,
|
|
599
|
+
"status": "UNVERIFIED",
|
|
600
|
+
"file": gcode_path.name,
|
|
601
|
+
"sha256": gcode_sha,
|
|
602
|
+
"includes": ["pocket roughing", "pocket wall finish", "four-hole peck drilling", "center pilot drilling", "through-bore interpolation", "counterbore interpolation"],
|
|
603
|
+
"omits": ["stock facing", "outside profile finishing", "outer-edge chamfer", "fixture/setup moves", "second setup"],
|
|
604
|
+
"reason": "Generic review program only. A qualified machine-specific post and simulation are still required.",
|
|
605
|
+
},
|
|
606
|
+
"stock_concept": {
|
|
607
|
+
"shape": "round",
|
|
608
|
+
"diameter_mm": p["outer_diameter_mm"] + 4.0,
|
|
609
|
+
"thickness_mm": p["thickness_mm"] + 2.0,
|
|
610
|
+
"material": params["material"],
|
|
611
|
+
"status": "conceptual stock; verify supplier availability and workholding",
|
|
612
|
+
"radial_allowance_mm": 2.0,
|
|
613
|
+
"axial_allowance_mm": 1.0,
|
|
614
|
+
},
|
|
615
|
+
"wcs_concept": {
|
|
616
|
+
"coordinate_system": "G54",
|
|
617
|
+
"origin": "center of raw stock top",
|
|
618
|
+
"x_mm": 0.0, "y_mm": 0.0, "z_mm": 0.0,
|
|
619
|
+
"finished_top_z_mm": TOP_Z,
|
|
620
|
+
"finished_bottom_z_mm": -12.5,
|
|
621
|
+
"axes": {"X": "part horizontal datum", "Y": "part vertical datum", "Z": "normal to top face"},
|
|
622
|
+
"status": "conceptual; confirm stock face and fixture datum",
|
|
623
|
+
},
|
|
624
|
+
"setups": [
|
|
625
|
+
{"id": "setup-01", "access": "top face", "purpose": "face reference, pocket, holes, pilot, bore, counterbore, top chamfer; leave radial stock on outside profile", "status": "conceptual; fixture not defined"},
|
|
626
|
+
{"id": "setup-02", "access": "flipped/back face", "purpose": "finish back face and outside diameter; deburr underside", "status": "planned only; no toolpath generated"},
|
|
627
|
+
],
|
|
628
|
+
"tools": tool_definitions,
|
|
629
|
+
"operation_sequence": [
|
|
630
|
+
{"order": 1, "id": "face-stock", "name": "Face stock", "tool": 5, "strategy": "raster facing", "rpm": 8000, "feed_mm_min": 350, "stepdown_mm": 0.5, "stepover_mm": 6.0, "stock_to_leave_mm": 0.0, "status": "planned; not included in NC file"},
|
|
631
|
+
{"order": 2, "id": "pocket-rough", "name": "Pocket roughing", "tool": 1, "strategy": "ramp-in plus raster", "rpm": 10000, "feed_mm_min": 400, "ramp_feed_mm_min": 150, "stepdown_mm": 1.0, "stepover_mm": 2.4, "stock_to_leave_radial_mm": 0.3, "status": "generated"},
|
|
632
|
+
{"order": 3, "id": "pocket-finish", "name": "Pocket finishing", "tool": 1, "strategy": "rounded contour", "rpm": 10000, "feed_mm_min": 250, "stepdown_mm": 0.5, "stepover_mm": 0.0, "stock_to_leave_radial_mm": 0.0, "status": "generated"},
|
|
633
|
+
{"order": 4, "id": "clearance-drill", "name": "Drill clearance holes", "tool": 2, "strategy": "explicit peck drilling", "rpm": 4000, "feed_mm_min": 160, "peck_depth_mm": 2.0, "final_z_mm": BREAKTHROUGH_Z, "status": "generated"},
|
|
634
|
+
{"order": 5, "id": "bore-pilot", "name": "Drill bore pilot", "tool": 3, "strategy": "explicit peck drilling", "rpm": 2500, "feed_mm_min": 100, "peck_depth_mm": 2.0, "final_z_mm": BREAKTHROUGH_Z, "status": "generated"},
|
|
635
|
+
{"order": 6, "id": "bore-interpolate", "name": "Bore Ø40 nominal", "tool": 1, "strategy": "helical entry plus concentric interpolation", "rpm": 10000, "feed_mm_min": 180, "stepdown_mm": 1.0, "radial_stepover_mm": 2.0, "stock_to_leave_mm": 0.0, "tolerance_status": "nominal only; H7 requires qualified finish and inspection", "status": "generated"},
|
|
636
|
+
{"order": 7, "id": "counterbore-interpolate", "name": "Counterbore Ø52 x 4 mm", "tool": 1, "strategy": "helical circular interpolation", "rpm": 10000, "feed_mm_min": 120, "stepdown_mm": 0.5, "stock_to_leave_mm": 0.0, "status": "generated"},
|
|
637
|
+
{"order": 8, "id": "outer-chamfer", "name": "Top outside chamfer 0.5 mm", "tool": 4, "strategy": "qualified chamfer contour", "rpm": 6000, "feed_mm_min": 120, "stepdown_mm": 0.5, "status": "planned; not included in NC file"},
|
|
638
|
+
{"order": 9, "id": "finish-outside-profile", "name": "Finish outside diameter and back face", "tool": 5, "strategy": "profile plus flipped setup", "rpm": 8000, "feed_mm_min": 350, "stepdown_mm": 1.0, "stock_to_leave_radial_mm": 0.5, "status": "planned; fixture and second setup not generated"},
|
|
639
|
+
],
|
|
640
|
+
"verification": {
|
|
641
|
+
"geometry_checks_pass": json.loads((out / "verification.json").read_text(encoding="utf-8"))["all_checks_pass"],
|
|
642
|
+
"toolpath_checks_pass": all_pass,
|
|
643
|
+
"toolpath_move_count": len(prog.moves),
|
|
644
|
+
"toolpath_checks": checks,
|
|
645
|
+
},
|
|
646
|
+
"cycle_time_estimate": toolpath_doc["summary"],
|
|
647
|
+
"excluded": {
|
|
648
|
+
"machine_specific_post": "not selected; generic Fanuc-style code is unverified",
|
|
649
|
+
"physical machining": "not authorized or supported by this artifact",
|
|
650
|
+
"collision_simulation": "not performed",
|
|
651
|
+
"H7_tolerance": "nominal path only; qualified finishing and inspection required",
|
|
652
|
+
"face_profile_chamfer_second_setup": "operation plan only; not in generated NC file",
|
|
653
|
+
},
|
|
654
|
+
"review_required": [
|
|
655
|
+
"Approve Candidate B 150 mm OD or revise the original 120 mm OD/pocket layout.",
|
|
656
|
+
"Confirm material, M6 clearance fit, and the exact Ø40 H7 acceptance limits.",
|
|
657
|
+
"Select stock, machine, fixture, clamps, tools, and a qualified postprocessor.",
|
|
658
|
+
"Simulate collisions and validate feeds/speeds, spindle load, chip evacuation, and workholding.",
|
|
659
|
+
"Inspect the finished bore and all critical dimensions before release.",
|
|
660
|
+
],
|
|
661
|
+
})
|
|
662
|
+
plan_path.write_text(json.dumps(plan, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
663
|
+
|
|
664
|
+
# The deck's image and narrative must refer to the generated backplot, not the old schematic.
|
|
665
|
+
deck_path = out / "presentation.html"
|
|
666
|
+
if deck_path.exists():
|
|
667
|
+
deck = deck_path.read_text(encoding="utf-8")
|
|
668
|
+
replacements = {
|
|
669
|
+
"The CAM view explains sequence, not machine commands.": "Generated cutter-center paths make the first machining sequence inspectable.",
|
|
670
|
+
'<img src="toolpath-preview.png" alt="Illustrative toolpath layers">': '<img src="toolpath-preview.svg" alt="Generated toolpath backplot">',
|
|
671
|
+
"No executable G-code, machine-specific feeds/speeds, or cycle-time estimate is included.": "Generic Fanuc-style G-code exists for review; post, machine settings, and cycle time remain unverified.",
|
|
672
|
+
"simulation-only process story": "offline CAM review package",
|
|
673
|
+
"The operation map connects each intent to a named CAD feature. It is useful for review without pretending that a machine, fixture, tool library, or post has been validated.": "The generated path data covers pocket roughing and finishing, peck drilling, bore interpolation, and counterbore interpolation. It remains unverified for any machine or post.",
|
|
674
|
+
}
|
|
675
|
+
for old, new in replacements.items():
|
|
676
|
+
deck = deck.replace(old, new)
|
|
677
|
+
deck_path.write_text(deck, encoding="utf-8")
|
|
678
|
+
|
|
679
|
+
summary = {
|
|
680
|
+
"schema": "inneranimalmedia.cam.toolpath-result.v1",
|
|
681
|
+
"ok": all_pass,
|
|
682
|
+
"part_id": params["part_id"],
|
|
683
|
+
"revision": params["revision"],
|
|
684
|
+
"design_status": "proposal_not_approved",
|
|
685
|
+
"dialect": DIALECT,
|
|
686
|
+
"post_status": "UNVERIFIED",
|
|
687
|
+
"move_count": len(prog.moves),
|
|
688
|
+
"gcode_motion_line_count": len(motion_lines),
|
|
689
|
+
"gcode_file": gcode_path.name,
|
|
690
|
+
"gcode_sha256": gcode_sha,
|
|
691
|
+
"toolpath_sha256": sha256(out / "toolpath.json"),
|
|
692
|
+
"verification_file": "gcode-verification.json",
|
|
693
|
+
"verification_pass": all_pass,
|
|
694
|
+
"estimated_cycle_time_seconds": round(estimated_seconds, 2),
|
|
695
|
+
"files": [
|
|
696
|
+
{"name": name, "bytes": (out / name).stat().st_size, "sha256": sha256(out / name)}
|
|
697
|
+
for name in ["toolpath-unverified.nc", "toolpath.json", "toolpath-preview.svg", "toolpath-preview.html", "gcode-verification.json", "cam-plan.json"]
|
|
698
|
+
],
|
|
699
|
+
}
|
|
700
|
+
(out / "toolpath-result.json").write_text(json.dumps(summary, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
701
|
+
print(json.dumps(summary, sort_keys=True))
|
|
702
|
+
return 0 if all_pass else 2
|
|
703
|
+
|
|
704
|
+
def main():
|
|
705
|
+
parser = argparse.ArgumentParser()
|
|
706
|
+
parser.add_argument("--parameters", required=True)
|
|
707
|
+
parser.add_argument("--output-dir", required=True)
|
|
708
|
+
args = parser.parse_args()
|
|
709
|
+
params_path = Path(args.parameters).resolve(strict=True)
|
|
710
|
+
out = Path(args.output_dir).resolve(strict=True)
|
|
711
|
+
params = json.loads(params_path.read_text(encoding="utf-8"))
|
|
712
|
+
return generate_paths(params, out)
|
|
713
|
+
|
|
714
|
+
if __name__ == "__main__":
|
|
715
|
+
raise SystemExit(main())
|