code wiki / _hdl_build / nx_footplant_gate.nx
nx_footplant_gate.nx source
↩ module page · 144 lines · 6096 B
1// nx_footplant_gate.nx -- ★Q5 FOOT PLANTING (the motion-realism audit named it: "feet float mid-stride, no ground
2// contact"). The ground-contact solve forward-FKs each foot's sole through its (hip,knee) chain and drops the being
3// onto its stance foot. T1 the FAULT measured (plant off, walk pose: the lowest sole floats). T2 the SOLVE closes it
4// (all four poses: lowest sole back at rest ground +-6). T3 causal SDF probes (ground-band occupancy flips). T4 no
5// regression at stand (offset exactly 0) + determinism. T5 evidence render (walk pose, off | on).
6// license_tier: ORIGINAL expect_exit: 0
7import "nx_syscalls.nx"
8import "nx_png.nx"
9import "nx_bodyatlas.nx"
10import "nx_gate_verdict.nx"
11
12func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
13func pn(v: i64) -> i64 { let b: *u8=sys_mmap(32) as *u8; var x: i64=v; var ng: i64=0; if x<0{ng=1;x=0-x} var i: i64=31; if x==0{b[i]=48 as u8;i=i-1} while x>0{b[i]=(48+x%10) as u8;x=x/10;i=i-1} if ng==1{b[i]=45 as u8;i=i-1} sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 }
14
15// lowest y where ANY skin is present in the foot band (scan a coarse x,z grid upward from below)
16func lowest_sole() -> i64 {
17 var y: i64 = 0-1400
18 while y < 0-680 {
19 var found: i64 = 0
20 var x: i64 = 0-260
21 while x <= 260 {
22 var z: i64 = 0-400
23 while z <= 700 {
24 if ba_sdf(x, y, z, 1) < 0 { found = 1 }
25 z = z + 40
26 }
27 x = x + 40
28 }
29 if found == 1 { return y }
30 y = y + 4
31 }
32 return 0-100000
33}
34
35func main() -> i64 {
36 hw("=== nx_footplant_gate -- Q5: ground contact (the being rides its planted foot) ===\n" as *u8)
37 let ctr: *i64 = gv_ctr()
38 atlas_hand_curl(0)
39 atlas_build(0)
40
41 // ---- T1 the FAULT, measured: walk pose with the solve OFF floats ----
42 atlas_set_plant(0)
43 atlas_pose(1)
44 let soleOff: i64 = lowest_sole()
45 atlas_pose(0)
46 let soleRest: i64 = lowest_sole()
47 hw(" rest sole="); pn(soleRest); hw(" walk sole (plant OFF)="); pn(soleOff); hw(" float="); pn(soleOff - soleRest); hw("\n" as *u8)
48 var t1: i64 = 0
49 if soleOff - soleRest > 15 { t1 = 1 }
50 gv_check("T1-the-fault-is-REAL-mid-stride-soles-float-above-rest-ground-fixture-reached-the-condition" as *u8, t1, ctr)
51
52 // ---- T2 the SOLVE closes it, on every pose ----
53 atlas_set_plant(1)
54 var worst: i64 = 0
55 var p: i64 = 0
56 while p < 4 {
57 atlas_pose(p)
58 let s: i64 = lowest_sole()
59 var off: i64 = s - soleRest
60 if off < 0 { off = 0-off }
61 hw(" pose "); pn(p); hw(": lowest sole="); pn(s); hw(" (off "); pn(off); hw(") ground_off="); pn(atlas_ground_off()); hw("\n" as *u8)
62 if off > worst { worst = off }
63 p = p + 1
64 }
65 var t2: i64 = 0
66 if worst <= 6 { t2 = 1 }
67 hw(" worst sole offset over all four poses="); pn(worst); hw("\n" as *u8)
68 gv_check("T2-PLANTED-every-pose-stance-sole-touches-the-rest-ground-inside-the-declared-band" as *u8, t2, ctr)
69
70 // ---- T3 causal: the ground band is EMPTY with the float, OCCUPIED with the solve ----
71 atlas_pose(1)
72 atlas_set_plant(0)
73 var bandOff: i64 = 0
74 var x: i64 = 0-220
75 while x <= 220 {
76 var z: i64 = 0-120
77 while z <= 260 {
78 if ba_sdf(x, soleRest + 6, z, 1) < 0 { bandOff = bandOff + 1 }
79 z = z + 20
80 }
81 x = x + 20
82 }
83 atlas_set_plant(1)
84 var bandOn: i64 = 0
85 x = 0-220
86 while x <= 220 {
87 var z: i64 = 0-120
88 while z <= 260 {
89 if ba_sdf(x, soleRest + 6, z, 1) < 0 { bandOn = bandOn + 1 }
90 z = z + 20
91 }
92 x = x + 20
93 }
94 hw(" ground-band occupancy: plant OFF="); pn(bandOff); hw(" ON="); pn(bandOn); hw("\n" as *u8)
95 var t3: i64 = 0
96 if bandOff == 0 { if bandOn > 3 { t3 = 1 } }
97 gv_check("T3-CAUSAL-ground-band-occupied-ONLY-when-the-solve-is-on-both-directions-measured" as *u8, t3, ctr)
98
99 // ---- T4 stand unaffected + deterministic ----
100 atlas_pose(0)
101 let g0: i64 = atlas_ground_off()
102 let probeA: i64 = ba_sdf(0, 800, 20, 1)
103 atlas_pose(1)
104 atlas_pose(0)
105 let probeB: i64 = ba_sdf(0, 800, 20, 1)
106 var t4: i64 = 0
107 if g0 == 0 { if probeA == probeB { t4 = 1 } }
108 hw(" stand ground_off="); pn(g0); hw(" probeA="); pn(probeA); hw(" probeB="); pn(probeB); hw("\n" as *u8)
109 gv_check("T4-neg-control-stand-pose-UNTOUCHED-offset-exactly-zero-and-the-probe-is-deterministic" as *u8, t4, ctr)
110
111 // ---- T5 evidence: walk pose, plant off | on (side-ish view; ground line drawn at the rest sole) ----
112 let W: i64 = 240
113 let H: i64 = 400
114 let GW: i64 = W*2
115 let gal: *i64 = sys_mmap(GW*H*8) as *i64
116 var i: i64 = 0
117 while i < GW*H { gal[i] = 24 + 26*256 + 34*65536; i = i + 1 }
118 let fb: *i64 = sys_mmap(W*H*8) as *i64
119 var slot: i64 = 0
120 while slot < 2 {
121 atlas_pose(1)
122 atlas_set_plant(slot)
123 atlas_render(fb, W, H, 1100, 1, 0-1)
124 var yy: i64 = 0
125 while yy < H {
126 var xx: i64 = 0
127 while xx < W { gal[yy*GW + slot*W + xx] = fb[yy*W + xx]; xx = xx + 1 }
128 yy = yy + 1
129 }
130 slot = slot + 1
131 }
132 // ground line at the rest sole row (atlas_render maps world y -> row via scale 2120/H about ycen -10)
133 let scale: i64 = 2120 / H
134 let grow: i64 = H/2 - (soleRest - (0-10))/scale
135 if grow >= 0 { if grow < H {
136 i = 0
137 while i < GW { gal[grow*GW + i] = 255 + 90*256 + 60*65536; i = i + 1 }
138 } }
139 write_png(gal, GW, H, "knowledge/nx_footplant.png" as *u8)
140 hw("T5 evidence -> knowledge/nx_footplant.png (walk: floating | planted, ground line)\n" as *u8)
141 atlas_set_plant(1)
142
143 return gv_verdict("FOOTPLANT-GATE" as *u8, ctr, "Q5 ground contact: the float is MEASURED with the solve off before the solve is asked to close it, so a gate that could not fail is excluded. Residual named, not hidden: weight shift/pelvis lean, heel-toe roll, IK knee bend on contact; and the T5 evidence render carries no tooth of its own" as *u8)
144}