@@ -233,7 +233,7 @@ def setHeadPosition(self, yaw: float, pitch: float):
233233
234234 return yaw_success and pitch_success
235235
236- def getHeadOrientationFromPico (self ) -> tuple :
236+ def get_target_orientation (self ) -> tuple :
237237 """
238238 Fetches the current head orientation from the Pico Robotics Service.
239239 Returns a tuple (yaw, pitch) in degrees.
@@ -254,7 +254,24 @@ def getHeadOrientationFromPico(self) -> tuple:
254254 print (f"Error fetching head orientation: { e } " )
255255 return 0.0 , 0.0 # Default values in case of error
256256
257- def run (self , get_orientation_callback , stop_event : threading .Event ):
257+ def run (self ):
258+ stop_event = threading .Event ()
259+ control_thread = threading .Thread (
260+ target = self .run_thread ,
261+ args = (stop_event ,),
262+ )
263+ control_thread .start ()
264+
265+ while True :
266+ try :
267+ time .sleep (0.1 )
268+ except KeyboardInterrupt :
269+ print ("Stopping head control..." )
270+ stop_event .set ()
271+ control_thread .join ()
272+ break
273+
274+ def run_thread (self , stop_event : threading .Event ):
258275 """
259276 Main control loop for head tracking.
260277 :param get_orientation_callback: A function that returns a tuple (current_yaw_degrees, current_pitch_degrees).
@@ -266,7 +283,9 @@ def run(self, get_orientation_callback, stop_event: threading.Event):
266283
267284 try :
268285 while not stop_event .is_set ():
269- current_yaw_raw , current_pitch_raw = get_orientation_callback ()
286+ current_yaw_raw , current_pitch_raw = (
287+ self .get_target_orientation ()
288+ )
270289
271290 current_yaw = current_yaw_raw
272291 if current_yaw > 90.0 and current_yaw < 180.0 :
0 commit comments