@@ -286,7 +286,11 @@ def _on_gizmo_update(event) -> None:
286286 with gui .add_folder (self ._arm_label ):
287287 self ._activate_btn = gui .add_button ("Activate" , color = "green" )
288288 self ._status_md = gui .add_markdown ("⚪ **Idle**" )
289- self ._mode_btn = gui .add_button ("Mode: Move" )
289+ self ._mode_dropdown = gui .add_dropdown (
290+ "Gizmo Mode" ,
291+ options = ["Move" , "Rotate" ],
292+ initial_value = "Move" ,
293+ )
290294 self ._snap_btn = gui .add_button ("Snap to EE" )
291295 self ._gripper_btn = gui .add_button ("Toggle Gripper" )
292296
@@ -310,26 +314,34 @@ def _on_activate(event) -> None:
310314 else :
311315 self ._activate_teleop ()
312316
313- @self ._mode_btn .on_click
314- def _on_mode_toggle (event ) -> None :
317+ @self ._mode_dropdown .on_update
318+ def _on_mode_change (event ) -> None :
319+ new_mode = self ._mode_dropdown .value .lower ()
320+ if new_mode == self ._gizmo_mode :
321+ return
322+ # Sync from the currently visible gizmo
315323 if self ._gizmo_mode == "move" :
316- # Sync rotate gizmo to current move gizmo pose before switching
317324 self ._gizmo_rotate .wxyz = self ._gizmo_move .wxyz
318325 self ._gizmo_rotate .position = self ._gizmo_move .position
319- self ._gizmo_mode = "rotate"
320- self ._mode_btn .name = "Mode: Rotate"
321- if self ._is_teleop_active :
322- self ._gizmo_move .visible = False
323- self ._gizmo_rotate .visible = True
324326 else :
325- # Sync move gizmo to current rotate gizmo pose before switching
326327 self ._gizmo_move .wxyz = self ._gizmo_rotate .wxyz
327328 self ._gizmo_move .position = self ._gizmo_rotate .position
328- self ._gizmo_mode = "move"
329- self ._mode_btn .name = "Mode: Move"
330- if self ._is_teleop_active :
331- self ._gizmo_rotate .visible = False
332- self ._gizmo_move .visible = True
329+ self ._gizmo_mode = new_mode
330+ if self ._is_teleop_active :
331+ self ._gizmo_move .visible = (new_mode == "move" )
332+ 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 )
333345
334346 @self ._snap_btn .on_click
335347 def _on_snap (event ) -> None :
0 commit comments