@@ -319,29 +319,21 @@ def _on_mode_change(event) -> None:
319319 new_mode = self ._mode_dropdown .value .lower ()
320320 if new_mode == self ._gizmo_mode :
321321 return
322- # Sync from the currently visible gizmo
323- if self ._gizmo_mode == "move" :
324- self ._gizmo_rotate .wxyz = self ._gizmo_move .wxyz
325- self ._gizmo_rotate .position = self ._gizmo_move .position
326- else :
327- self ._gizmo_move .wxyz = self ._gizmo_rotate .wxyz
328- self ._gizmo_move .position = self ._gizmo_rotate .position
322+ # Snap both gizmos to the arm's current EE pose to avoid jumps.
323+ # The gizmo that was hidden may have stale position/orientation.
324+ ee_pose = self ._arm .get_ee_pose ()
325+ wxyz = xmat_to_wxyz (ee_pose [:3 , :3 ].flatten ())
326+ pos = tuple (ee_pose [:3 , 3 ])
327+ self ._gizmo_move .wxyz = wxyz
328+ self ._gizmo_move .position = pos
329+ self ._gizmo_rotate .wxyz = wxyz
330+ self ._gizmo_rotate .position = pos
329331 self ._gizmo_mode = new_mode
330332 if self ._is_teleop_active :
331333 self ._gizmo_move .visible = (new_mode == "move" )
332334 self ._gizmo_rotate .visible = (new_mode == "rotate" )
333- # Keep ghost at the same pose
334- active = self ._gizmo_move if new_mode == "move" else self ._gizmo_rotate
335- if self ._ghost is not None :
336- pose = np .eye (4 )
337- w , x , y , z = active .wxyz
338- pose [:3 , :3 ] = np .array ([
339- [1 - 2 * (y * y + z * z ), 2 * (x * y - w * z ), 2 * (x * z + w * y )],
340- [2 * (x * y + w * z ), 1 - 2 * (x * x + z * z ), 2 * (y * z - w * x )],
341- [2 * (x * z - w * y ), 2 * (y * z + w * x ), 1 - 2 * (x * x + y * y )],
342- ])
343- pose [:3 , 3 ] = active .position
344- self ._ghost .set_pose (pose )
335+ if self ._ghost is not None :
336+ self ._ghost .set_pose (ee_pose )
345337
346338 @self ._snap_btn .on_click
347339 def _on_snap (event ) -> None :
0 commit comments