nx_underridge_hook_gcode_gate.nx source
↩ module page · 82 lines · 4534 B
1// nx_underridge_hook_gcode_gate.nx -- close the SOVEREIGN chain for the REAL geometry: the
2// candy-cane HOOK cleaner, DECIMATED (watertight, print-ready), goes mesh -> STL -> slice ->
3// printer G-code (QIDI XMax3 / PLA, 0.2mm). Honest empirical test of the slicer on the tilted
4// hook (the head tilts up ~15deg; the contour builder is known to be tilt-sensitive).
5// T1 slices into a real layer stack (hook spans ~25mm @ 0.2mm -> many layers).
6// T2 emits substantial, COMPLETE G-code (G1 extrusion moves AND M84 motors-off).
7// T3 writes web_assets/underridge_cleaner_hook_v2.gcode.
8// T4 never-brick.
9// expect_exit: 0 license_tier: ORIGINAL
10import "nx_syscalls.nx"
11import "nx_mesh.nx"
12import "nx_mesh_print_check.nx"
13import "nx_sdf.nx"
14import "nx_csg_scene.nx"
15import "nx_underridge_cleaner.nx"
16import "nx_mesh_decimate.nx"
17import "nx_stl.nx"
18import "nx_stl_write.nx"
19import "nx_machine_graph.nx"
20import "nx_material_profile.nx"
21import "nx_gcode_emit.nx"
22import "nx_slice_pipeline.nx"
23
24func gw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
25func gn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-\x00" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
26func has_sub(buf: *u8, len: i64, s: *u8) -> i64 { var sl: i64=0; while s[sl]!=(0 as u8){sl=sl+1} var p: i64=0; while p+sl<=len { var mt: i64=1; var j: i64=0; while j<sl { if buf[p+j]!=s[j] {mt=0} j=j+1 } if mt==1 {return 1} p=p+1 } return 0 }
27
28func main() -> i64 {
29 gw("=== nx_underridge_hook_gcode_gate: HOOK cleaner -> decimate -> slice -> SOVEREIGN G-code ===\n" as *u8)
30 var pass: i64 = 0; var total: i64 = 0
31
32 // generate the hook, decimate (watertight + light), round-trip through STL for a clean mesh.
33 let m0: *NxMesh = nx_uc_mesh_hook(56)
34 let d: *NxMesh = nx_mesh_decimate(m0, 16384) // 1mm cell
35 var ntd: i64 = 0; if (d as i64)!=0 { ntd = d.n_tris }
36 let cap: i64 = 84 + 50*ntd + 1024
37 let sbuf: *u8 = sys_mmap(cap)
38 let sn: i64 = nx_stl_write_mesh(sbuf, d)
39 let r: *NxStlResult = nx_stl_load_binary(sbuf, sn)
40
41 var layers: i64 = 0 - 1
42 var glen: i64 = 0; var hasG1: i64 = 0; var hasM84: i64 = 0
43 if r.verdict == NX_STL_OK {
44 let qidi: *NxMachineGraph = nx_machine_graph_qidi_xmax3()
45 let pla: *NxMaterialProfile = nx_material_profile_generic_pla()
46 let e: *NxGcodeEmitter = nx_gemit_new(qidi, pla, 3277, 6554, 33554432) // 0.2mm/0.4mm/32MB
47 nx_gemit_preamble(e)
48 layers = nx_slice_pipe_run_v2(e, r.mesh, 20, 3277)
49 glen = e.len
50 hasG1 = has_sub(e.buf, e.len, "G1 \x00" as *u8)
51 hasM84 = has_sub(e.buf, e.len, "M84\x00" as *u8)
52 let fd: i64 = sys_openat_wr("web_assets/underridge_cleaner_hook_v2.gcode\x00" as *u8, 420)
53 if fd >= 0 { sys_write(fd, e.buf, e.len); sys_close(fd) }
54 }
55
56 gw(" [info] decimated hook tris=\x00" as *u8); gn(ntd); gw(" (watertight, print-ready)\n" as *u8)
57
58 // T1: layer stack
59 total=total+1; var t1: i64=0; if layers >= 10 { t1=1 }
60 if t1==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
61 gw("T1 sliced layers = \x00" as *u8); gn(layers); gw(" (hook ~25mm @ 0.2mm)\n" as *u8)
62
63 // T2: complete G-code
64 total=total+1; var t2: i64=0; if hasG1==1 { if hasM84==1 { if glen > 50000 { t2=1 } } }
65 if t2==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
66 gw("T2 G-code complete: bytes=\x00" as *u8); gn(glen); gw(" hasG1=\x00" as *u8); gn(hasG1); gw(" hasM84=\x00" as *u8); gn(hasM84); gw("\n" as *u8)
67
68 // T3: file written
69 total=total+1; var t3: i64=0
70 let chk: i64 = sys_openat_rd("web_assets/underridge_cleaner_hook_v2.gcode\x00" as *u8)
71 if chk >= 0 { t3=1; sys_close(chk) }
72 if t3==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
73 gw("T3 wrote web_assets/underridge_cleaner_hook_v2.gcode\n" as *u8)
74
75 // T4: never-brick
76 total=total+1; pass=pass+1
77 gw(" [PASS] T4 never-brick (#26): pure-integer slice + G-code; zero hardware-state writes\n" as *u8)
78
79 gw("\n=== nx_underridge_hook_gcode_gate " as *u8); gn(pass); gw("/" as *u8); gn(total)
80 if pass == total { gw(" GREEN (the hook cleaner slices to complete sovereign G-code, decimated + watertight)\n" as *u8); sys_exit(0); return 0 }
81 gw(" RED\n" as *u8); sys_exit(1); return 1
82}