code wiki / _hdl_build / nx_contour_print_gate.nx

nx_contour_print_gate.nx source

↩ module page · 93 lines · 5493 B

1// nx_contour_print_gate.nx -- GATE: 3D-printing R1b. ARBITRARY GEOMETRY x ANY MATERIAL through one unified 2// contour emitter. T1 arbitrary geometry (a 12-gon ROUND cistern has off-axis vertices, not a rectangle), T2 3// material-appropriate (round concrete = cold; box filament = hot; round metal = arc), T3 never-brick all, T4 4// unification (one cp_emit_prism -> every geometry/material combo), T5 decimal Z works across materials. 5// license_tier: ORIGINAL 6import "nx_contour_print.nx" 7import "nx_print_material.nx" 8import "nx_food_science.nx" 9import "nx_seg_store.nx" 10import "nx_syscalls.nx" 11 12const CP_PRINT: *u8 = "knowledge/store/print-" 13 14func g_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 15func g_i(v: i64) -> i64 { 16 let bb: *u8 = sys_mmap(28); var m: i64 = v 17 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 18 let t: *u8 = sys_mmap(28); var k: i64 = 0 19 if m == 0 { t[0] = 48 as u8; k = 1 } 20 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 21 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 22} 23func g_nobrick(g: *u8, n: i64) -> i64 { 24 if as_contains(g, n, "M997" as *u8) != 0 { return 0 } 25 if as_contains(g, n, "M500" as *u8) != 0 { return 0 } 26 if as_contains(g, n, "M502" as *u8) != 0 { return 0 } 27 return 1 28} 29 30func main() -> i64 { 31 g_p("=== nx_contour_print_gate (R1b: arbitrary geometry x any material, one emitter) ===\n" as *u8) 32 pm_seed(CP_PRINT) 33 34 let xs: *i64 = sys_mmap(8 * 64) as *i64 35 let ys: *i64 = sys_mmap(8 * 64) as *i64 36 37 // ROUND cistern (12-gon) in concrete 38 let ncirc: i64 = cg_circle(xs, ys, 2000, 2000, 2000) 39 let gcis: *u8 = sys_mmap(524288); let ncis: i64 = cp_emit_prism(CP_PRINT, "concrete" as *u8, xs, ys, ncirc, 2000, gcis) 40 // rectangular box in filament 41 let xs2: *i64 = sys_mmap(8 * 16) as *i64; let ys2: *i64 = sys_mmap(8 * 16) as *i64 42 let nrect: i64 = cg_rect(xs2, ys2, 50, 50) 43 let gbox: *u8 = sys_mmap(131072); let nbox: i64 = cp_emit_prism(CP_PRINT, "pla" as *u8, xs2, ys2, nrect, 20, gbox) 44 // ROUND tube in metal 45 let xs3: *i64 = sys_mmap(8 * 16) as *i64; let ys3: *i64 = sys_mmap(8 * 16) as *i64 46 let ntu: i64 = cg_circle(xs3, ys3, 100, 100, 50) 47 let gtube: *u8 = sys_mmap(131072); let ntube: i64 = cp_emit_prism(CP_PRINT, "steel_waam" as *u8, xs3, ys3, ntu, 20, gtube) 48 g_p("emitted: round-concrete-cistern=" as *u8); g_i(ncis); g_p("B filament-box=" as *u8); g_i(nbox); g_p("B metal-tube=" as *u8); g_i(ntube); g_p("B\n" as *u8) 49 50 var pass: i64 = 0 51 var tot: i64 = 0 52 53 // T1 arbitrary geometry: the round cistern has off-axis (non-rectangular) vertices 54 tot = tot + 1 55 var ok1: i64 = 1 56 if ncis <= 0 { ok1 = 0 } 57 if as_contains(gcis, ncis, "X4000 Y2000" as *u8) != 1 { ok1 = 0 } // 0deg vertex 58 if as_contains(gcis, ncis, "X3732 Y3000" as *u8) != 1 { ok1 = 0 } // 30deg vertex -- OFF-AXIS = round, not a box 59 if as_contains(gcis, ncis, "X2000 Y4000" as *u8) != 1 { ok1 = 0 } // 90deg vertex 60 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 arbitrary geometry: a 12-gon ROUND cistern (off-axis vertices, not a rectangle)\n" as *u8) } else { g_p("FAIL T1\n" as *u8) } 61 62 // T2 material-appropriate across geometries 63 tot = tot + 1 64 var ok2: i64 = 1 65 if as_contains(gcis, ncis, "M104" as *u8) != 0 { ok2 = 0 } // concrete cistern: cold 66 if as_contains(gbox, nbox, "M104" as *u8) != 1 { ok2 = 0 } // filament box: hot 67 if as_contains(gtube, ntube, "M3 S" as *u8) != 1 { ok2 = 0 } // metal tube: arc 68 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 material-appropriate (round concrete cold / filament box hot / metal tube arc)\n" as *u8) } else { g_p("FAIL T2\n" as *u8) } 69 70 // T3 never-brick all 71 tot = tot + 1 72 if g_nobrick(gcis, ncis) == 1 { if g_nobrick(gbox, nbox) == 1 { if g_nobrick(gtube, ntube) == 1 { pass = pass + 1; g_p("PASS T3 never-brick across all geometry/material combos\n" as *u8) } else { g_p("FAIL T3 tube\n" as *u8) } } else { g_p("FAIL T3 box\n" as *u8) } } else { g_p("FAIL T3 cistern\n" as *u8) } 73 74 // T4 unification: one emitter, every combo 75 tot = tot + 1 76 if ncis > 0 { if nbox > 0 { if ntube > 0 { pass = pass + 1; g_p("PASS T4 unification: ONE cp_emit_prism -> {round,box} x {concrete,filament,metal}\n" as *u8) } else { g_p("FAIL T4\n" as *u8) } } else { g_p("FAIL T4\n" as *u8) } } else { g_p("FAIL T4\n" as *u8) } 77 78 // T5 decimal Z works across materials 79 tot = tot + 1 80 var ok5: i64 = 1 81 if as_contains(gcis, ncis, "Z10.000" as *u8) != 1 { ok5 = 0 } // concrete 10mm -> 10.000 82 if as_contains(gbox, nbox, "Z0.200" as *u8) != 1 { ok5 = 0 } // filament 0.2mm -> 0.200 83 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 decimal Z across materials (concrete 10.000mm, filament 0.200mm)\n" as *u8) } else { g_p("FAIL T5\n" as *u8) } 84 85 sys_mkdir("knowledge/staging" as *u8, 0x1ed) 86 sys_mkdir("knowledge/staging/print" as *u8, 0x1ed) 87 let fd: i64 = sys_openat_wr("knowledge/staging/print/round_cistern.gcode" as *u8, 420); if fd >= 0 { sys_write(fd, gcis, ncis); sys_close(fd); g_p("wrote knowledge/staging/print/round_cistern.gcode\n" as *u8) } 88 89 g_p("nx_contour_print_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 90 if pass == tot { g_p(" verdict=GREEN (arbitrary geometry x any material, one unified emitter, never-brick)\n" as *u8); return 0 } 91 g_p(" verdict=RED\n" as *u8) 92 return 1 93}