66import mujoco
77import numpy as np
88from rcs ._core .common import Pose
9- from rcs .envs .base import GripperWrapper , RobotEnv
9+ from rcs ._core .sim import SimRobot
10+ from rcs .envs .base import GripperWrapper
1011from rcs .envs .creators import FR3SimplePickUpSimEnvCreator
1112
1213logger = logging .getLogger (__name__ )
1617class PickUpDemo :
1718 def __init__ (self , env : gym .Env ):
1819 self .env = env
19- self .unwrapped : RobotEnv = cast (RobotEnv , self .env .unwrapped )
20- self .home_pose = self .unwrapped . robot .get_cartesian_position ()
20+ self ._robot = cast (SimRobot , self .env .get_wrapper_attr ( "robot" ) )
21+ self .home_pose = self ._robot .get_cartesian_position ()
2122
2223 def _action (self , pose : Pose , gripper : list [float ]) -> dict [str , Any ]:
2324 return {"xyzrpy" : pose .xyzrpy (), "gripper" : [gripper ]}
@@ -32,7 +33,7 @@ def get_object_pose(self, geom_name) -> Pose:
3233 ) * Pose (
3334 rpy_vector = np .array ([0 , 0 , np .pi ]), translation = [0 , 0 , 0 ] # type: ignore
3435 )
35- return self .unwrapped . robot .to_pose_in_robot_coordinates (obj_pose_world_coordinates )
36+ return self ._robot .to_pose_in_robot_coordinates (obj_pose_world_coordinates )
3637
3738 def generate_waypoints (self , start_pose : Pose , end_pose : Pose , num_waypoints : int ) -> list [Pose ]:
3839 waypoints = []
@@ -45,12 +46,13 @@ def step(self, action: dict) -> dict:
4546 return self .env .step (action )[0 ]
4647
4748 def plan_linear_motion (self , geom_name : str , delta_up : float , num_waypoints : int = 20 ) -> list [Pose ]:
48- end_eff_pose = self .unwrapped . robot .get_cartesian_position ()
49+ end_eff_pose = self ._robot .get_cartesian_position ()
4950 goal_pose = self .get_object_pose (geom_name = geom_name )
5051 goal_pose *= Pose (translation = np .array ([0 , 0 , delta_up ]), quaternion = np .array ([1 , 0 , 0 , 0 ])) # type: ignore
5152 return self .generate_waypoints (end_eff_pose , goal_pose , num_waypoints = num_waypoints )
5253
5354 def execute_motion (self , waypoints : list [Pose ], gripper : list [float ] = GripperWrapper .BINARY_GRIPPER_OPEN ) -> dict :
55+ obs = {}
5456 for i in range (len (waypoints )):
5557 obs = self .step (self ._action (waypoints [i ], gripper ))
5658 return obs
@@ -65,13 +67,13 @@ def grasp(self, geom_name: str):
6567 self .execute_motion (waypoints = waypoints , gripper = GripperWrapper .BINARY_GRIPPER_OPEN )
6668
6769 for _ in range (4 ):
68- self .step (self ._action (self .unwrapped . robot .get_cartesian_position (), GripperWrapper .BINARY_GRIPPER_CLOSED ))
70+ self .step (self ._action (self ._robot .get_cartesian_position (), GripperWrapper .BINARY_GRIPPER_CLOSED ))
6971
7072 waypoints = self .plan_linear_motion (geom_name = geom_name , delta_up = 0.2 , num_waypoints = 60 )
7173 self .execute_motion (waypoints = waypoints , gripper = GripperWrapper .BINARY_GRIPPER_CLOSED )
7274
7375 def move_home (self ):
74- end_eff_pose = self .unwrapped . robot .get_cartesian_position ()
76+ end_eff_pose = self ._robot .get_cartesian_position ()
7577 waypoints = self .generate_waypoints (end_eff_pose , self .home_pose , num_waypoints = 60 )
7678 self .execute_motion (waypoints = waypoints , gripper = GripperWrapper .BINARY_GRIPPER_CLOSED )
7779
@@ -90,7 +92,7 @@ def main():
9092 sleep (3 )
9193 for _ in range (100 ):
9294 env .reset ()
93- print (env .unwrapped . robot .get_cartesian_position ().translation ()) # type: ignore
95+ print (env .get_wrapper_attr ( " robot" ) .get_cartesian_position ().translation ()) # type: ignore
9496 controller = PickUpDemo (env )
9597 controller .pickup ("box_geom" )
9698
0 commit comments