Skip to content

Commit

Permalink
Merge pull request #336 from StanfordVL/articulationview
Browse files Browse the repository at this point in the history
Replace dynamic control APIs with Isaac.Core View APIs
  • Loading branch information
cgokmen authored Dec 21, 2023
2 parents a18e858 + 8d58b6c commit 08aee08
Show file tree
Hide file tree
Showing 20 changed files with 778 additions and 727 deletions.
2 changes: 1 addition & 1 deletion omnigibson/object_states/particle_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def overlap_callback(hit):
z_offset = 0.0 if self._projection_mesh_params["type"] == "Sphere" else self._projection_mesh_params["extents"][2] / 2

self.projection_mesh.set_local_pose(
translation=np.array([0, 0, -z_offset]),
position=np.array([0, 0, -z_offset]),
orientation=T.euler2quat([0, 0, 0]),
)

Expand Down
2 changes: 1 addition & 1 deletion omnigibson/object_states/toggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _initialize(self):
self.visual_marker.visible = True

# Make sure the marker isn't translated at all
self.visual_marker.set_local_pose(translation=np.zeros(3), orientation=np.array([0, 0, 0, 1.0]))
self.visual_marker.set_local_pose(position=np.zeros(3), orientation=np.array([0, 0, 0, 1.0]))

# Store the projection mesh's IDs
projection_mesh_ids = PhysicsSchemaTools.encodeSdfPath(self.visual_marker.prim_path)
Expand Down
2 changes: 1 addition & 1 deletion omnigibson/objects/controllable_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def reload_controllers(self, controller_config=None):
else self._create_continuous_action_space()

def reset(self):
# Make sure simulation is playing, otherwise, we cannot reset because DC requires active running
# Make sure simulation is playing, otherwise, we cannot reset because physx requires active running
# simulation in order to set joints
assert og.sim.is_playing(), "Simulator must be playing in order to reset controllable object's joints!"

Expand Down
5 changes: 5 additions & 0 deletions omnigibson/objects/dataset_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(
visible=True,
fixed_base=False,
visual_only=False,
kinematic_only=None,
self_collisions=False,
prim_type=PrimType.RIGID,
load_config=None,
Expand Down Expand Up @@ -83,6 +84,9 @@ def __init__(
visible (bool): whether to render this object or not in the stage
fixed_base (bool): whether to fix the base of this object or not
visual_only (bool): Whether this object should be visual only (and not collide with any other objects)
kinematic_only (None or bool): Whether this object should be kinematic only (and not get affected by any
collisions). If None, then this value will be set to True if @fixed_base is True and some other criteria
are satisfied (see object_base.py post_load function), else False.
self_collisions (bool): Whether to enable self collisions for this object
prim_type (PrimType): Which type of prim the object is, Valid options are: {PrimType.RIGID, PrimType.CLOTH}
load_config (None or dict): If specified, should contain keyword-mapped values that are relevant for
Expand Down Expand Up @@ -136,6 +140,7 @@ def __init__(
visible=visible,
fixed_base=fixed_base,
visual_only=visual_only,
kinematic_only=kinematic_only,
self_collisions=self_collisions,
prim_type=prim_type,
include_default_states=include_default_states,
Expand Down
50 changes: 33 additions & 17 deletions omnigibson/objects/object_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(
visible=True,
fixed_base=False,
visual_only=False,
kinematic_only=None,
self_collisions=False,
prim_type=PrimType.RIGID,
load_config=None,
Expand All @@ -68,6 +69,9 @@ def __init__(
visible (bool): whether to render this object or not in the stage
fixed_base (bool): whether to fix the base of this object or not
visual_only (bool): Whether this object should be visual only (and not collide with any other objects)
kinematic_only (None or bool): Whether this object should be kinematic only (and not get affected by any
collisions). If None, then this value will be set to True if @fixed_base is True and some other criteria
are satisfied (see object_base.py post_load function), else False.
self_collisions (bool): Whether to enable self collisions for this object
prim_type (PrimType): Which type of prim the object is, Valid options are: {PrimType.RIGID, PrimType.CLOTH}
load_config (None or dict): If specified, should contain keyword-mapped values that are relevant for
Expand Down Expand Up @@ -104,6 +108,7 @@ def __init__(
load_config["scale"] = np.array(scale) if isinstance(scale, Iterable) else scale
load_config["visible"] = visible
load_config["visual_only"] = visual_only
load_config["kinematic_only"] = kinematic_only
load_config["self_collisions"] = self_collisions
load_config["prim_type"] = prim_type

Expand Down Expand Up @@ -136,9 +141,37 @@ def remove(self):
log.info(f"Removed {self.name} from {self.prim_path}")

def _post_load(self):
# Add fixed joint or make object kinematic only if we're fixing the base
kinematic_only = False
if self.fixed_base:
# For optimization purposes, if we only have a single rigid body that has either
# (no custom scaling OR no fixed joints), we assume this is not an articulated object so we
# merely set this to be a static collider, i.e.: kinematic-only
# The custom scaling / fixed joints requirement is needed because omniverse complains about scaling that
# occurs with respect to fixed joints, as omni will "snap" bodies together otherwise
scale = np.ones(3) if self._load_config["scale"] is None else np.array(self._load_config["scale"])
if self.n_joints == 0 and (np.all(np.isclose(scale, 1.0, atol=1e-3)) or self.n_fixed_joints == 0) and (self._load_config["kinematic_only"] != False):
kinematic_only = True

# Validate that we didn't make a kinematic-only decision that does not match
assert self._load_config["kinematic_only"] is None or kinematic_only == self._load_config["kinematic_only"], \
f"Kinematic only decision does not match! Got: {kinematic_only}, expected: {self._load_config['kinematic_only']}"

# Actually apply the kinematic-only decision
self._load_config["kinematic_only"] = kinematic_only

# Run super first
super()._post_load()

# If the object is fixed_base but kinematic only is false, create the joint
if self.fixed_base and not self.kinematic_only:
# Create fixed joint, and set Body0 to be this object's root prim
create_joint(
prim_path=f"{self._prim_path}/rootJoint",
joint_type="FixedJoint",
body1=f"{self._prim_path}/{self._root_link_name}",
)

# Set visibility
if "visible" in self._load_config and self._load_config["visible"] is not None:
self.visible = self._load_config["visible"]
Expand All @@ -148,23 +181,6 @@ def _post_load(self):
self._prim.RemoveAPI(UsdPhysics.ArticulationRootAPI)
self._prim.RemoveAPI(PhysxSchema.PhysxArticulationAPI)

# Add fixed joint if we're fixing the base
if self.fixed_base:
# For optimization purposes, if we only have a single rigid body that has either
# (no custom scaling OR no fixed joints), we assume this is not an articulated object so we
# merely set this to be a static collider, i.e.: kinematic-only
# The custom scaling / fixed joints requirement is needed because omniverse complains about scaling that
# occurs with respect to fixed joints, as omni will "snap" bodies together otherwise
if self.n_joints == 0 and (np.all(np.isclose(self.scale, 1.0, atol=1e-3)) or self.n_fixed_joints == 0):
self.kinematic_only = True
else:
# Create fixed joint, and set Body0 to be this object's root prim
create_joint(
prim_path=f"{self._prim_path}/rootJoint",
joint_type="FixedJoint",
body1=f"{self._prim_path}/{self._root_link_name}",
)

# Potentially add articulation root APIs and also set self collisions
root_prim = None if self.articulation_root_path is None else get_prim_at_path(self.articulation_root_path)
if root_prim is not None:
Expand Down
5 changes: 5 additions & 0 deletions omnigibson/objects/primitive_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(
visible=True,
fixed_base=False,
visual_only=False,
kinematic_only=None,
self_collisions=False,
prim_type=PrimType.RIGID,
load_config=None,
Expand Down Expand Up @@ -66,6 +67,9 @@ def __init__(
visible (bool): whether to render this object or not in the stage
fixed_base (bool): whether to fix the base of this object or not
visual_only (bool): Whether this object should be visual only (and not collide with any other objects)
kinematic_only (None or bool): Whether this object should be kinematic only (and not get affected by any
collisions). If None, then this value will be set to True if @fixed_base is True and some other criteria
are satisfied (see object_base.py post_load function), else False.
self_collisions (bool): Whether to enable self collisions for this object
prim_type (PrimType): Which type of prim the object is, Valid options are: {PrimType.RIGID, PrimType.CLOTH}
load_config (None or dict): If specified, should contain keyword-mapped values that are relevant for
Expand Down Expand Up @@ -110,6 +114,7 @@ def __init__(
visible=visible,
fixed_base=fixed_base,
visual_only=visual_only,
kinematic_only=kinematic_only,
self_collisions=self_collisions,
prim_type=prim_type,
include_default_states=include_default_states,
Expand Down
5 changes: 5 additions & 0 deletions omnigibson/objects/stateful_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(
visible=True,
fixed_base=False,
visual_only=False,
kinematic_only=None,
self_collisions=False,
prim_type=PrimType.RIGID,
load_config=None,
Expand All @@ -89,6 +90,9 @@ def __init__(
visible (bool): whether to render this object or not in the stage
fixed_base (bool): whether to fix the base of this object or not
visual_only (bool): Whether this object should be visual only (and not collide with any other objects)
kinematic_only (None or bool): Whether this object should be kinematic only (and not get affected by any
collisions). If None, then this value will be set to True if @fixed_base is True and some other criteria
are satisfied (see object_base.py post_load function), else False.
self_collisions (bool): Whether to enable self collisions for this object
prim_type (PrimType): Which type of prim the object is, Valid options are: {PrimType.RIGID, PrimType.CLOTH}
load_config (None or dict): If specified, should contain keyword-mapped values that are relevant for
Expand Down Expand Up @@ -129,6 +133,7 @@ def __init__(
visible=visible,
fixed_base=fixed_base,
visual_only=visual_only,
kinematic_only=kinematic_only,
self_collisions=self_collisions,
prim_type=prim_type,
load_config=load_config,
Expand Down
5 changes: 5 additions & 0 deletions omnigibson/objects/usd_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(
visible=True,
fixed_base=False,
visual_only=False,
kinematic_only=None,
self_collisions=False,
prim_type=PrimType.RIGID,
load_config=None,
Expand All @@ -52,6 +53,9 @@ def __init__(
visible (bool): whether to render this object or not in the stage
fixed_base (bool): whether to fix the base of this object or not
visual_only (bool): Whether this object should be visual only (and not collide with any other objects)
kinematic_only (None or bool): Whether this object should be kinematic only (and not get affected by any
collisions). If None, then this value will be set to True if @fixed_base is True and some other criteria
are satisfied (see object_base.py post_load function), else False.
self_collisions (bool): Whether to enable self collisions for this object
prim_type (PrimType): Which type of prim the object is, Valid options are: {PrimType.RIGID, PrimType.CLOTH}
load_config (None or dict): If specified, should contain keyword-mapped values that are relevant for
Expand All @@ -77,6 +81,7 @@ def __init__(
visible=visible,
fixed_base=fixed_base,
visual_only=visual_only,
kinematic_only=kinematic_only,
self_collisions=self_collisions,
prim_type=prim_type,
include_default_states=include_default_states,
Expand Down
Loading

0 comments on commit 08aee08

Please sign in to comment.