Skip to content

Commit 41b43a7

Browse files
committed
chore: unifed mjcf robot name
1 parent f285afd commit 41b43a7

10 files changed

Lines changed: 33 additions & 24 deletions

File tree

‎assets/scenes/fr3_empty_world/scene.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<mujoco model="fr3 scene">
22
<include file="fr3_common.xml"/>
3-
<include file="fr3_0.xml"/>
3+
<include file="robot.xml"/>
44

55
<statistic center="0.3 0 0.4" extent="1"/>
66

File renamed without changes.

‎assets/scenes/fr3_simple_pick_up/scene.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<mujoco model="simple pick up task">
22
<include file="fr3_common.xml" />
3-
<include file="fr3_0.xml" />
3+
<include file="robot.xml" />
44

55
<statistic center="0.3 0 0.4" extent="1" />
66

‎cmake/compile_scenes.cmake‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ foreach(scene_dir ${scene_dirs})
3030
# Install scene files
3131
install(FILES ${scene_mjb} DESTINATION rcs/scenes/${scene_name} COMPONENT python_package)
3232

33-
# Install URDF files
34-
file(GLOB urdfs ${scene_dir}/*.urdf)
35-
foreach(urdf ${urdfs})
36-
install(FILES ${urdf} DESTINATION rcs/scenes/${scene_name} COMPONENT python_package)
37-
endforeach()
3833
endforeach()
3934

4035
# Create a custom target that depends on all generated .mjb files

‎examples/fr3_env_cartesian_control.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from rcs_fr3.desk import FCI, ContextManager, Desk, load_creds_fr3_desk
1313
from rcs_fr3.utils import default_fr3_hw_gripper_cfg, default_fr3_hw_robot_cfg
1414

15+
import rcs
16+
1517
logger = logging.getLogger(__name__)
1618
logger.setLevel(logging.INFO)
1719

@@ -64,19 +66,22 @@ def main():
6466
else:
6567
env_rel = SimEnvCreator()(
6668
control_mode=ControlMode.CARTESIAN_TQuat,
67-
robot_cfg=default_sim_robot_cfg(),
69+
robot_cfg=default_sim_robot_cfg(mjcf=rcs.scenes["fr3_empty_world"]["mjcf_scene"]),
6870
collision_guard=False,
6971
gripper_cfg=default_sim_gripper_cfg(),
7072
cameras=default_mujoco_cameraset_cfg(),
7173
max_relative_movement=0.5,
7274
relative_to=RelativeTo.LAST_STEP,
75+
mjcf=rcs.scenes["fr3_empty_world"]["mjb"],
76+
robot_kinematics_path=rcs.scenes["fr3_empty_world"]["mjcf_robot"],
77+
kinematics_frame_id="attachment_site_0",
7378
)
7479
env_rel.get_wrapper_attr("sim").open_gui()
7580

7681
env_rel.reset()
7782
print(env_rel.unwrapped.robot.get_cartesian_position()) # type: ignore
7883

79-
for _ in range(10):
84+
for _ in range(100):
8085
for _ in range(10):
8186
# move 1cm in x direction (forward) and close gripper
8287
act = {"tquat": [0.01, 0, 0, 0, 0, 0, 1], "gripper": 0}

‎examples/fr3_env_joint_control.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from rcs_fr3.desk import FCI, ContextManager, Desk, load_creds_fr3_desk
1414
from rcs_fr3.utils import default_fr3_hw_gripper_cfg, default_fr3_hw_robot_cfg
1515

16+
import rcs
17+
1618
logger = logging.getLogger(__name__)
1719
logger.setLevel(logging.INFO)
1820

@@ -66,15 +68,17 @@ def main():
6668
env_rel = SimEnvCreator()(
6769
control_mode=ControlMode.JOINTS,
6870
collision_guard=False,
69-
robot_cfg=default_sim_robot_cfg(),
71+
robot_cfg=default_sim_robot_cfg(mjcf=rcs.scenes["fr3_empty_world"]["mjcf_scene"]),
7072
gripper_cfg=default_sim_gripper_cfg(),
7173
cameras=default_mujoco_cameraset_cfg(),
7274
max_relative_movement=np.deg2rad(5),
7375
relative_to=RelativeTo.LAST_STEP,
76+
mjcf=rcs.scenes["fr3_empty_world"]["mjb"],
77+
robot_kinematics_path=rcs.scenes["fr3_empty_world"]["mjcf_robot"],
7478
)
7579
env_rel.get_wrapper_attr("sim").open_gui()
7680

77-
for _ in range(10):
81+
for _ in range(100):
7882
obs, info = env_rel.reset()
7983
for _ in range(10):
8084
# sample random relative action and execute it

‎python/rcs/__init__.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
scenes: dict[str, dict[str, pathlib.Path]] = {
1414
path.stem: {
1515
"mjb": path / "scene.mjb",
16-
"urdf": path / "fr3.urdf",
16+
"urdf": f"assets/scenes/{path.stem}/robot.urdf",
17+
"mjcf_scene": f"assets/scenes/{path.stem}/scene.xml",
18+
"mjcf_robot": f"assets/scenes/{path.stem}/robot.xml",
1719
}
1820
for path in (pathlib.Path(site.getsitepackages()[0]) / "rcs" / "scenes").glob("*")
1921
}

‎python/rcs/envs/creators.py‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ def __call__( # type: ignore
4343
self,
4444
control_mode: ControlMode,
4545
robot_cfg: rcs.sim.SimRobotConfig,
46+
robot_kinematics_path: str | PathLike,
47+
mjcf: str | PathLike,
48+
kinematics_frame_id: str = "attachment_site",
4649
collision_guard: bool = False,
4750
gripper_cfg: rcs.sim.SimGripperConfig | None = None,
4851
cameras: dict[str, SimCameraConfig] | None = None,
4952
max_relative_movement: float | tuple[float, float] | None = None,
5053
relative_to: RelativeTo = RelativeTo.LAST_STEP,
51-
urdf_path: str | PathLike | None = None,
52-
mjcf: str | PathLike = "fr3_empty_world",
5354
sim_wrapper: Type[SimWrapper] | None = None,
5455
) -> gym.Env:
5556
"""
@@ -64,28 +65,28 @@ def __call__( # type: ignore
6465
max_relative_movement (float | tuple[float, float] | None): Maximum allowed movement. If float, it restricts
6566
translational movement in meters. If tuple, it restricts both translational (in meters) and rotational
6667
(in radians) movements. If None, no restriction is applied.
68+
kinematics_frame_id (str): Frame name of the flange. Defaults to "attachment_site". Note: if name doesnt exist
69+
then pinocchio just segfaults.
6770
relative_to (RelativeTo): Specifies whether the movement is relative to a configured origin or the last step.
68-
urdf_path (str | PathLike | None): Path to the URDF file. If None, the URDF file is automatically deduced
69-
which requires a UTN compatible lab scene to be present.
71+
robot_kinematics_path (str | PathLike | None): Path to either urdf or mjcf file that describes the robot kinematic.
72+
This is used for ik.
7073
mjcf (str | PathLike): Path to the Mujoco scene XML file. Defaults to "fr3_empty_world".
7174
sim_wrapper (Type[SimWrapper] | None): Wrapper to be applied before the simulation wrapper. This is useful
7275
for reset management e.g. resetting objects in the scene with correct observations. Defaults to None.
7376
7477
Returns:
7578
gym.Env: The configured simulation environment for the FR3 robot.
7679
"""
77-
if urdf_path is None:
78-
urdf_path = rcs.scenes["fr3_empty_world"]["urdf"]
7980
if mjcf not in rcs.scenes:
8081
logger.info("mjcf not found as key in scenes, interpreting mjcf as path the mujoco scene xml")
8182
if mjcf in rcs.scenes:
8283
assert isinstance(mjcf, str)
8384
mjcf = rcs.scenes[mjcf]["mjb"]
8485
simulation = sim.Sim(mjcf)
8586

86-
# ik = rcs.common.Pin("/home/juelg/code/internal_rcs/assets/scenes/fr3_empty_world/fr3_0.xml", "attachment_site_0", urdf=False)
87-
# ik = rcs.common.Pin(str(urdf_path))
88-
ik = rcs.common.RL(str(urdf_path))
87+
ik = rcs.common.Pin(
88+
str(robot_kinematics_path), kinematics_frame_id, urdf=robot_kinematics_path.endswith(".urdf")
89+
)
8990

9091
robot = rcs.sim.SimRobot(simulation, ik, robot_cfg)
9192
env: gym.Env = RobotEnv(robot, control_mode)
@@ -106,7 +107,7 @@ def __call__( # type: ignore
106107
env = CollisionGuard.env_from_xml_paths(
107108
env,
108109
str(rcs.scenes.get(str(mjcf), mjcf)),
109-
str(urdf_path),
110+
str(robot_kinematics_path),
110111
gripper=gripper_cfg is not None,
111112
check_home_collision=False,
112113
control_mode=control_mode,
@@ -132,14 +133,15 @@ def __call__( # type: ignore
132133

133134
env_rel = SimEnvCreator()(
134135
control_mode=control_mode,
135-
robot_cfg=default_sim_robot_cfg(mjcf),
136+
robot_cfg=default_sim_robot_cfg(rcs.scenes[mjcf]["mjcf_scene"]),
136137
collision_guard=False,
137138
gripper_cfg=default_sim_gripper_cfg(),
138139
cameras=cameras,
139140
max_relative_movement=(0.2, np.deg2rad(45)) if delta_actions else None,
140141
relative_to=RelativeTo.LAST_STEP,
141-
mjcf=mjcf,
142+
mjcf=rcs.scenes[mjcf]["mjcf_scene"],
142143
sim_wrapper=RandomCubePos,
144+
robot_kinematics_path=rcs.scenes[mjcf]["mjcf_robot"],
143145
)
144146
env_rel = PickCubeSuccessWrapper(env_rel)
145147
if render_mode == "human":

‎python/rcs/envs/sim.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def env_from_xml_paths(
202202
sim_gui: bool = True,
203203
truncate_on_collision: bool = True,
204204
) -> "CollisionGuard":
205+
# TODO: remove urdf and use mjcf
205206
# TODO: this needs to support non FR3 robots
206207
assert isinstance(env.unwrapped, RobotEnv)
207208
simulation = sim.Sim(mjmld)

0 commit comments

Comments
 (0)