5757
5858 # Test 5: Check initial controller state
5959 print ("[Test 5] Checking controller state..." )
60- left_snapshot = controller_tracker .get_left_controller (session )
61- right_snapshot = controller_tracker .get_right_controller (session )
62- print (
63- f" Left controller: { 'ACTIVE' if left_snapshot .is_active else 'INACTIVE' } "
64- )
65- print (
66- f" Right controller: { 'ACTIVE' if right_snapshot .is_active else 'INACTIVE' } "
67- )
68-
69- if left_snapshot .is_active and left_snapshot .grip_pose .is_valid :
70- pos = left_snapshot .grip_pose .pose .position
71- print (f" Left grip position: [{ pos .x :.3f} , { pos .y :.3f} , { pos .z :.3f} ]" )
72-
73- if right_snapshot .is_active and right_snapshot .grip_pose .is_valid :
74- pos = right_snapshot .grip_pose .pose .position
75- print (f" Right grip position: [{ pos .x :.3f} , { pos .y :.3f} , { pos .z :.3f} ]" )
60+ left_tracked = controller_tracker .get_left_controller (session )
61+ right_tracked = controller_tracker .get_right_controller (session )
62+
63+ if left_tracked .data is not None and left_tracked .data .grip_pose .is_valid :
64+ pos = left_tracked .data .grip_pose .pose .position
65+ print (f" Left grip: [{ pos .x :.3f} , { pos .y :.3f} , { pos .z :.3f} ]" )
66+ else :
67+ print (" Left: inactive" )
68+
69+ if right_tracked .data is not None and right_tracked .data .grip_pose .is_valid :
70+ pos = right_tracked .data .grip_pose .pose .position
71+ print (f" Right grip: [{ pos .x :.3f} , { pos .y :.3f} , { pos .z :.3f} ]" )
72+ else :
73+ print (" Right: inactive" )
7674 print ()
7775
7876 # Test 6: Available inputs
10098 current_time = time .time ()
10199 if current_time - last_status_print >= 0.5 : # Print every 0.5 seconds
102100 elapsed = current_time - start_time
103- left_snapshot = controller_tracker .get_left_controller (session )
104- right_snapshot = controller_tracker .get_right_controller (session )
105-
106- # Show current state
107- left_trigger = left_snapshot .inputs .trigger_value
108- left_squeeze = left_snapshot .inputs .squeeze_value
109- left_stick_x = left_snapshot .inputs .thumbstick_x
110- left_stick_y = left_snapshot .inputs .thumbstick_y
111- left_primary = left_snapshot .inputs .primary_click
112- left_secondary = left_snapshot .inputs .secondary_click
113-
114- right_trigger = right_snapshot .inputs .trigger_value
115- right_squeeze = right_snapshot .inputs .squeeze_value
116- right_stick_x = right_snapshot .inputs .thumbstick_x
117- right_stick_y = right_snapshot .inputs .thumbstick_y
118- right_primary = right_snapshot .inputs .primary_click
119- right_secondary = right_snapshot .inputs .secondary_click
120-
121- # Build status strings
122- left_status = f"Trig={ left_trigger :.2f} Sq={ left_squeeze :.2f} "
123- if abs (left_stick_x ) > 0.1 or abs (left_stick_y ) > 0.1 :
124- left_status += (
125- f" Stick=({ left_stick_x :+.2f} ,{ left_stick_y :+.2f} )"
101+ left_tracked = controller_tracker .get_left_controller (session )
102+ right_tracked = controller_tracker .get_right_controller (session )
103+
104+ print (f" [{ elapsed :5.2f} s] Frame { frame_count :4d} " )
105+
106+ left_data = left_tracked .data
107+ if left_data is not None :
108+ li = left_data .inputs
109+ print (
110+ f" L: Trig={ li .trigger_value :.2f} Sq={ li .squeeze_value :.2f} "
111+ f" Stick=({ li .thumbstick_x :+.2f} ,{ li .thumbstick_y :+.2f} )"
112+ f" Btn=[{ int (li .primary_click )} { int (li .secondary_click )} { int (li .thumbstick_click )} ]"
126113 )
127- if left_primary :
128- left_status += " [X]"
129- if left_secondary :
130- left_status += " [Y]"
131-
132- right_status = f"Trig={ right_trigger :.2f} Sq={ right_squeeze :.2f} "
133- if abs (right_stick_x ) > 0.1 or abs (right_stick_y ) > 0.1 :
134- right_status += (
135- f" Stick=({ right_stick_x :+.2f} ,{ right_stick_y :+.2f} )"
114+ else :
115+ print (" L: INACTIVE" )
116+
117+ right_data = right_tracked .data
118+ if right_data is not None :
119+ ri = right_data .inputs
120+ print (
121+ f" R: Trig={ ri .trigger_value :.2f} Sq={ ri .squeeze_value :.2f} "
122+ f" Stick=({ ri .thumbstick_x :+.2f} ,{ ri .thumbstick_y :+.2f} )"
123+ f" Btn=[{ int (ri .primary_click )} { int (ri .secondary_click )} { int (ri .thumbstick_click )} ]"
136124 )
137- if right_primary :
138- right_status += " [A]"
139- if right_secondary :
140- right_status += " [B]"
141-
142- print (
143- f" [{ elapsed :5.2f} s] Frame { frame_count :4d} | L: { left_status } | R: { right_status } "
144- )
125+ else :
126+ print (" R: INACTIVE" )
145127 last_status_print = current_time
146128
147129 frame_count += 1
157139 # Test 8: Show final statistics
158140 print ("[Test 8] Final controller state..." )
159141
160- def print_controller_summary (hand_name , snapshot ):
142+ def print_controller_summary (hand_name , tracked ):
161143 print (f" { hand_name } Controller:" )
162- if snapshot .is_active :
163- print (" Status: ACTIVE" )
164-
165- # Poses from snapshot
166- grip = snapshot .grip_pose
167- aim = snapshot .aim_pose
168-
169- if grip .is_valid :
170- pos = grip .pose .position
171- print (
172- f" Grip position: [{ pos .x :+.3f} , { pos .y :+.3f} , { pos .z :+.3f} ]"
173- )
174-
175- if aim .is_valid :
176- pos = aim .pose .position
177- print (
178- f" Aim position: [{ pos .x :+.3f} , { pos .y :+.3f} , { pos .z :+.3f} ]"
179- )
180-
181- # Input values
182- inputs = snapshot .inputs
144+ if tracked .data is not None :
145+ pos = tracked .data .grip_pose .pose .position
146+ print (f" Grip position: [{ pos .x :+.3f} , { pos .y :+.3f} , { pos .z :+.3f} ]" )
147+ pos = tracked .data .aim_pose .pose .position
148+ print (f" Aim position: [{ pos .x :+.3f} , { pos .y :+.3f} , { pos .z :+.3f} ]" )
149+ inputs = tracked .data .inputs
183150 print (f" Trigger: { inputs .trigger_value :.2f} " )
184151 print (f" Squeeze: { inputs .squeeze_value :.2f} " )
185152 print (
@@ -192,13 +159,13 @@ def print_controller_summary(hand_name, snapshot):
192159 f" Secondary: { 'PRESSED' if inputs .secondary_click else 'released' } "
193160 )
194161 else :
195- print (" Status: INACTIVE " )
162+ print (" inactive " )
196163
197- left_snapshot = controller_tracker .get_left_controller (session )
198- right_snapshot = controller_tracker .get_right_controller (session )
199- print_controller_summary ("Left" , left_snapshot )
164+ left_tracked = controller_tracker .get_left_controller (session )
165+ right_tracked = controller_tracker .get_right_controller (session )
166+ print_controller_summary ("Left" , left_tracked )
200167 print ()
201- print_controller_summary ("Right" , right_snapshot )
168+ print_controller_summary ("Right" , right_tracked )
202169 print ()
203170
204171 # Cleanup
0 commit comments