apirrone commited on
Commit
53a403c
·
1 Parent(s): b7ae8d6

properly stop the app

Browse files
Files changed (1) hide show
  1. hand_tracker_v2/main.py +11 -6
hand_tracker_v2/main.py CHANGED
@@ -44,7 +44,7 @@ class HandTrackerV2(ReachyMiniApp):
44
  elif self.hand_pos is not None:
45
  self.hand_pos *= 0.9 # Slowly go back to center
46
 
47
- def track(self, reachy_mini: ReachyMini):
48
  target = np.array([0, 0])
49
  pitch_kp = 0.03
50
  yaw_kp = 0.08
@@ -55,8 +55,9 @@ class HandTrackerV2(ReachyMiniApp):
55
  head_pose = np.eye(4)
56
  euler_rot = np.array([0.0, 0.0, 0.0])
57
 
58
- while True:
59
  if self.hand_pos is None:
 
60
  continue
61
  error = target - self.hand_pos
62
  error = np.clip(
@@ -74,9 +75,7 @@ class HandTrackerV2(ReachyMiniApp):
74
  "xyz", euler_rot, degrees=False
75
  ).as_matrix()
76
 
77
- head_pose[:3, 3][2] = (
78
- error[1] * kz
79
- ) # Adjust height based on vertical error
80
 
81
  reachy_mini.set_target(head=head_pose)
82
 
@@ -86,7 +85,7 @@ class HandTrackerV2(ReachyMiniApp):
86
  reachy_mini.goto_target(np.eye(4), [0.0, 0.0], body_yaw=0.0, duration=1.0)
87
 
88
  tracking_thread = threading.Thread(
89
- target=self.track, args=(reachy_mini,), daemon=True
90
  )
91
  tracking_thread.start()
92
 
@@ -104,6 +103,12 @@ class HandTrackerV2(ReachyMiniApp):
104
  self.draw(im)
105
  # time.sleep(0.02)
106
 
 
 
 
 
 
 
107
  tracking_thread.join()
108
 
109
 
 
44
  elif self.hand_pos is not None:
45
  self.hand_pos *= 0.9 # Slowly go back to center
46
 
47
+ def track(self, reachy_mini: ReachyMini, stop_event: threading.Event):
48
  target = np.array([0, 0])
49
  pitch_kp = 0.03
50
  yaw_kp = 0.08
 
55
  head_pose = np.eye(4)
56
  euler_rot = np.array([0.0, 0.0, 0.0])
57
 
58
+ while not stop_event.is_set():
59
  if self.hand_pos is None:
60
+ time.sleep(dt)
61
  continue
62
  error = target - self.hand_pos
63
  error = np.clip(
 
75
  "xyz", euler_rot, degrees=False
76
  ).as_matrix()
77
 
78
+ head_pose[:3, 3][2] = error[1] * kz # Adjust height based on vertical error
 
 
79
 
80
  reachy_mini.set_target(head=head_pose)
81
 
 
85
  reachy_mini.goto_target(np.eye(4), [0.0, 0.0], body_yaw=0.0, duration=1.0)
86
 
87
  tracking_thread = threading.Thread(
88
+ target=self.track, args=(reachy_mini, stop_event)
89
  )
90
  tracking_thread.start()
91
 
 
103
  self.draw(im)
104
  # time.sleep(0.02)
105
 
106
+ if DEBUG:
107
+ try:
108
+ cv2.destroyAllWindows()
109
+ except Exception:
110
+ pass
111
+
112
  tracking_thread.join()
113
 
114