102
102
m .LOW_PRECISION_DIST_THRESHOLD = 0.1
103
103
m .LOW_PRECISION_ANGLE_THRESHOLD = 0.2
104
104
105
- m .JOINT_POS_DIFF_THRESHOLD = 0.01
105
+ m .JOINT_POS_DIFF_THRESHOLD = 0.005
106
106
m .LOW_PRECISION_JOINT_POS_DIFF_THRESHOLD = 0.05
107
107
m .JOINT_CONTROL_MIN_ACTION = 0.0
108
108
m .MAX_ALLOWED_JOINT_ERROR_FOR_LINEAR_MOTION = math .radians (45 )
@@ -506,7 +506,10 @@ def _sample_grasp_pose(self, obj):
506
506
# Identity quaternion for top-down grasping (x-forward, y-right, z-down)
507
507
approach_dir = T .quat2mat (grasp_quat ) @ th .tensor ([0.0 , 0.0 , - 1.0 ])
508
508
509
- pregrasp_offset = self .robot .finger_lengths [self .arm ] / 2.0 + m .GRASP_APPROACH_DISTANCE
509
+ avg_finger_offset = th .mean (
510
+ th .tensor ([length for length in self .robot .eef_to_fingertip_lengths [self .arm ].values ()])
511
+ )
512
+ pregrasp_offset = avg_finger_offset + m .GRASP_APPROACH_DISTANCE
510
513
511
514
pregrasp_pos = grasp_pos - approach_dir * pregrasp_offset
512
515
@@ -581,7 +584,7 @@ def _grasp(self, obj):
581
584
# By default, it's NOT the z-axis of the world frame unless `project_pose_to_goal_frame=False` is set in curobo.
582
585
# For sticky grasping, we also need to ignore the object during motion planning because the fingers are already closed.
583
586
yield from self ._move_hand (
584
- grasp_pose , motion_constraint = [1 , 1 , 1 , 1 , 1 , 0 ], stop_on_contact = True , ignore_objects = [obj ]
587
+ grasp_pose , motion_constraint = [1 , 1 , 1 , 1 , 1 , 0 ], stop_on_ag = True , ignore_objects = [obj ]
585
588
)
586
589
elif self .robot .grasping_mode == "assisted" :
587
590
indented_print ("Assisted grasping: approach" )
@@ -853,6 +856,7 @@ def _move_hand(
853
856
self ,
854
857
target_pose ,
855
858
stop_on_contact = False ,
859
+ stop_on_ag = False ,
856
860
motion_constraint = None ,
857
861
low_precision = False ,
858
862
lock_auxiliary_arm = False ,
@@ -864,6 +868,7 @@ def _move_hand(
864
868
Args:
865
869
target_pose (Tuple[th.tensor, th.tensor]): target pose to reach for the default end-effector in the world frame
866
870
stop_on_contact (bool): Whether to stop executing motion plan if contact is detected
871
+ stop_on_ag (bool): Whether to stop executing motion plan if assisted grasping is activated
867
872
motion_constraint (MotionConstraint): Motion constraint for the motion
868
873
low_precision (bool): Whether to use low precision for the motion
869
874
lock_auxiliary_arm (bool): Whether to lock the other arm in place
@@ -906,7 +911,9 @@ def _move_hand(
906
911
)
907
912
908
913
indented_print (f"Plan has { len (q_traj )} steps" )
909
- yield from self ._execute_motion_plan (q_traj , stop_on_contact = stop_on_contact , low_precision = low_precision )
914
+ yield from self ._execute_motion_plan (
915
+ q_traj , stop_on_contact = stop_on_contact , stop_on_ag = stop_on_ag , low_precision = low_precision
916
+ )
910
917
911
918
def _plan_joint_motion (
912
919
self ,
@@ -972,7 +979,13 @@ def _plan_joint_motion(
972
979
return q_traj
973
980
974
981
def _execute_motion_plan (
975
- self , q_traj , stop_on_contact = False , ignore_failure = False , low_precision = False , ignore_physics = False
982
+ self ,
983
+ q_traj ,
984
+ stop_on_contact = False ,
985
+ stop_on_ag = False ,
986
+ ignore_failure = False ,
987
+ low_precision = False ,
988
+ ignore_physics = False ,
976
989
):
977
990
for i , joint_pos in enumerate (q_traj ):
978
991
# indented_print(f"Executing motion plan step {i + 1}/{len(q_traj)}")
@@ -992,6 +1005,12 @@ def _execute_motion_plan(
992
1005
articulation_control_idx = th .cat (articulation_control_idx )
993
1006
for j in range (m .MAX_STEPS_FOR_JOINT_MOTION ):
994
1007
# indented_print(f"Step {j + 1}/{m.MAX_STEPS_FOR_JOINT_MOTION}")
1008
+
1009
+ # We need to call @q_to_action for every step because as the robot base moves, the same base joint_pos will be
1010
+ # converted to different actions, since HolonomicBaseJointController accepts an action in the robot local frame.
1011
+ action = self .robot .q_to_action (joint_pos )
1012
+ yield self ._postprocess_action (action )
1013
+
995
1014
current_joint_pos = self .robot .get_joint_positions ()
996
1015
joint_pos_diff = joint_pos - current_joint_pos
997
1016
base_joint_diff = joint_pos_diff [self .robot .base_control_idx ]
@@ -1014,14 +1033,10 @@ def _execute_motion_plan(
1014
1033
1015
1034
collision_detected = detect_robot_collision_in_sim (self .robot )
1016
1035
if stop_on_contact and collision_detected :
1017
- indented_print (f"Collision detected at step { i + 1 } /{ len (q_traj )} " )
1018
1036
return
1019
1037
1020
- # We need to call @q_to_action for every step because as the robot base moves, the same base joint_pos will be
1021
- # converted to different actions, since HolonomicBaseJointController accepts an action in the robot local frame.
1022
- action = self .robot .q_to_action (joint_pos )
1023
-
1024
- yield self ._postprocess_action (action )
1038
+ if stop_on_ag and self ._get_obj_in_hand () is not None :
1039
+ return
1025
1040
1026
1041
if not ignore_failure :
1027
1042
if not base_target_reached :
@@ -1334,13 +1349,13 @@ def _move_fingers_to_limit(self, limit_type):
1334
1349
target_joint_positions = self ._get_joint_position_with_fingers_at_limit (limit_type )
1335
1350
action = self .robot .q_to_action (target_joint_positions )
1336
1351
for _ in range (m .MAX_STEPS_FOR_GRASP_OR_RELEASE ):
1337
- current_joint_positinos = self .robot .get_joint_positions ()
1338
- if th .allclose (current_joint_positinos , target_joint_positions , atol = 0.005 ):
1352
+ yield self ._postprocess_action (action )
1353
+ current_joint_positions = self .robot .get_joint_positions ()
1354
+ if th .allclose (current_joint_positions , target_joint_positions , atol = m .JOINT_POS_DIFF_THRESHOLD ):
1339
1355
break
1340
1356
elif limit_type == "lower" and self ._get_obj_in_hand () is not None :
1341
1357
# If we are grasping an object, we should stop when object is detected in hand
1342
1358
break
1343
- yield self ._postprocess_action (action )
1344
1359
1345
1360
def _execute_grasp (self ):
1346
1361
"""
0 commit comments