nx_jam_detect.nx source
↩ module page · 31 lines · 1844 B
1// nx_jam_detect.nx -- SOVEREIGN clog/jam detector (QIDI fix; complements
2// nx_print_runtime_monitor's spaghetti/temp/shift detection, which does NOT cover
3// a feed-side JAM).
4//
5// Researcher-grounded (nx_research over FFF): "compressive stress IS THE driving
6// force behind extrusion" -> a JAM = that chain broken: the extruder COMMANDS
7// filament advance but little/none actually FEEDS (heat-creep softening above the
8// melt zone, PTFE-heatbreak gap, partial clog, or gear grinding). Stock QIDI has
9// only a binary runout sensor; this uses a filament-MOTION signal (commanded-E vs
10// measured-feed, e.g. a BTT Smart Filament Sensor encoder) to catch jams EARLY,
11// before a long print is wasted -- predictive, sovereign, cheap. license_tier: ORIGINAL.
12
13import "nx_syscalls.nx"
14
15const JAM_OK: i64 = 0
16const JAM_CLOG: i64 = 1 // commanded extrusion but ZERO feed -> hard clog / heat-creep / PTFE gap
17const JAM_GRIND: i64 = 2 // feed far below commanded -> extruder gear grinding / partial clog
18const NX_JAM_Q14: i64 = 16384
19
20// One detection window.
21// e_adv_q14 = commanded extruder advance this window (Q14 mm)
22// feed_q14 = MEASURED filament travel this window (Q14 mm, from motion sensor)
23// e_thresh_q14 = min commanded advance before judging (ignore tiny moves)
24// min_ratio_pct = min acceptable measured/commanded ratio; below -> grinding
25func jam_step(e_adv_q14: i64, feed_q14: i64, e_thresh_q14: i64, min_ratio_pct: i64) -> i64 {
26 if e_adv_q14 < e_thresh_q14 { return JAM_OK } // not enough commanded extrusion to judge
27 if feed_q14 <= 0 { return JAM_CLOG } // commanded but nothing fed = hard clog
28 let ratio_pct: i64 = (feed_q14 * 100) / e_adv_q14
29 if ratio_pct < min_ratio_pct { return JAM_GRIND } // feeding far less than commanded
30 return JAM_OK
31}