11import logging
2- from time import sleep
32import math
3+ from time import sleep
44
55import numpy as np
66from rcs ._core .common import RobotPlatform
77from rcs .envs .base import ControlMode , RelativeTo
88from rcs .envs .creators import SimEnvCreator
9- from rcs .envs .utils import get_tcp_offset
10- from rcs_xarm7 .creators import RCSXArm7EnvCreator , XArm7SimEnvCreator
9+ from rcs .envs .utils import default_sim_tilburg_hand_cfg , get_tcp_offset
1110from rcs .hand .tilburg_hand import THConfig
11+ from rcs_xarm7 .creators import RCSXArm7EnvCreator , XArm7SimEnvCreator
12+
1213import rcs
1314from rcs import sim
1415
2021ROBOT_INSTANCE = RobotPlatform .HARDWARE
2122
2223
24+ def sim_env ():
25+ robot_cfg = sim .SimRobotConfig ()
26+ robot_cfg .actuators = [
27+ "act1" ,
28+ "act2" ,
29+ "act3" ,
30+ "act4" ,
31+ "act5" ,
32+ "act6" ,
33+ "act7" ,
34+ ]
35+ robot_cfg .joints = [
36+ "joint1" ,
37+ "joint2" ,
38+ "joint3" ,
39+ "joint4" ,
40+ "joint5" ,
41+ "joint6" ,
42+ "joint7" ,
43+ ]
44+ robot_cfg .base = "base"
45+ robot_cfg .robot_type = rcs .common .RobotType .XArm7
46+ robot_cfg .attachment_site = "attachment_site"
47+ robot_cfg .arm_collision_geoms = []
48+ robot_cfg .tcp_offset = get_tcp_offset (rcs .scenes ["xarm7_empty_world" ]["mjcf_robot" ])
49+ env_rel = SimEnvCreator ()(
50+ control_mode = ControlMode .JOINTS ,
51+ collision_guard = False ,
52+ robot_cfg = robot_cfg ,
53+ gripper_cfg = None ,
54+ hand_cfg = default_sim_tilburg_hand_cfg (),
55+ # cameras=default_mujoco_cameraset_cfg(),
56+ # max_relative_movement=0.5,
57+ relative_to = RelativeTo .LAST_STEP ,
58+ # mjcf=rcs.scenes["xarm7_empty_world"]["mjb"],
59+ robot_kinematics_path = rcs .scenes ["xarm7_empty_world" ]["mjcf_robot" ],
60+ mjcf = "/home/ken/robot-control-stack/models/scenes/xarm7_tilburg/scene.xml" ,
61+ )
62+ env_rel .get_wrapper_attr ("sim" ).open_gui ()
63+ return env_rel
64+
65+
2366def main ():
2467
2568 if ROBOT_INSTANCE == RobotPlatform .HARDWARE :
2669 hand_cfg = THConfig (
27- calibration_file = "/home/ken/tilburg_hand/calibration.json" ,
28- grasp_percentage = 1 ,
29- hand_orientation = "right"
70+ calibration_file = "/home/ken/tilburg_hand/calibration.json" , grasp_percentage = 1 , hand_orientation = "right"
3071 )
3172 env_rel = RCSXArm7EnvCreator ()(
3273 control_mode = ControlMode .JOINTS ,
@@ -36,73 +77,45 @@ def main():
3677 max_relative_movement = None ,
3778 )
3879 else :
39- robot_cfg = sim .SimRobotConfig ()
40- robot_cfg .actuators = [
41- "act1" ,
42- "act2" ,
43- "act3" ,
44- "act4" ,
45- "act5" ,
46- "act6" ,
47- "act7" ,
48- ]
49- robot_cfg .joints = [
50- "joint1" ,
51- "joint2" ,
52- "joint3" ,
53- "joint4" ,
54- "joint5" ,
55- "joint6" ,
56- "joint7" ,
57- ]
58- robot_cfg .base = "base"
59- robot_cfg .robot_type = rcs .common .RobotType .XArm7
60- robot_cfg .attachment_site = "attachment_site"
61- robot_cfg .arm_collision_geoms = []
62- robot_cfg .tcp_offset = get_tcp_offset (rcs .scenes ["xarm7_empty_world" ]["mjcf_robot" ])
63- env_rel = SimEnvCreator ()(
64- control_mode = ControlMode .CARTESIAN_TQuat ,
65- collision_guard = False ,
66- robot_cfg = robot_cfg ,
67- gripper_cfg = None ,
68- # cameras=default_mujoco_cameraset_cfg(),
69- max_relative_movement = 0.5 ,
70- relative_to = RelativeTo .LAST_STEP ,
71- mjcf = rcs .scenes ["xarm7_empty_world" ]["mjb" ],
72- robot_kinematics_path = rcs .scenes ["xarm7_empty_world" ]["mjcf_robot" ],
73- )
74- env_rel .get_wrapper_attr ("sim" ).open_gui ()
80+ env_rel = sim_env ()
81+
82+ twin_env = sim_env ()
83+ twin_robot = twin_env .unwrapped .robot
84+ twin_sim = twin_env .get_wrapper_attr ("sim" )
7585
7686 env_rel .reset ()
7787
7888 actions = [
7989 # open hand
80- ( [0 , math .radians (- 45 ), 0 , math .radians (15 ), 0 , math .radians (- 25 ), 0 ], 1 , 2.0 ),
90+ ([0 , math .radians (- 45 ), 0 , math .radians (15 ), 0 , math .radians (- 25 ), 0 ], 1 , 2.0 ),
8191 # approach
82- ( [0 , math .radians (45 ), 0 , math .radians (40 ), 0 , math .radians (- 95 ), 0 ], 1 , 2.0 ),
92+ ([0 , math .radians (45 ), 0 , math .radians (40 ), 0 , math .radians (- 95 ), 0 ], 1 , 2.0 ),
8393 # close hand
84- ( [0 , math .radians (45 ), 0 , math .radians (40 ), 0 , math .radians (- 95 ), 0 ], 0 , 2.0 ),
94+ ([0 , math .radians (45 ), 0 , math .radians (40 ), 0 , math .radians (- 95 ), 0 ], 0 , 2.0 ),
8595 # lift
86- ( [0 , math .radians (15 ), 0 , math .radians (30 ), 0 , math .radians (- 75 ), 0 ], 0 , 4.0 ),
96+ ([0 , math .radians (15 ), 0 , math .radians (30 ), 0 , math .radians (- 75 ), 0 ], 0 , 4.0 ),
8797 # put back
88- ( [0 , math .radians (45 ), 0 , math .radians (40 ), 0 , math .radians (- 95 ), 0 ], 0 , 2.0 ),
98+ ([0 , math .radians (45 ), 0 , math .radians (40 ), 0 , math .radians (- 95 ), 0 ], 0 , 2.0 ),
8999 # open hand
90- ( [0 , math .radians (45 ), 0 , math .radians (40 ), 0 , math .radians (- 95 ), 0 ], 1 , 2.0 ),
100+ ([0 , math .radians (45 ), 0 , math .radians (40 ), 0 , math .radians (- 95 ), 0 ], 1 , 2.0 ),
91101 # back to home
92- ( [0 , math .radians (- 45 ), 0 , math .radians (15 ), 0 , math .radians (- 25 ), 0 ], 1 , 0.0 ),
102+ ([0 , math .radians (- 45 ), 0 , math .radians (15 ), 0 , math .radians (- 25 ), 0 ], 1 , 0.0 ),
93103 ]
94104
95105 with env_rel :
96106 for joints , hand , delay in actions :
97107 act = {"joints" : joints , "hand" : hand }
108+ twin_env .step (act )
98109 obs , reward , terminated , truncated , info = env_rel .step (act )
110+ # twin_robot.set_joint_position(joints)
111+ # twin_sim.step(50)
112+ sleep (1 )
99113 if truncated or terminated :
100114 logger .info ("Truncated or terminated!" )
101115 break
102116 if delay > 0 :
103117 sleep (delay )
104118
105119
106-
107120if __name__ == "__main__" :
108121 main ()
0 commit comments