Skip to content

Commit 855d837

Browse files
committed
feat: add lerobot rcs eval config
1 parent 22771b5 commit 855d837

File tree

2 files changed

+46
-19
lines changed

2 files changed

+46
-19
lines changed

python/rcs/__init__.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
import os
44
import site
5-
from dataclasses import dataclass
5+
from dataclasses import dataclass, field
66

77
from gymnasium import register
8+
from lerobot.configs.types import PolicyFeature
9+
from lerobot.envs.configs import EnvConfig
810
from rcs._core import __version__, common
911
from rcs.envs.creators import (
1012
FR3LabDigitGripperPickUpSimEnvCreator,
1113
FR3SimplePickUpSimEnvCreator,
1214
)
15+
from rcs.lerobot import Pick
1316

1417
from rcs import camera, envs, hand, sim
15-
from rcs.lerobot import Pick
1618

1719

1820
@dataclass(kw_only=True)
@@ -105,11 +107,36 @@ def get_scene_urdf(scene_name: str) -> str | None:
105107
entry_point=Pick(),
106108
)
107109

108-
# Genius TODO: Add the tacto version of the SimEnvCreator
109110
# TODO: gym.make("rcs/FR3SimEnv-v0") results in a pickling error:
110111
# TypeError: cannot pickle 'rcs._core.sim.SimRobotConfig' object
111112
# cf. https://pybind11.readthedocs.io/en/stable/advanced/classes.html#deepcopy-support
112113
# register(
113114
# id="rcs/FR3SimEnv-v0",
114115
# entry_point=SimEnvCreator(),
115116
# )
117+
118+
119+
# lerobot env registration
120+
@EnvConfig.register_subclass("rcs/pick")
121+
@dataclass
122+
class RCSEnvConfig(EnvConfig):
123+
task: str | None = "pick"
124+
fps: int = 30
125+
features: dict[str, PolicyFeature] = field(default_factory=dict)
126+
features_map: dict[str, str] = field(default_factory=dict)
127+
max_parallel_tasks: int = 1
128+
disable_env_checker: bool = True
129+
130+
@property
131+
def package_name(self) -> str:
132+
"""Package name to import if environment not found in gym registry"""
133+
return "rcs"
134+
135+
@property
136+
def gym_id(self) -> str:
137+
"""ID string used in gym.make() to instantiate the environment"""
138+
return f"{self.package_name}/{self.task}"
139+
140+
@property
141+
def gym_kwargs(self) -> dict:
142+
return {}

python/rcs/lerobot.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
from typing import Any
2+
23
import gymnasium as gym
3-
import rcs
44
import numpy as np
5-
6-
from rcs._core.sim import SimConfig
5+
from gymnasium.envs.registration import EnvCreator
6+
from rcs._core.sim import CameraType, SimCameraConfig, SimConfig
77
from rcs.envs.base import ControlMode, RelativeActionSpace
8+
from rcs.envs.creators import SimTaskEnvCreator
89
from rcs.envs.space_utils import ActObsInfoWrapper
910
from rcs.sim import SimGripperConfig
1011
from rcs_tacto.tacto_wrapper import TactoSimWrapper
11-
from gymnasium.envs.registration import EnvCreator
1212

13-
14-
from rcs._core.sim import CameraType, SimCameraConfig
15-
from rcs.envs.creators import SimTaskEnvCreator
13+
import rcs
1614

1715
SCENE_FILE = "beast_refiner/rcs_env/rcs_icra_scene_digit/scene.xml"
1816
CAMERAS = [
@@ -23,17 +21,20 @@
2321
"side_wide",
2422
]
2523

24+
2625
class AlignSpaceWrapper(ActObsInfoWrapper):
2726

2827
def __init__(self, env):
2928
super().__init__(env)
30-
self.observation_space = gym.spaces.Dict({
31-
"state": gym.spaces.Box(low=-np.inf, high=np.inf, shape=(15,), dtype=np.float32),
32-
"images.image": env.observation_space["frames"]["side"]["rgb"]["data"],
33-
"images.image2": env.observation_space["frames"]["wrist"]["rgb"]["data"],
34-
"images.tactile_left": gym.spaces.Box(low=0, high=255, shape=(320, 240, 3), dtype=np.uint8),
35-
"images.tactile_right": gym.spaces.Box(low=0, high=255, shape=(320, 240, 3), dtype=np.uint8),
36-
})
29+
self.observation_space = gym.spaces.Dict(
30+
{
31+
"state": gym.spaces.Box(low=-np.inf, high=np.inf, shape=(15,), dtype=np.float32),
32+
"images.image": env.observation_space["frames"]["side"]["rgb"]["data"],
33+
"images.image2": env.observation_space["frames"]["wrist"]["rgb"]["data"],
34+
"images.tactile_left": gym.spaces.Box(low=0, high=255, shape=(320, 240, 3), dtype=np.uint8),
35+
"images.tactile_right": gym.spaces.Box(low=0, high=255, shape=(320, 240, 3), dtype=np.uint8),
36+
}
37+
)
3738
# self.action_space = env.action_space["joints"]
3839
gym.spaces.Box(low=-np.inf, high=np.inf, shape=(8,), dtype=np.float32)
3940

@@ -48,7 +49,6 @@ def observation(self, observation: dict[str, Any], info: dict[str, Any]) -> tupl
4849
# tactile and tau_ext are still unsolved
4950

5051
return observation, info
51-
5252

5353
def action(self, action: np.ndarray) -> dict[str, Any]:
5454
action = {"joints": action[:7], "gripper": action[7]}
@@ -151,4 +151,4 @@ def make_env(n_envs: int = 1, use_async_envs: bool = False):
151151

152152
class Pick(EnvCreator):
153153
def __call__(self) -> gym.Env:
154-
return make_single_env()
154+
return make_single_env()

0 commit comments

Comments
 (0)