Skip to content

Commit 8a33af1

Browse files
authored
infra: add PrimitiveFrameCfg; isaaclab: support it (#135)
* infra: add PrimitiveFrameCfg; isaaclab: support it * add frame asset to metasim/data; update path * quickfix
1 parent 6ff093b commit 8a33af1

4 files changed

Lines changed: 50 additions & 1 deletion

File tree

metasim/cfg/objects.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ def density(self) -> float:
131131
return self.mass / (4 / 3 * math.pi * self.radius**3)
132132

133133

134+
@configclass
135+
class PrimitiveFrameCfg(RigidObjCfg):
136+
"""Primitive coordinate frame cfg."""
137+
138+
# TODO: This is object shouldn't inherit from RigidObjCfg?
139+
name: str = MISSING
140+
scale: float = 1.0
141+
"""Scale of the frame"""
142+
base_link: str | tuple[str, str] | None = None
143+
"""Base link to attach the frame.
144+
If ``None``, the frame will be attached to the world origin.
145+
If a ``str``, the frame will be attached to the root link of the object specified by the name.
146+
If a ``tuple[str, str]``, the frame will be attached to the object specified by the first str and the body link specified by the second str.
147+
"""
148+
149+
134150
@configclass
135151
class PrimitiveCylinderCfg(RigidObjCfg):
136152
"""Primitive cylinder object cfg."""
6.24 KB
Binary file not shown.

metasim/sim/isaaclab/isaaclab.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import torch
88
from loguru import logger as log
99

10-
from metasim.cfg.objects import ArticulationObjCfg, BaseObjCfg, RigidObjCfg
10+
from metasim.cfg.objects import ArticulationObjCfg, BaseObjCfg, PrimitiveFrameCfg, RigidObjCfg
1111
from metasim.cfg.scenario import ScenarioCfg
1212
from metasim.sim import BaseSimHandler, EnvWrapper, IdentityEnvWrapper
1313
from metasim.types import Action, EnvState, Extra, Obs, Reward, Success, TimeOut
@@ -128,6 +128,23 @@ def step(self, action: list[Action]) -> tuple[Obs, Reward, Success, TimeOut, Ext
128128
time_out = time_out.cpu()
129129
success = self.checker.check(self)
130130
states = self.get_states()
131+
132+
## TODO: organize this
133+
for obj in self.objects:
134+
if isinstance(obj, PrimitiveFrameCfg):
135+
if obj.base_link is None:
136+
pos = torch.zeros((self.num_envs, 3), device=self.device)
137+
rot = torch.zeros((self.num_envs, 4), device=self.device)
138+
rot[:, 0] = 1.0
139+
elif isinstance(obj.base_link, str):
140+
pos, rot = (states.objects | states.robots)[obj.base_link].root_state[:, :7].split([3, 4], dim=-1)
141+
else:
142+
base_obj_name = obj.base_link[0]
143+
base_body_name = obj.base_link[1]
144+
merged_states = states.objects | states.robots
145+
body_idx = merged_states[base_obj_name].body_names.index(base_body_name)
146+
pos, rot = merged_states[base_obj_name].body_state[:, body_idx, :7].split([3, 4], dim=-1)
147+
self._set_object_pose(obj, pos, rot)
131148
return states, None, success, time_out, extras
132149

133150
def reset(self, env_ids: list[int] | None = None) -> tuple[list[EnvState], Extra]:

metasim/sim/isaaclab/isaaclab_helper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
BaseObjCfg,
1010
PrimitiveCubeCfg,
1111
PrimitiveCylinderCfg,
12+
PrimitiveFrameCfg,
1213
PrimitiveSphereCfg,
1314
RigidObjCfg,
1415
)
@@ -91,6 +92,21 @@ def add_object(env: "EmptyEnv", obj: BaseObjCfg) -> None:
9192
)
9293
)
9394
return
95+
if isinstance(obj, PrimitiveFrameCfg):
96+
env.scene.rigid_objects[obj.name] = RigidObject(
97+
RigidObjectCfg(
98+
prim_path=prim_path,
99+
spawn=sim_utils.UsdFileCfg(
100+
usd_path="metasim/data/quick_start/assets/COMMON/frame/usd/frame.usd",
101+
rigid_props=sim_utils.RigidBodyPropertiesCfg(
102+
disable_gravity=True, kinematic_enabled=True
103+
), # fixed
104+
collision_props=None, # no collision
105+
scale=obj.scale,
106+
),
107+
)
108+
)
109+
return
94110

95111
## File-based object
96112
usd_file_cfg = sim_utils.UsdFileCfg(

0 commit comments

Comments
 (0)