code wiki / (root) / nx_material_profile_test.nx

nx_material_profile_test.nx source

↩ module page · 104 lines · 4214 B

1// nx_material_profile_test.nx -- exercise the Generic PLA factory + 2// validator on both the seed default and on hand-corrupted variants. 3// 4// Closed-form invariants: 5// (a) Generic PLA factory returns non-null + validate == OK. 6// (b) Material class == PLA, flow ratio == 1.0 (16384 in Q14). 7// (c) Hotend temps: first-layer 215°C, print 210°C (5°C hotter 8// first-layer is the documented adhesion-bias choice). 9// (d) Bed temps: first-layer 65°C, print 60°C. 10// (e) Print speed 150 mm/s, first-layer 50 mm/s, bridge 80 mm/s. 11// (f) Bridge cooling: 100% fan during bridges (the 64.91%-sag- 12// reduction lever from NCBI PMC12608786). 13// (g) First N layers fan-disabled (default 1). 14// (h) Retraction 0.8 mm (direct drive). 15// (i) Validator catches: bad class, bad temp, bad speed, bad 16// cooling, bad retract, bad advanced. 17// 18// expect_exit: 0 19// license_tier: ORIGINAL 20 21import "nx_syscalls.nx" 22import "nx_material_profile.nx" 23 24func main() -> i64 { 25 let p: *NxMaterialProfile = nx_material_profile_generic_pla() 26 if (p as i64) == 0 { return 5 } 27 28 if nx_material_profile_validate(p) != NX_MATERIAL_OK { return 10 } 29 30 if p.material_class != NX_MAT_PLA { return 20 } 31 if p.flow_ratio_q14 != 16384 { return 21 } 32 33 if p.hotend_first_layer_c != 215 { return 30 } 34 if p.hotend_print_c != 210 { return 31 } 35 if p.bed_first_layer_c != 65 { return 32 } 36 if p.bed_print_c != 60 { return 33 } 37 38 if p.print_speed_mms != 150 { return 40 } 39 if p.first_layer_speed_mms != 50 { return 41 } 40 if p.bridge_speed_mms != 80 { return 42 } 41 if p.travel_speed_mms != 400 { return 43 } 42 43 if p.fan_speed_bridge_pct != 100 { return 50 } 44 if p.fan_speed_normal_pct != 100 { return 51 } 45 if p.fan_disable_first_n_layers != 1 { return 52 } 46 47 if p.retract_distance_um != 800 { return 60 } 48 if p.retract_speed_mms != 35 { return 61 } 49 50 // Validator mutations 51 p.material_class = 99 52 if nx_material_profile_validate(p) != NX_MATERIAL_ERR_BAD_CLASS { return 70 } 53 p.material_class = NX_MAT_PLA 54 55 p.hotend_print_c = -1 56 if nx_material_profile_validate(p) != NX_MATERIAL_ERR_BAD_TEMP { return 71 } 57 p.hotend_print_c = 210 58 59 p.print_speed_mms = 0 60 if nx_material_profile_validate(p) != NX_MATERIAL_ERR_BAD_SPEED { return 72 } 61 p.print_speed_mms = 150 62 63 p.fan_speed_normal_pct = 200 64 if nx_material_profile_validate(p) != NX_MATERIAL_ERR_BAD_COOLING { return 73 } 65 p.fan_speed_normal_pct = 100 66 67 p.retract_speed_mms = 0 68 if nx_material_profile_validate(p) != NX_MATERIAL_ERR_BAD_RETRACT { return 74 } 69 p.retract_speed_mms = 35 70 71 p.flow_ratio_q14 = 0 72 if nx_material_profile_validate(p) != NX_MATERIAL_ERR_BAD_ADVANCED { return 75 } 73 p.flow_ratio_q14 = 16384 74 75 if nx_material_profile_validate(p) != NX_MATERIAL_OK { return 79 } 76 77 // --- New factories: PETG, ABS, ASA, PEEK all validate --- 78 let petg: *NxMaterialProfile = nx_material_profile_generic_petg() 79 if (petg as i64) == 0 { return 80 } 80 if petg.material_class != NX_MAT_PETG { return 81 } 81 if nx_material_profile_validate(petg) != NX_MATERIAL_OK { return 82 } 82 if petg.hotend_print_c != 235 { return 83 } 83 84 let abs: *NxMaterialProfile = nx_material_profile_generic_abs() 85 if (abs as i64) == 0 { return 90 } 86 if abs.material_class != NX_MAT_ABS { return 91 } 87 if nx_material_profile_validate(abs) != NX_MATERIAL_OK { return 92 } 88 if abs.bed_print_c != 100 { return 93 } 89 90 let asa: *NxMaterialProfile = nx_material_profile_generic_asa() 91 if (asa as i64) == 0 { return 100 } 92 if asa.material_class != NX_MAT_ASA { return 101 } 93 if nx_material_profile_validate(asa) != NX_MATERIAL_OK { return 102 } 94 if asa.fan_speed_normal_pct != 20 { return 103 } 95 96 let peek: *NxMaterialProfile = nx_material_profile_generic_peek() 97 if (peek as i64) == 0 { return 110 } 98 if peek.material_class != NX_MAT_PEEK { return 111 } 99 if nx_material_profile_validate(peek) != NX_MATERIAL_OK { return 112 } 100 if peek.hotend_print_c != 380 { return 113 } 101 if peek.fan_speed_normal_pct != 0 { return 114 } // crystallization 102 103 return 0 104}