Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cmake/compile_scenes.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ foreach(scene_dir ${scene_dirs})
foreach(urdf ${urdfs})
install(FILES ${urdf} DESTINATION rcsss/scenes/${scene_name} COMPONENT python_package)
endforeach()

# Install xml files
foreach(xml ${xml_files})
install(FILES ${xml} DESTINATION rcsss/scenes/${scene_name} COMPONENT python_package)
endforeach()

# Install assets
foreach(asset ${asset_files})
install(FILES ${asset} DESTINATION rcsss/scenes/${scene_name}/assets COMPONENT python_package)
endforeach()
endforeach()

# Create a custom target that depends on all generated .mjb files
Expand Down
2 changes: 1 addition & 1 deletion python/examples/fr3.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def main():
robot: rcsss.common.Robot
gripper: rcsss.common.Gripper
if ROBOT_INSTANCE == RobotInstance.SIMULATION:
simulation = sim.Sim(rcsss.scenes["fr3_empty_world"])
simulation = sim.Sim(rcsss.scenes["fr3_empty_world"]["mjb"])
urdf_path = get_urdf_path(URDF_PATH, allow_none_if_not_found=False)
assert urdf_path is not None
ik = rcsss.common.IK(urdf_path)
Expand Down
28 changes: 25 additions & 3 deletions python/rcsss/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,39 @@

import pathlib
import site
from typing import TypedDict
from warnings import warn

from gymnasium import register
from rcsss import camera, control, envs, sim
from rcsss._core import __version__, common, hw
from rcsss.envs.factories import FR3Real, FR3SimplePickUpSim

# available mujoco scenes
scenes = {
path.stem: path / "scene.mjb" for path in (pathlib.Path(site.getsitepackages()[0]) / "rcsss" / "scenes").glob("*")

class SceneData(TypedDict):
xml: pathlib.Path
mjb: pathlib.Path
urdfs: dict[str, pathlib.Path]


scenes: dict[str, SceneData] = {
path.stem: {
"xml": path / "scene.xml",
"mjb": path / "scene.mjb",
"urdfs": {urdf.stem: urdf for urdf in path.glob("*.urdf")},
}
for path in (pathlib.Path(site.getsitepackages()[0]) / "rcsss" / "scenes").glob("*")
}

for _ in scenes.values():
if not _["xml"].exists():
warn(f"Missing XML scene file {_['xml']}", stacklevel=2)
if not _["mjb"].exists():
warn(f"Missing mjb scene file {_['mjb']}", stacklevel=2)
for __ in _["urdfs"].values():
if not __.exists():
warn(f"Missing urdf file {__}", stacklevel=2)

# make submodules available
__all__ = ["__doc__", "__version__", "common", "hw", "sim", "camera", "scenes", "control", "envs"]

Expand Down
16 changes: 11 additions & 5 deletions python/rcsss/envs/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def default_realsense(name2id: dict[str, str] | None) -> RealSenseCameraSet | No

def get_urdf_path(urdf_path: str | PathLike | None, allow_none_if_not_found: bool = False) -> str | None:
if urdf_path is None and "lab" in rcsss.scenes:
urdf_path = rcsss.scenes["lab"].parent / "fr3.urdf"
urdf_path = rcsss.scenes["lab"]["urdfs"]["fr3"]
assert urdf_path.exists(), "Automatic deduced urdf path does not exist. Corrupted models directory."
logger.info("Using automatic found urdf.")
elif urdf_path is None and not allow_none_if_not_found:
Expand Down Expand Up @@ -134,7 +134,11 @@ def fr3_hw_env(
assert urdf_path is not None
env = CollisionGuard.env_from_xml_paths(
env,
str(rcsss.scenes.get(str(collision_guard), collision_guard)),
str(
rcsss.scenes[collision_guard]["mjb"]
if isinstance(collision_guard, str) and collision_guard in rcsss.scenes
else collision_guard
),
urdf_path,
gripper=True,
check_home_collision=False,
Expand Down Expand Up @@ -209,10 +213,12 @@ def fr3_sim_env(
"""
urdf_path = get_urdf_path(urdf_path, allow_none_if_not_found=False)
assert urdf_path is not None
if mjcf not in rcsss.scenes:
if isinstance(mjcf, str) and mjcf in rcsss.scenes:
mjcf = rcsss.scenes[mjcf]["mjb"]
else:
logger.warning("mjcf not found as key in scenes, interpreting mjcf as path the mujoco scene xml")

simulation = sim.Sim(rcsss.scenes.get(str(mjcf), mjcf))
simulation = sim.Sim(mjcf)
ik = rcsss.common.IK(urdf_path)
robot = rcsss.sim.FR3(simulation, "0", ik)
robot.set_parameters(robot_cfg)
Expand All @@ -230,7 +236,7 @@ def fr3_sim_env(
if collision_guard:
env = CollisionGuard.env_from_xml_paths(
env,
str(rcsss.scenes.get(str(mjcf), mjcf)),
str(rcsss.scenes[mjcf]["mjb"] if isinstance(mjcf, str) and mjcf in rcsss.scenes else mjcf),
urdf_path,
gripper=gripper_cfg is not None,
check_home_collision=False,
Expand Down
Loading