Skip to content

Commit 934b99e

Browse files
committed
refactor: removed get tcp offset from mjcf utility
1 parent 801800f commit 934b99e

9 files changed

Lines changed: 5 additions & 67 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ from rcs import sim
6565
from rcs._core.sim import CameraType
6666
from rcs.camera.sim import SimCameraConfig, SimCameraSet
6767
from time import sleep
68-
simulation = sim.Sim(rcs.scenes["fr3_empty_world"]["mjb"])
69-
urdf_path = rcs.scenes["fr3_empty_world"]["urdf"]
68+
simulation = sim.Sim(rcs.scenes["fr3_empty_world"].mjb)
69+
urdf_path = rcs.scenes["fr3_empty_world"].urdf
7070
ik = rcs.common.RL(str(urdf_path))
7171
cfg = sim.SimRobotConfig()
7272
cfg.add_id("0")

examples/xarm7_env_cartesian_control.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from rcs.envs.base import ControlMode, RelativeTo
44
from rcs.envs.creators import SimEnvCreator
5-
from rcs.envs.utils import get_tcp_offset
65

76
import rcs
87
from rcs import sim
@@ -36,7 +35,6 @@ def main():
3635
robot_cfg.robot_type = rcs.common.RobotType.XArm7
3736
robot_cfg.attachment_site = "attachment_site"
3837
robot_cfg.arm_collision_geoms = []
39-
robot_cfg.tcp_offset = get_tcp_offset(rcs.scenes["xarm7_empty_world"].mjcf_scene)
4038
robot_cfg.mjcf_scene_path = rcs.scenes["xarm7_empty_world"].mjb
4139
robot_cfg.kinematic_model_path = rcs.scenes["xarm7_empty_world"].mjcf_robot
4240
env_rel = SimEnvCreator()(

examples/xarm7_env_joint_control.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import numpy as np
44
from rcs.envs.base import ControlMode, RelativeTo
55
from rcs.envs.creators import SimEnvCreator
6-
from rcs.envs.utils import get_tcp_offset
76

87
import rcs
98
from rcs import sim
@@ -36,7 +35,6 @@ def main():
3635
robot_cfg.robot_type = rcs.common.RobotType.XArm7
3736
robot_cfg.attachment_site = "attachment_site"
3837
robot_cfg.arm_collision_geoms = []
39-
robot_cfg.tcp_offset = get_tcp_offset(rcs.scenes["xarm7_empty_world"].mjcf_scene)
4038
robot_cfg.mjcf_scene_path = rcs.scenes["xarm7_empty_world"].mjb
4139
robot_cfg.kinematic_model_path = rcs.scenes["xarm7_empty_world"].mjcf_robot
4240
env_rel = SimEnvCreator()(

extensions/rcs_fr3/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ from rcs_fr3._core import hw
1919
from rcs_fr3.desk import FCI, ContextManager, Desk, load_creds_fr3_desk
2020
user, pw = load_creds_fr3_desk()
2121
with FCI(Desk(ROBOT_IP, user, pw), unlock=False, lock_when_done=False):
22-
urdf_path = rcs.scenes["fr3_empty_world"]["urdf"]
22+
urdf_path = rcs.scenes["fr3_empty_world"].urdf
2323
ik = rcs.common.RL(str(urdf_path))
2424
robot = hw.FR3(ROBOT_IP, ik)
2525
robot_cfg = FR3Config()

extensions/rcs_xarm7/src/rcs_xarm7/creators.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ def __call__( # type: ignore
3737
control_mode: ControlMode,
3838
ip: str,
3939
calibration_dir: PathLike | str | None = None,
40-
collision_guard: str | PathLike | None = None,
41-
cg_kinematics_path: str | PathLike | None = None,
4240
camera_set: HardwareCameraSet | None = None,
4341
hand_cfg: THConfig | None = None,
4442
max_relative_movement: float | tuple[float, float] | None = None,
@@ -47,7 +45,6 @@ def __call__( # type: ignore
4745
if isinstance(calibration_dir, str):
4846
calibration_dir = Path(calibration_dir)
4947
robot = XArm7(ip=ip)
50-
# env: gym.Env = RobotEnv(robot, ControlMode.JOINTS, home_on_reset=True)
5148
env: gym.Env = RobotEnv(robot, control_mode, home_on_reset=True)
5249

5350
if camera_set is not None:
@@ -59,20 +56,6 @@ def __call__( # type: ignore
5956
hand = TilburgHand(cfg=hand_cfg, verbose=True)
6057
env = HandWrapper(env, hand, True)
6158

62-
# if collision_guard:
63-
# env = CollisionGuard.env_from_xml_paths(
64-
# env=env,
65-
# cg_kinematics_path=cg_kinematics_path,
66-
# hand=True,
67-
# gripper=False,
68-
# check_home_collision=False,
69-
# control_mode=control_mode,
70-
# tcp_offset=rcs.common.Pose(),
71-
# sim_gui=True,
72-
# truncate_on_collision=True,
73-
# id="",
74-
# )
75-
7659
if max_relative_movement is not None:
7760
env = RelativeActionSpace(env, max_mov=max_relative_movement, relative_to=relative_to)
7861

extensions/rcs_xarm7/src/rcs_xarm7/env_cartesian_control.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from rcs._core.common import RobotPlatform
55
from rcs.envs.base import ControlMode, RelativeTo
66
from rcs.envs.creators import SimEnvCreator
7-
from rcs.envs.utils import default_sim_tilburg_hand_cfg, get_tcp_offset
7+
from rcs.envs.utils import default_sim_tilburg_hand_cfg
88
from rcs.hand.tilburg_hand import THConfig
99
from rcs_xarm7.creators import RCSXArm7EnvCreator
1010

@@ -43,7 +43,6 @@ def sim_env():
4343
robot_cfg.robot_type = rcs.common.RobotType.XArm7
4444
robot_cfg.attachment_site = "attachment_site"
4545
robot_cfg.arm_collision_geoms = []
46-
robot_cfg.tcp_offset = get_tcp_offset(rcs.scenes["xarm7_empty_world"].mjcf_scene)
4746
robot_cfg.mjcf_scene_path = rcs.scenes["xarm7_empty_world"].mjb
4847
robot_cfg.kinematic_model_path = rcs.scenes["xarm7_empty_world"].mjcf_robot
4948
env_rel = SimEnvCreator()(
@@ -72,8 +71,6 @@ def main():
7271
hand_cfg=hand_cfg,
7372
relative_to=RelativeTo.LAST_STEP,
7473
max_relative_movement=np.deg2rad(3),
75-
# collision_guard=rcs.scenes["xarm7_empty_world"]["mjcf_scene"],
76-
# cg_kinematics_path=rcs.scenes["xarm7_empty_world"]["mjcf_robot"],
7774
)
7875
else:
7976
env_rel = sim_env()

extensions/rcs_xarm7/src/rcs_xarm7/env_grasp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from rcs._core.common import RobotPlatform
66
from rcs.envs.base import ControlMode, RelativeTo
77
from rcs.envs.creators import SimEnvCreator
8-
from rcs.envs.utils import default_sim_tilburg_hand_cfg, get_tcp_offset
8+
from rcs.envs.utils import default_sim_tilburg_hand_cfg
99
from rcs.hand.tilburg_hand import THConfig
1010
from rcs_xarm7.creators import RCSXArm7EnvCreator
1111

@@ -44,7 +44,6 @@ def sim_env():
4444
robot_cfg.robot_type = rcs.common.RobotType.XArm7
4545
robot_cfg.attachment_site = "attachment_site"
4646
robot_cfg.arm_collision_geoms = []
47-
robot_cfg.tcp_offset = get_tcp_offset(rcs.scenes["xarm7_empty_world"].mjcf_scene)
4847
env_rel = SimEnvCreator()(
4948
robot_cfg=robot_cfg,
5049
control_mode=ControlMode.JOINTS,

extensions/rcs_xarm7/src/rcs_xarm7/env_joint_control.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from rcs._core.common import RobotPlatform
66
from rcs.envs.base import ControlMode, RelativeTo
77
from rcs.envs.creators import SimEnvCreator
8-
from rcs.envs.utils import get_tcp_offset
98
from rcs_xarm7.creators import RCSXArm7EnvCreator
109

1110
import rcs
@@ -52,7 +51,6 @@ def main():
5251
robot_cfg.robot_type = rcs.common.RobotType.XArm7
5352
robot_cfg.attachment_site = "attachment_site"
5453
robot_cfg.arm_collision_geoms = []
55-
robot_cfg.tcp_offset = get_tcp_offset(rcs.scenes["xarm7_empty_world"].mjcf_scene)
5654
robot_cfg.mjcf_scene_path = rcs.scenes["xarm7_empty_world"].mjb
5755
robot_cfg.kinematic_model_path = rcs.scenes["xarm7_empty_world"].mjcf_robot
5856
env_rel = SimEnvCreator()(

python/rcs/envs/utils.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import logging
22
from os import PathLike
3-
from pathlib import Path
43

5-
import mujoco as mj
6-
import numpy as np
74
from digit_interface import Digit
85
from rcs._core.common import BaseCameraConfig
96
from rcs._core.sim import CameraType, SimCameraConfig
@@ -19,7 +16,6 @@
1916

2017
def default_sim_robot_cfg(scene: str = "fr3_empty_world", idx: str = "0") -> sim.SimRobotConfig:
2118
robot_cfg = rcs.sim.SimRobotConfig()
22-
robot_cfg.tcp_offset = get_tcp_offset(rcs.scenes[scene].mjcf_scene)
2319
robot_cfg.realtime = False
2420
robot_cfg.robot_type = rcs.scenes[scene].robot_type
2521
robot_cfg.add_id(idx)
@@ -73,34 +69,3 @@ def default_mujoco_cameraset_cfg() -> dict[str, SimCameraConfig]:
7369
),
7470
# "bird_eye": SimCameraConfig(identifier="bird_eye_cam", type=int(CameraType.fixed), frame_rate=10, resolution_width=256, resolution_height=256),
7571
}
76-
77-
78-
def get_tcp_offset(mjcf: str | Path) -> rcs.common.Pose:
79-
"""Reads out tcp offset set in mjcf file.
80-
81-
Convention: The tcp offset is stored in the model as a numeric attribute named "tcp_offset".
82-
83-
Args:
84-
mjcf (str | PathLike): Path to the mjcf file.
85-
86-
Returns:
87-
rcs.common.Pose: The tcp offset.
88-
"""
89-
mjcf = Path(mjcf)
90-
if mjcf.suffix in (".xml", ".mjcf"):
91-
model = mj.MjModel.from_xml_path(str(mjcf))
92-
elif mjcf.suffix == ".mjb":
93-
model = mj.MjModel.from_binary_path(str(mjcf))
94-
else:
95-
msg = f"Expected .mjb, .mjcf or.xml, got {mjcf.suffix} and {mjcf}"
96-
raise AssertionError(msg)
97-
try:
98-
tcp_offset_translation = np.array(model.numeric("tcp_offset_translation").data)
99-
tcp_offset_rotation_matrix = np.array(model.numeric("tcp_offset_rotation_matrix").data)
100-
return rcs.common.Pose(
101-
translation=tcp_offset_translation, rotation=tcp_offset_rotation_matrix.reshape((3, 3)) # type: ignore
102-
)
103-
except KeyError:
104-
msg = "No tcp offset found in the model. Using an identity transform as tcp offset."
105-
logging.warning(msg)
106-
return rcs.common.Pose()

0 commit comments

Comments
 (0)