Skip to content

Commit 2357d42

Browse files
committed
removed callback function for head control run_thread
1 parent 965cb64 commit 2357d42

File tree

3 files changed

+24
-49
lines changed

3 files changed

+24
-49
lines changed

scripts/head_control.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def main():
1313
stop_signal = threading.Event()
1414

1515
control_thread = threading.Thread(
16-
target=controller.run,
17-
args=(controller.getHeadOrientationFromPico, stop_signal),
16+
target=controller.run_thread,
17+
args=(stop_signal,),
1818
)
1919
control_thread.start()
2020

scripts/ur5e_dual_arm_demo.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

teleop_demo_python/hardware/dynamixel.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)