code wiki / _hdl_build / nx_footplant_gate.nx
nx_footplant_gate.nx source
↩ module page · 148 lines · 6125 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"
10
11func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
12func 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 }
13
14// lowest y where ANY skin is present in the foot band (scan a coarse x,z grid upward from below)
15func lowest_sole() -> i64 {
16 var y: i64 = 0-1400
17 while y < 0-680 {
18 var found: i64 = 0
19 var x: i64 = 0-260
20 while x <= 260 {
21 var z: i64 = 0-400
22 while z <= 700 {
23 if ba_sdf(x, y, z, 1) < 0 { found = 1 }
24 z = z + 40
25 }
26 x = x + 40
27 }
28 if found == 1 { return y }
29 y = y + 4
30 }
31 return 0-100000
32}
33
34func main() -> i64 {
35 hw("=== nx_footplant_gate -- Q5: ground contact (the being rides its planted foot) ===\n" as *u8)
36 var fails: i64 = 0
37 atlas_hand_curl(0)
38 atlas_build(0)
39
40 // ---- T1 the FAULT, measured: walk pose with the solve OFF floats ----
41 atlas_set_plant(0)
42 atlas_pose(1)
43 let soleOff: i64 = lowest_sole()
44 atlas_pose(0)
45 let soleRest: i64 = lowest_sole()
46 hw(" rest sole="); pn(soleRest); hw(" walk sole (plant OFF)="); pn(soleOff); hw(" float="); pn(soleOff - soleRest); hw("\n" as *u8)
47 var t1: i64 = 0
48 if soleOff - soleRest > 15 { t1 = 1 }
49 if t1 == 1 { hw("T1 PASS the fault is real: mid-stride the feet FLOAT (measured) with no ground solve\n" as *u8) }
50 else { fails=fails+1; hw("T1 FAIL\n" as *u8) }
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 if t2 == 1 { hw("T2 PASS PLANTED: in every pose the stance sole touches the rest ground (worst off "); pn(worst); hw(")\n" as *u8) }
68 else { fails=fails+1; hw("T2 FAIL worst="); pn(worst); hw("\n" as *u8) }
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 if t3 == 1 { hw("T3 PASS CAUSAL: the stance foot OCCUPIES the ground band only when the solve is on\n" as *u8) }
98 else { fails=fails+1; hw("T3 FAIL\n" as *u8) }
99
100 // ---- T4 stand unaffected + deterministic ----
101 atlas_pose(0)
102 let g0: i64 = atlas_ground_off()
103 let probeA: i64 = ba_sdf(0, 800, 20, 1)
104 atlas_pose(1)
105 atlas_pose(0)
106 let probeB: i64 = ba_sdf(0, 800, 20, 1)
107 var t4: i64 = 0
108 if g0 == 0 { if probeA == probeB { t4 = 1 } }
109 if t4 == 1 { hw("T4 PASS stand pose untouched (offset 0) + deterministic\n" as *u8) }
110 else { fails=fails+1; hw("T4 FAIL g0="); pn(g0); hw("\n" as *u8) }
111
112 // ---- T5 evidence: walk pose, plant off | on (side-ish view; ground line drawn at the rest sole) ----
113 let W: i64 = 240
114 let H: i64 = 400
115 let GW: i64 = W*2
116 let gal: *i64 = sys_mmap(GW*H*8) as *i64
117 var i: i64 = 0
118 while i < GW*H { gal[i] = 24 + 26*256 + 34*65536; i = i + 1 }
119 let fb: *i64 = sys_mmap(W*H*8) as *i64
120 var slot: i64 = 0
121 while slot < 2 {
122 atlas_pose(1)
123 atlas_set_plant(slot)
124 atlas_render(fb, W, H, 1100, 1, 0-1)
125 var yy: i64 = 0
126 while yy < H {
127 var xx: i64 = 0
128 while xx < W { gal[yy*GW + slot*W + xx] = fb[yy*W + xx]; xx = xx + 1 }
129 yy = yy + 1
130 }
131 slot = slot + 1
132 }
133 // ground line at the rest sole row (atlas_render maps world y -> row via scale 2120/H about ycen -10)
134 let scale: i64 = 2120 / H
135 let grow: i64 = H/2 - (soleRest - (0-10))/scale
136 if grow >= 0 { if grow < H {
137 i = 0
138 while i < GW { gal[grow*GW + i] = 255 + 90*256 + 60*65536; i = i + 1 }
139 } }
140 write_png(gal, GW, H, "knowledge/nx_footplant.png" as *u8)
141 hw("T5 evidence -> knowledge/nx_footplant.png (walk: floating | planted, ground line)\n" as *u8)
142 atlas_set_plant(1)
143
144 if fails == 0 { hw("FOOTPLANT-GATE GREEN -- Q5: ground contact is REAL (float measured, solve closes it in every pose, causal band proof, stand untouched). Residual: weight shift/pelvis lean, heel-toe roll, IK knee bend on contact.\n" as *u8); sys_exit(0); return 0 }
145 hw("FOOTPLANT-GATE RED fails="); pn(fails); hw("\n" as *u8)
146 sys_exit(1)
147 return 1
148}