66import rcs
77from rcs import sim
88from rcs .envs .base import ControlMode , GripperWrapper , MultiRobotWrapper , RobotEnv
9- from rcs .envs .space_utils import ActObsInfoWrapper , VecType
9+ from rcs .envs .space_utils import ActObsInfoWrapper
1010from rcs .envs .utils import default_fr3_sim_robot_cfg
1111
1212logger = logging .getLogger (__name__ )
@@ -108,6 +108,8 @@ def observation(self, observation: dict[str, Any], info: dict[str, Any]) -> tupl
108108 state = self ._gripper .get_state ()
109109 if "collision" not in info or not info ["collision" ]:
110110 info ["collision" ] = state .collision
111+ info ["gripper_width" ] = self ._gripper .get_normalized_width ()
112+ info ["is_grasped" ] = self ._gripper .get_normalized_width () > 0.01 and self ._gripper .get_normalized_width () < 0.99
111113 return observation , info
112114
113115
@@ -258,9 +260,9 @@ def reset(
258260 pos_y = iso_cube [1 ] + np .random .random () * 0.2 - 0.1
259261
260262 if self .include_rotation :
261- self .sim .data .joint ("box-joint " ).qpos = [pos_x , pos_y , pos_z , 2 * np .random .random () - 1 , 0 , 0 , 1 ]
263+ self .sim .data .joint ("box_joint " ).qpos = [pos_x , pos_y , pos_z , 2 * np .random .random () - 1 , 0 , 0 , 1 ]
262264 else :
263- self .sim .data .joint ("box-joint " ).qpos = [pos_x , pos_y , pos_z , 0 , 0 , 0 , 1 ]
265+ self .sim .data .joint ("box_joint " ).qpos = [pos_x , pos_y , pos_z , 0 , 0 , 0 , 1 ]
264266
265267 return obs , info
266268
@@ -280,17 +282,17 @@ def step(self, action: dict[str, Any]):
280282 obs , reward , _ , truncated , info = super ().step (action )
281283
282284 success = (
283- self .sim .data .joint ("box-joint " ).qpos [2 ] > 0.15 + 0.852
285+ self .sim .data .joint ("box_joint " ).qpos [2 ] > 0.15 + 0.852
284286 and obs ["gripper" ] == GripperWrapper .BINARY_GRIPPER_CLOSED
285287 )
286288 info ["success" ] = success
287289 if success :
288290 reward = 5
289291 else :
290292 tcp_to_obj_dist = np .linalg .norm (
291- self .sim .data .joint ("box-joint " ).qpos [:3 ] - self .unwrapped .robot .get_cartesian_position ().translation ()
293+ self .sim .data .joint ("box_joint " ).qpos [:3 ] - self .unwrapped .robot .get_cartesian_position ().translation ()
292294 )
293- obj_to_goal_dist = np .linalg .norm (self .sim .data .joint ("box-joint " ).qpos [:3 ] - self .EE_HOME )
295+ obj_to_goal_dist = np .linalg .norm (self .sim .data .joint ("box_joint " ).qpos [:3 ] - self .EE_HOME )
294296
295297 # old reward
296298 # reward = -obj_to_goal_dist - tcp_to_obj_dist
@@ -311,29 +313,3 @@ def step(self, action: dict[str, Any]):
311313 # normalize
312314 reward /= 5 # type: ignore
313315 return obs , reward , success , truncated , info
314-
315-
316- class CamRobot (gym .Wrapper ):
317- """Use this wrapper in lab setups where the second arm is used as a camera holder."""
318-
319- def __init__ (self , env , cam_robot_joints : VecType , scene : str = "lab_simple_pick_up_digit_hand" ):
320- super ().__init__ (env )
321- self .unwrapped : RobotEnv
322- assert isinstance (self .unwrapped .robot , sim .SimRobot ), "Robot must be a sim.SimRobot instance."
323- self .sim = env .get_wrapper_attr ("sim" )
324- cfg = default_fr3_sim_robot_cfg (scene , "1" )
325- self .cam_robot = rcs .sim .SimRobot (
326- self .sim , env .unwrapped .robot .get_ik (), cfg , register_convergence_callback = False
327- )
328- self .cam_robot .set_parameters (default_fr3_sim_robot_cfg (scene ))
329- self .cam_robot_joints = cam_robot_joints
330-
331- def step (self , action : dict ):
332- self .cam_robot .set_joints_hard (self .cam_robot_joints )
333- obs , reward , done , truncated , info = super ().step (action )
334- return obs , reward , done , truncated , info
335-
336- def reset (self , * , seed = None , options = None ):
337- re = super ().reset (seed = seed , options = options )
338- self .cam_robot .reset ()
339- return re
0 commit comments