@@ -439,6 +439,72 @@ def _is_left_arm_motion_complete(self, atol=0.01):
439439 if not self ._is_joint_positions_reached (module , target_positions , atol ):
440440 return False
441441 return True
442+
443+ def _is_right_arm_motion_complete (self , atol = 0.01 ):
444+ """Check if right arm has reached its target position."""
445+ for module_name , target_positions in self .target_joint_positions .items ():
446+ module = getattr (self .interface , module_name )
447+ if not self ._is_joint_positions_reached (module , target_positions , atol ):
448+ return False
449+ return True
450+
451+ def _move_left_arm_to_pose (self , target_position , target_orientation ):
452+ """Move left arm to target pose with IK solving and motion control.
453+
454+ Args:
455+ target_position: Target position [x, y, z]
456+ target_orientation: Target orientation [qx, qy, qz, qw]
457+
458+ Returns:
459+ True if motion is complete, False otherwise
460+ """
461+ if not self .motion_in_progress :
462+ # Prepare target pose
463+ target_pose = np .concatenate ([target_position , target_orientation ])
464+
465+ # Solve IK and start motion
466+ current_joints = self .mink_config .q
467+ left_arm_joints = self .compute_simple_ik (current_joints , target_pose , "left_arm" )
468+ self ._move_joints_to_target (self .interface .left_arm , left_arm_joints )
469+
470+ # Store target positions for completion check
471+ self .target_joint_positions = {"left_arm" : left_arm_joints }
472+ self .motion_in_progress = True
473+
474+ # Check if motion is complete
475+ if self ._is_left_arm_motion_complete ():
476+ self .motion_in_progress = False
477+ return True
478+ return False
479+
480+ def _move_right_arm_to_pose (self , target_position , target_orientation ):
481+ """Move right arm to target pose with IK solving and motion control.
482+
483+ Args:
484+ target_position: Target position [x, y, z]
485+ target_orientation: Target orientation [qx, qy, qz, qw]
486+
487+ Returns:
488+ True if motion is complete, False otherwise
489+ """
490+ if not self .motion_in_progress :
491+ # Prepare target pose
492+ target_pose = np .concatenate ([target_position , target_orientation ])
493+
494+ # Solve IK and start motion
495+ current_joints = self .mink_config .q
496+ right_arm_joints = self .compute_simple_ik (current_joints , target_pose , "right_arm" )
497+ self ._move_joints_to_target (self .interface .right_arm , right_arm_joints )
498+
499+ # Store target positions for completion check
500+ self .target_joint_positions = {"right_arm" : right_arm_joints }
501+ self .motion_in_progress = True
502+
503+ # Check if motion is complete
504+ if self ._is_right_arm_motion_complete ():
505+ self .motion_in_progress = False
506+ return True
507+ return False
442508
443509 def get_left_gripper_pose (self ):
444510 tmat = np .eye (4 )
@@ -475,75 +541,20 @@ def pick_and_place_callback(self):
475541
476542 def init_state ():
477543 """Move to initial pose"""
478- if not self .motion_in_progress :
479- # Get current joint positions as start configuration
480- current_joints = self .mink_config .q
481-
482- # Solve IK for left arm only
483- left_target_pose = np .array ([0.5 , 0.3 , 0.7 , 0 , 0.7071 , 0 , 0.7071 ])
484- left_arm_joints = self .compute_simple_ik (current_joints , left_target_pose , "left_arm" )
485-
486- # Start motion for left arm only
487- self ._move_joints_to_target (self .interface .left_arm , left_arm_joints )
488-
489- # Store target positions for completion check
490- self .target_joint_positions = {
491- "left_arm" : left_arm_joints
492- }
493- self .motion_in_progress = True
494-
495- # Check if motion is complete
496- if self ._is_left_arm_motion_complete ():
497- self .motion_in_progress = False
498- return True
499- return False
544+ return self ._move_left_arm_to_pose ([0.5 , 0.3 , 0.7 ], [0 , 0.7071 , 0 , 0.7071 ])
500545
501546 def move_to_pre_pick_state ():
502547 """Move to pre-pick position"""
503- if not self .motion_in_progress :
504- if self .state_first_entry :
505- cube_state = self .simulator .get_object_state ("/World/Cube" )
506- self .cube_position = cube_state ["position" ].copy ()
507- self .state_first_entry = False
508-
509- current_joints = self .mink_config .q
510-
511- # Solve IK for left arm only
512- left_target_pose = np .concatenate ([self .cube_position + np .array ([0 , 0 , 0.15 ]), np .array ([0 , 0.7071 , 0 , 0.7071 ])])
513- left_arm_joints = self .compute_simple_ik (current_joints , left_target_pose , "left_arm" )
514-
515- self ._move_joints_to_target (self .interface .left_arm , left_arm_joints )
516-
517- self .target_joint_positions = {
518- "left_arm" : left_arm_joints
519- }
520- self .motion_in_progress = True
548+ if self .state_first_entry :
549+ cube_state = self .simulator .get_object_state ("/World/Cube" )
550+ self .cube_position = cube_state ["position" ].copy ()
551+ self .state_first_entry = False
521552
522- if self ._is_left_arm_motion_complete ():
523- self .motion_in_progress = False
524- return True
525- return False
553+ return self ._move_left_arm_to_pose (self .cube_position + np .array ([0 , 0 , 0.15 ]), [0 , 0.7071 , 0 , 0.7071 ])
526554
527555 def move_to_pick_state ():
528556 """Move to pick position"""
529- if not self .motion_in_progress :
530- current_joints = self .mink_config .q
531-
532- # Solve IK for left arm only
533- left_target_pose = np .concatenate ([self .cube_position + np .array ([0 , 0 , 0.03 ]), np .array ([0 , 0.7071 , 0 , 0.7071 ])])
534- left_arm_joints = self .compute_simple_ik (current_joints , left_target_pose , "left_arm" )
535-
536- self ._move_joints_to_target (self .interface .left_arm , left_arm_joints )
537-
538- self .target_joint_positions = {
539- "left_arm" : left_arm_joints
540- }
541- self .motion_in_progress = True
542-
543- if self ._is_left_arm_motion_complete ():
544- self .motion_in_progress = False
545- return True
546- return False
557+ return self ._move_left_arm_to_pose (self .cube_position + np .array ([0 , 0 , 0.03 ]), [0 , 0.7071 , 0 , 0.7071 ])
547558
548559 def grasp_state ():
549560 """Grasp the object"""
@@ -559,50 +570,16 @@ def grasp_state():
559570
560571 def move_to_pre_place_state ():
561572 """Move to pre-place position"""
562- if not self .motion_in_progress :
563- current_joints = self .mink_config .q
564-
565- # Solve IK for left arm only
566- left_target_pose = np .concatenate ([self .cube_position + np .array ([- 0.1 , 0 , 0.4 ]), np .array ([0 , 0.7071 , 0 , 0.7071 ])])
567- left_arm_joints = self .compute_simple_ik (current_joints , left_target_pose , "left_arm" )
568-
569- self ._move_joints_to_target (self .interface .left_arm , left_arm_joints )
570-
571- self .target_joint_positions = {
572- "left_arm" : left_arm_joints
573- }
574- self .motion_in_progress = True
575-
576- if self ._is_left_arm_motion_complete ():
577- self .motion_in_progress = False
578- return True
579- return False
573+ return self ._move_left_arm_to_pose (self .cube_position + np .array ([- 0.1 , 0 , 0.4 ]), [0 , 0.7071 , 0 , 0.7071 ])
580574
581575 def move_to_place_state ():
582576 """Move to place position"""
583- if not self .motion_in_progress :
584- if self .state_first_entry :
585- bucket_state = self .simulator .get_object_state ("/World/bucket" )
586- self .bucket_position = bucket_state ["position" ].copy ()
587- self .state_first_entry = False
588-
589- current_joints = self .mink_config .q
590-
591- # Solve IK for left arm only
592- left_target_pose = np .concatenate ([self .bucket_position + np .array ([0 , 0 , 0.3 ]), np .array ([0 , 0.7071 , 0 , 0.7071 ])])
593- left_arm_joints = self .compute_simple_ik (current_joints , left_target_pose , "left_arm" )
594-
595- self ._move_joints_to_target (self .interface .left_arm , left_arm_joints )
596-
597- self .target_joint_positions = {
598- "left_arm" : left_arm_joints
599- }
600- self .motion_in_progress = True
601-
602- if self ._is_left_arm_motion_complete ():
603- self .motion_in_progress = False
604- return True
605- return False
577+ if self .state_first_entry :
578+ bucket_state = self .simulator .get_object_state ("/World/bucket" )
579+ self .bucket_position = bucket_state ["position" ].copy ()
580+ self .state_first_entry = False
581+
582+ return self ._move_left_arm_to_pose (self .bucket_position + np .array ([0 , 0 , 0.3 ]), [0 , 0.7071 , 0 , 0.7071 ])
606583
607584 def release_state ():
608585 """Release the object"""
0 commit comments