|
| 1 | +import logging |
| 2 | + |
| 3 | +import numpy as np |
| 4 | +from rcs.envs.base import ControlMode, RelativeTo |
| 5 | +from rcs.envs.creators import SimEnvCreator |
| 6 | + |
| 7 | +import rcs |
| 8 | +from rcs import sim |
| 9 | + |
| 10 | +logger = logging.getLogger(__name__) |
| 11 | +logger.setLevel(logging.INFO) |
| 12 | + |
| 13 | + |
| 14 | +def main(): |
| 15 | + |
| 16 | + robot_cfg = sim.SimRobotConfig() |
| 17 | + robot_cfg.actuators = ["1", "2", "3", "4", "5"] |
| 18 | + robot_cfg.joints = [ |
| 19 | + "1", |
| 20 | + "2", |
| 21 | + "3", |
| 22 | + "4", |
| 23 | + "5", |
| 24 | + ] |
| 25 | + robot_cfg.base = "base" |
| 26 | + robot_cfg.robot_type = rcs.common.RobotType.UR5e |
| 27 | + robot_cfg.attachment_site = "gripper" |
| 28 | + robot_cfg.arm_collision_geoms = [] |
| 29 | + gripper_cfg = sim.SimGripperConfig |
| 30 | + gripper_cfg.min_actuator_width = -0.17453292519943295 |
| 31 | + gripper_cfg.max_actuator_width = 1.7453292519943295 |
| 32 | + gripper_cfg.min_joint_width = -0.17453292519943295 |
| 33 | + gripper_cfg.max_joint_width = 1.7453292519943295 |
| 34 | + env_rel = SimEnvCreator()( |
| 35 | + control_mode=ControlMode.JOINTS, |
| 36 | + collision_guard=False, |
| 37 | + robot_cfg=robot_cfg, |
| 38 | + gripper_cfg=gripper_cfg, |
| 39 | + # cameras=default_mujoco_cameraset_cfg(), |
| 40 | + max_relative_movement=np.deg2rad(5), |
| 41 | + relative_to=RelativeTo.LAST_STEP, |
| 42 | + mjcf=rcs.scenes["so101_empty_world"]["mjb"], |
| 43 | + urdf_path=rcs.scenes["so101_empty_world"]["urdf"], |
| 44 | + ) |
| 45 | + env_rel.get_wrapper_attr("sim").open_gui() |
| 46 | + |
| 47 | + for _ in range(10): |
| 48 | + obs, info = env_rel.reset() |
| 49 | + for _ in range(10): |
| 50 | + # sample random relative action and execute it |
| 51 | + act = env_rel.action_space.sample() |
| 52 | + obs, reward, terminated, truncated, info = env_rel.step(act) |
| 53 | + if truncated or terminated: |
| 54 | + logger.info("Truncated or terminated!") |
| 55 | + return |
| 56 | + |
| 57 | + |
| 58 | +if __name__ == "__main__": |
| 59 | + main() |
0 commit comments