drenayaz commited on
Commit
1eb2bda
·
1 Parent(s): 8b2dcf1

Tune head tracking KP gains

Browse files
Files changed (1) hide show
  1. hand_tracker_v2/main.py +9 -7
hand_tracker_v2/main.py CHANGED
@@ -166,16 +166,17 @@ class HandTrackerV2(ReachyMiniApp):
166
  else:
167
  self.number_hands = len(hands)
168
  if hands:
169
-
170
  # Reset IDLE TIMER
171
  self.last_hand_seen = time.time()
172
  self.is_idle = False
173
  rightmost_hand = min(hands, key=lambda h: h["palm"][0])
174
  leftmost_hand = max(hands, key=lambda h: h["palm"][0])
 
175
  if self.preferred_side == "Left":
176
  self.hand_pos = np.array(leftmost_hand["palm"])
177
  else:
178
  self.hand_pos = np.array(rightmost_hand["palm"])
 
179
  self.left_antenna_angle = - finger_orientation_deg(
180
  rightmost_hand["index_mcp"], rightmost_hand["index_tip"]
181
  )
@@ -197,13 +198,14 @@ class HandTrackerV2(ReachyMiniApp):
197
 
198
  def track(self, reachy_mini: ReachyMini, stop_event: threading.Event):
199
  target = np.array([0, 0])
200
- pitch_kp = 0.02
201
- yaw_kp = 0.035
202
- kz = 0.02
203
- max_delta = 0.3
204
  max_antenna_delta = np.radians(5)
205
  head_pose = np.eye(4)
206
  euler_rot = np.array([0.0, 0.0, 0.0])
 
 
207
 
208
  while not stop_event.is_set():
209
  self.hand_count_history.append(self.number_hands)
@@ -213,7 +215,6 @@ class HandTrackerV2(ReachyMiniApp):
213
  if len(self.hand_count_history) == self.hand_count_buffer_size:
214
  stable_hand_count = self.hand_count_history[0]
215
  if all(count == stable_hand_count for count in self.hand_count_history):
216
- # Le nombre de mains est stable, comparer avec précédent
217
  if stable_hand_count > self.previous_number_hands:
218
  self.play_sound(reachy_mini, "success2")
219
  elif stable_hand_count < self.previous_number_hands:
@@ -268,6 +269,7 @@ class HandTrackerV2(ReachyMiniApp):
268
 
269
  # Tracking error
270
  error = target - self.hand_pos
 
271
  error = np.clip(error, -max_delta, max_delta)
272
 
273
  # Update head orientation
@@ -285,7 +287,7 @@ class HandTrackerV2(ReachyMiniApp):
285
 
286
  # Compute new head pose
287
  head_pose[:3, :3] = R.from_euler("xyz", euler_rot).as_matrix()
288
- head_pose[:3, 3][2] = error[1] * kz
289
 
290
  if not self.antenna_tracking:
291
  antennas = self.previous_antenna_angles.copy()
 
166
  else:
167
  self.number_hands = len(hands)
168
  if hands:
 
169
  # Reset IDLE TIMER
170
  self.last_hand_seen = time.time()
171
  self.is_idle = False
172
  rightmost_hand = min(hands, key=lambda h: h["palm"][0])
173
  leftmost_hand = max(hands, key=lambda h: h["palm"][0])
174
+
175
  if self.preferred_side == "Left":
176
  self.hand_pos = np.array(leftmost_hand["palm"])
177
  else:
178
  self.hand_pos = np.array(rightmost_hand["palm"])
179
+
180
  self.left_antenna_angle = - finger_orientation_deg(
181
  rightmost_hand["index_mcp"], rightmost_hand["index_tip"]
182
  )
 
198
 
199
  def track(self, reachy_mini: ReachyMini, stop_event: threading.Event):
200
  target = np.array([0, 0])
201
+ pitch_kp = 0.024
202
+ yaw_kp = 0.028
203
+ max_delta = 0.6
 
204
  max_antenna_delta = np.radians(5)
205
  head_pose = np.eye(4)
206
  euler_rot = np.array([0.0, 0.0, 0.0])
207
+ dead_zone = 0.05
208
+
209
 
210
  while not stop_event.is_set():
211
  self.hand_count_history.append(self.number_hands)
 
215
  if len(self.hand_count_history) == self.hand_count_buffer_size:
216
  stable_hand_count = self.hand_count_history[0]
217
  if all(count == stable_hand_count for count in self.hand_count_history):
 
218
  if stable_hand_count > self.previous_number_hands:
219
  self.play_sound(reachy_mini, "success2")
220
  elif stable_hand_count < self.previous_number_hands:
 
269
 
270
  # Tracking error
271
  error = target - self.hand_pos
272
+ error[np.abs(error) < dead_zone] = 0.0
273
  error = np.clip(error, -max_delta, max_delta)
274
 
275
  # Update head orientation
 
287
 
288
  # Compute new head pose
289
  head_pose[:3, :3] = R.from_euler("xyz", euler_rot).as_matrix()
290
+ # head_pose[:3, 3][2] = error[1] * kz
291
 
292
  if not self.antenna_tracking:
293
  antennas = self.previous_antenna_angles.copy()