5757
5858 # Test 5: Check initial controller state
5959 print ("[Test 5] Checking controller state..." )
60- left_snap = controller_tracker .get_left_controller (session )
61- right_snap = controller_tracker .get_right_controller (session )
62- print (f" Left controller: { 'ACTIVE' if left_snap .is_active else 'INACTIVE' } " )
63- print (f" Right controller: { 'ACTIVE' if right_snap .is_active else 'INACTIVE' } " )
64-
65- if left_snap .is_active and left_snap .grip_pose .is_valid :
66- pos = left_snap .grip_pose .pose .position
60+ tracked_left = controller_tracker .get_left_controller (session )
61+ tracked_right = controller_tracker .get_right_controller (session )
62+ print (
63+ f" Left controller: { 'ACTIVE' if tracked_left .data is not None else 'INACTIVE' } "
64+ )
65+ print (
66+ f" Right controller: { 'ACTIVE' if tracked_right .data is not None else 'INACTIVE' } "
67+ )
68+
69+ if tracked_left .data is not None and tracked_left .data .grip_pose .is_valid :
70+ pos = tracked_left .data .grip_pose .pose .position
6771 print (f" Left grip position: [{ pos .x :.3f} , { pos .y :.3f} , { pos .z :.3f} ]" )
6872
69- if right_snap . is_active and right_snap .grip_pose .is_valid :
70- pos = right_snap .grip_pose .pose .position
73+ if tracked_right . data is not None and tracked_right . data .grip_pose .is_valid :
74+ pos = tracked_right . data .grip_pose .pose .position
7175 print (f" Right grip position: [{ pos .x :.3f} , { pos .y :.3f} , { pos .z :.3f} ]" )
7276 print ()
7377
96100 current_time = time .time ()
97101 if current_time - last_status_print >= 0.5 : # Print every 0.5 seconds
98102 elapsed = current_time - start_time
99- left_snap = controller_tracker .get_left_controller (session )
100- right_snap = controller_tracker .get_right_controller (session )
103+ tracked_left = controller_tracker .get_left_controller (session )
104+ tracked_right = controller_tracker .get_right_controller (session )
101105
102106 # Show current state
103- left_trigger = left_snap .inputs .trigger_value
104- left_squeeze = left_snap .inputs .squeeze_value
105- left_stick_x = left_snap .inputs .thumbstick_x
106- left_stick_y = left_snap .inputs .thumbstick_y
107- left_primary = left_snap .inputs .primary_click
108- left_secondary = left_snap .inputs .secondary_click
109-
110- right_trigger = right_snap .inputs .trigger_value
111- right_squeeze = right_snap .inputs .squeeze_value
112- right_stick_x = right_snap .inputs .thumbstick_x
113- right_stick_y = right_snap .inputs .thumbstick_y
114- right_primary = right_snap .inputs .primary_click
115- right_secondary = right_snap .inputs .secondary_click
107+ left_trigger = (
108+ tracked_left .data .inputs .trigger_value
109+ if tracked_left .data is not None
110+ else 0.0
111+ )
112+ left_squeeze = (
113+ tracked_left .data .inputs .squeeze_value
114+ if tracked_left .data is not None
115+ else 0.0
116+ )
117+ left_stick_x = (
118+ tracked_left .data .inputs .thumbstick_x
119+ if tracked_left .data is not None
120+ else 0.0
121+ )
122+ left_stick_y = (
123+ tracked_left .data .inputs .thumbstick_y
124+ if tracked_left .data is not None
125+ else 0.0
126+ )
127+ left_primary = (
128+ tracked_left .data .inputs .primary_click
129+ if tracked_left .data is not None
130+ else False
131+ )
132+ left_secondary = (
133+ tracked_left .data .inputs .secondary_click
134+ if tracked_left .data is not None
135+ else False
136+ )
137+
138+ right_trigger = (
139+ tracked_right .data .inputs .trigger_value
140+ if tracked_right .data is not None
141+ else 0.0
142+ )
143+ right_squeeze = (
144+ tracked_right .data .inputs .squeeze_value
145+ if tracked_right .data is not None
146+ else 0.0
147+ )
148+ right_stick_x = (
149+ tracked_right .data .inputs .thumbstick_x
150+ if tracked_right .data is not None
151+ else 0.0
152+ )
153+ right_stick_y = (
154+ tracked_right .data .inputs .thumbstick_y
155+ if tracked_right .data is not None
156+ else 0.0
157+ )
158+ right_primary = (
159+ tracked_right .data .inputs .primary_click
160+ if tracked_right .data is not None
161+ else False
162+ )
163+ right_secondary = (
164+ tracked_right .data .inputs .secondary_click
165+ if tracked_right .data is not None
166+ else False
167+ )
116168
117169 # Build status strings
118170 left_status = f"Trig={ left_trigger :.2f} Sq={ left_squeeze :.2f} "
153205 # Test 8: Show final statistics
154206 print ("[Test 8] Final controller state..." )
155207
156- def print_controller_summary (hand_name , snapshot ):
208+ def print_controller_summary (hand_name , tracked ):
157209 print (f" { hand_name } Controller:" )
158- if snapshot . is_active :
210+ if tracked . data is not None :
159211 print (" Status: ACTIVE" )
160212
161213 # Poses from snapshot
162- grip = snapshot .grip_pose
163- aim = snapshot .aim_pose
214+ grip = tracked . data .grip_pose
215+ aim = tracked . data .aim_pose
164216
165217 if grip .is_valid :
166218 pos = grip .pose .position
@@ -175,7 +227,7 @@ def print_controller_summary(hand_name, snapshot):
175227 )
176228
177229 # Input values
178- inputs = snapshot .inputs
230+ inputs = tracked . data .inputs
179231 print (f" Trigger: { inputs .trigger_value :.2f} " )
180232 print (f" Squeeze: { inputs .squeeze_value :.2f} " )
181233 print (
@@ -190,11 +242,11 @@ def print_controller_summary(hand_name, snapshot):
190242 else :
191243 print (" Status: INACTIVE" )
192244
193- left_snap = controller_tracker .get_left_controller (session )
194- right_snap = controller_tracker .get_right_controller (session )
195- print_controller_summary ("Left" , left_snap )
245+ tracked_left = controller_tracker .get_left_controller (session )
246+ tracked_right = controller_tracker .get_right_controller (session )
247+ print_controller_summary ("Left" , tracked_left )
196248 print ()
197- print_controller_summary ("Right" , right_snap )
249+ print_controller_summary ("Right" , tracked_right )
198250 print ()
199251
200252 # Cleanup
0 commit comments