Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add APIs for deformable asset #630

Merged
merged 53 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
044ef8e
Add deformable asset
masoudmoghani Jul 3, 2024
d341462
Add Franka Deformable Cube Lift Env
masoudmoghani Jul 3, 2024
18c778a
Add reset nodal state
masoudmoghani Jul 4, 2024
801f04b
Merge branch 'main' into feature/deformable_assets
masoudmoghani Jul 16, 2024
6fd32f8
Replace object with mesh cuboid
masoudmoghani Jul 16, 2024
fcd4c32
Add test_deformable_object
masoudmoghani Jul 21, 2024
ab7eb11
Merge branch 'main' into feature/deformable_assets
masoudmoghani Jul 23, 2024
67b7e05
Merge branch 'main' into feature/deformable_assets
masoudmoghani Jul 29, 2024
2361a50
Update deformable_object_data
masoudmoghani Jul 30, 2024
63a7b54
Add mesh_kinematic_targets
masoudmoghani Jul 31, 2024
7413bc3
Remove soft RL env
masoudmoghani Aug 2, 2024
8f59534
Merge branch 'main' into feature/deformable_assets
Mayankm96 Aug 14, 2024
46c8fe4
runs formatter
Mayankm96 Aug 14, 2024
01e7c9d
adds proper messages for invalid prim
Mayankm96 Aug 14, 2024
c85fcdb
adapts deformable example script to reset with the view
Mayankm96 Aug 14, 2024
a897b14
adds material view to deformable
Mayankm96 Aug 15, 2024
ed0c281
redoes some api stuff
Mayankm96 Aug 16, 2024
cd010f8
fixes docstrings
Mayankm96 Aug 17, 2024
034aafb
adds material test to defo
Mayankm96 Aug 17, 2024
85ea4a4
adds errors for physx failing
Mayankm96 Aug 17, 2024
6d65cd3
simplifies check
Mayankm96 Aug 17, 2024
c8f998b
adds sim kinematic target props
Mayankm96 Aug 17, 2024
485bc42
adds test for kin targets
Mayankm96 Aug 17, 2024
6709f04
adds deformable marker
Mayankm96 Aug 17, 2024
f7eefa2
updates examples
Mayankm96 Aug 17, 2024
0552be2
Merge branch 'main' into feature/deformable_assets
Mayankm96 Aug 17, 2024
b7067d7
updates version
Mayankm96 Aug 17, 2024
6a6fed8
minor doc fixes
Mayankm96 Aug 17, 2024
de5ec2d
adds api docs
Mayankm96 Aug 17, 2024
a9fe30b
adds doc for deof
Mayankm96 Aug 17, 2024
a1ae7b0
removes stop button instruction
Mayankm96 Aug 17, 2024
3f7669c
fix typo
Mayankm96 Aug 17, 2024
4c8758a
Merge branch 'main' into feature/deformable_assets
Mayankm96 Aug 17, 2024
3f7fba9
renames sim kinematic target to nodal
Mayankm96 Aug 17, 2024
3a31491
typo
Mayankm96 Aug 17, 2024
26f2262
fix when no kinematic targets
Mayankm96 Aug 17, 2024
e9040e9
better way to hide
Mayankm96 Aug 17, 2024
72fbf63
fix typo in contact offset
Mayankm96 Aug 17, 2024
6443fc6
adds helper function to transform nodal pos
Mayankm96 Aug 17, 2024
0887215
fix highlight index
Mayankm96 Aug 17, 2024
17f843c
adds test for checking pos calculation is correct
Mayankm96 Aug 17, 2024
980cbaf
updates tutorial
Mayankm96 Aug 17, 2024
78d1997
fix docs
Mayankm96 Aug 17, 2024
4d97a0d
fix typos
Mayankm96 Aug 17, 2024
51b5423
adds attention notice for physx changes
Mayankm96 Aug 17, 2024
3f60a91
makes it clear that num bodies is 1 for rigid bodies
Mayankm96 Aug 18, 2024
4ad2e1e
explains more
Mayankm96 Aug 18, 2024
ca899b8
runs formatter
Mayankm96 Aug 20, 2024
cc7ed05
Merge branch 'main' into feature/deformable_assets
Mayankm96 Aug 20, 2024
5cf18e7
adds frame names to quants
Mayankm96 Aug 20, 2024
aa2055e
Merge branch 'feature/deformable_assets' of github.com:isaac-sim/Isaa…
Mayankm96 Aug 20, 2024
11309eb
better names
Mayankm96 Aug 20, 2024
d864844
makes color nicer than green
Mayankm96 Aug 20, 2024
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
23 changes: 23 additions & 0 deletions docs/source/api/lab/omni.isaac.lab.assets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
Articulation
ArticulationData
ArticulationCfg
DeformableObject
DeformableObjectData
DeformableObjectCfg

.. currentmodule:: omni.isaac.lab.assets

Expand Down Expand Up @@ -67,3 +70,23 @@ Articulation
:inherited-members:
:show-inheritance:
:exclude-members: __init__, class_type

Deformable Object
-----------------

.. autoclass:: DeformableObject
:members:
:inherited-members:
:show-inheritance:

.. autoclass:: DeformableObjectData
:members:
:inherited-members:
:show-inheritance:
:exclude-members: __init__

.. autoclass:: DeformableObjectCfg
:members:
:inherited-members:
:show-inheritance:
:exclude-members: __init__, class_type
2 changes: 1 addition & 1 deletion docs/source/how-to/save_camera_output.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ The simulation should start, and you can observe different objects falling down.
in the ``IsaacLab/source/standalone/tutorials/04_sensors`` directory, where the images will be saved. Additionally,
you should see the point cloud in the 3D space drawn on the viewport.

To stop the simulation, close the window, press the ``STOP`` button in the UI, or use ``Ctrl+C`` in the terminal.
To stop the simulation, close the window, or use ``Ctrl+C`` in the terminal.
Mayankm96 marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 3 additions & 2 deletions docs/source/tutorials/01_assets/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ Interacting with Assets

Having spawned objects in the scene, these tutorials show you how to create physics handles for these
objects and interact with them. These revolve around the :class:`~omni.isaac.lab.assets.AssetBase`
class and its derivatives such as :class:`~omni.isaac.lab.assets.RigidObject` and
:class:`~omni.isaac.lab.assets.Articulation`.
class and its derivatives such as :class:`~omni.isaac.lab.assets.RigidObject`,
:class:`~omni.isaac.lab.assets.Articulation` and :class:`~omni.isaac.lab.assets.DeformableObject`.

.. toctree::
:maxdepth: 1
:titlesonly:

run_rigid_object
run_articulation
run_deformable_object
3 changes: 1 addition & 2 deletions docs/source/tutorials/01_assets/run_articulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ To run the code and see the results, let's run the script from the terminal:


This command should open a stage with a ground plane, lights, and two cart-poles that are moving around randomly.
To stop the simulation, you can either close the window, press the ``STOP`` button in the UI, or press ``Ctrl+C``
in the terminal.
To stop the simulation, you can either close the window, or press ``Ctrl+C`` in the terminal.

In this tutorial, we learned how to create and interact with a simple articulation. We saw how to set the state
of an articulation (its root and joint state) and how to apply commands to it. We also saw how to update its
Expand Down
175 changes: 175 additions & 0 deletions docs/source/tutorials/01_assets/run_deformable_object.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
.. _tutorial-interact-deformable-object:


Interacting with a deformable object
====================================

.. currentmodule:: omni.isaac.lab

While deformable objects sometimes refer to a broader class of objects, such as cloths, fluids and soft bodies,
in PhysX, deformable objects syntactically correspond to soft bodies. Unlike rigid objects, soft bodies can deform
under external forces and collisions.

Soft bodies are simulated using Finite Element Method (FEM) in PhysX. The soft body comprises of two tetrahedral
meshes -- a simulation mesh and a collision mesh. The simulation mesh is used to simulate the deformations of
the soft body, while the collision mesh is used to detect collisions with other objects in the scene.
For more details, please check the `PhysX documentation`_.

This tutorial shows how to interact with a deformable object in the simulation. We will spawn a
set of soft cubes and see how to set their nodal positions and velocities, along with apply kinematic
commands to the mesh nodes to move the soft body.


The Code
~~~~~~~~

The tutorial corresponds to the ``run_deformable_object.py`` script in the ``source/standalone/tutorials/01_assets`` directory.

.. dropdown:: Code for run_deformable_object.py
:icon: code

.. literalinclude:: ../../../../source/standalone/tutorials/01_assets/run_deformable_object.py
:language: python
:emphasize-lines: 61-73, 75-77, 102-110, 112-115, 117-118, 123-130, 132-133, 139-140
:linenos:


The Code Explained
~~~~~~~~~~~~~~~~~~

Designing the scene
-------------------

Similar to the :ref:`tutorial-interact-rigid-object` tutorial, we populate the scene with a ground plane
and a light source. In addition, we add a deformable object to the scene using the :class:`assets.DeformableObject`
class. This class is responsible for spawning the prims at the input path and initializes their corresponding
deformable body physics handles.

In this tutorial, we create a cubical soft object using the spawn configuration similar to the deformable cube
in the :ref:`Spawn Objects <tutorial-spawn-prims>` tutorial. The only difference is that now we wrap
the spawning configuration into the :class:`assets.DeformableObjectCfg` class. This class contains information about
the asset's spawning strategy and default initial state. When this class is passed to
the :class:`assets.DeformableObject` class, it spawns the object and initializes the corresponding physics handles
when the simulation is played.

.. note::
The deformable object is only supported in GPU simulation and requires a mesh object to be spawned with the
deformable body physics properties on it.


As seen in the rigid body tutorial, we can spawn the deformable object into the scene in a similar fashion by creating
an instance of the :class:`assets.DeformableObject` class by passing the configuration object to its constructor.

.. literalinclude:: ../../../../source/standalone/tutorials/01_assets/run_deformable_object.py
:language: python
:start-at: # Create separate groups called "Origin1", "Origin2", "Origin3"
:end-at: cube_object = DeformableObject(cfg=cfg)

Running the simulation loop
---------------------------

Continuing from the rigid body tutorial, we reset the simulation at regular intervals, apply kinematic commands
to the deformable body, step the simulation, and update the deformable object's internal buffers.

Resetting the simulation state
""""""""""""""""""""""""""""""

Unlike rigid bodies and articulations, deformable objects have a different state representation. The state of a
deformable object is defined by the nodal positions and velocities of the mesh. The nodal positions and velocities
are defined in the **simulation world frame** and are stored in the :attr:`assets.DeformableObject.data` attribute.

We use the :attr:`assets.DeformableObject.data.default_nodal_state_w` attribute to get the default nodal state of the
spawned object prims. This default state can be configured from the :attr:`assets.DeformableObjectCfg.init_state`
attribute, which we left as identity in this tutorial.

.. attention::
The initial state in the configuration :attr:`assets.DeformableObjectCfg` specifies the pose
of the deformable object at the time of spawning. Based on this initial state, the default nodal state is
obtained when the simulation is played for the first time.

We apply transformations to the nodal positions to randomize the initial state of the deformable object.

.. literalinclude:: ../../../../source/standalone/tutorials/01_assets/run_deformable_object.py
:language: python
:start-at: # reset the nodal state of the object
:end-at: nodal_state[..., :3] = cube_object.transform_nodal_pos(nodal_state[..., :3], pos_w, quat_w)

To reset the deformable object, we first set the nodal state by calling the :meth:`assets.DeformableObject.write_nodal_state_to_sim`
method. This method writes the nodal state of the deformable object prim into the simulation buffer.
Additionally, we free all the kinematic targets set for the nodes in the previous simulation step by calling
the :meth:`assets.DeformableObject.write_nodal_kinematic_target_to_sim` method. We explain the
kinematic targets in the next section.

Finally, we call the :meth:`assets.DeformableObject.reset` method to reset any internal buffers and caches.

.. literalinclude:: ../../../../source/standalone/tutorials/01_assets/run_deformable_object.py
:language: python
:start-at: # write nodal state to simulation
:end-at: cube_object.reset()

Stepping the simulation
"""""""""""""""""""""""

Deformable bodies support user-driven kinematic control where a user can specify position targets for some of
the mesh nodes while the rest of the nodes are simulated using the FEM solver. This `partial kinematic`_ control
is useful for applications where the user wants to interact with the deformable object in a controlled manner.

In this tutorial, we apply kinematic commands to two out of the four cubes in the scene. We set the position
targets for the node at index 0 (bottom-left corner) to move the cube along the z-axis.

At every step, we increment the kinematic position target for the node by a small value. Additionally,
we set the flag to indicate that the target is a kinematic target for that node in the simulation buffer.
These are set into the simulation buffer by calling the :meth:`assets.DeformableObject.write_nodal_kinematic_target_to_sim`
method.

.. literalinclude:: ../../../../source/standalone/tutorials/01_assets/run_deformable_object.py
:language: python
:start-at: # update the kinematic target for cubes at index 0 and 3
:end-at: cube_object.write_nodal_kinematic_target_to_sim(nodal_kinematic_target)

Similar to the rigid object and articulation, we perform the :meth:`assets.DeformableObject.write_data_to_sim` method
before stepping the simulation. For deformable objects, this method does not apply any external forces to the object.
However, we keep this method for completeness and future extensions.

.. literalinclude:: ../../../../source/standalone/tutorials/01_assets/run_deformable_object.py
:language: python
:start-at: # write internal data to simulation
:end-at: cube_object.write_data_to_sim()

Updating the state
""""""""""""""""""

After stepping the simulation, we update the internal buffers of the deformable object prims to reflect their new state
inside the :class:`assets.DeformableObject.data` attribute. This is done using the :meth:`assets.DeformableObject.update` method.

At a fixed interval, we print the root position of the deformable object to the terminal. As mentioned
earlier, there is no concept of a root state for deformable objects. However, we compute the root position as
the average position of all the nodes in the mesh.

.. literalinclude:: ../../../../source/standalone/tutorials/01_assets/run_deformable_object.py
:language: python
:start-at: # update buffers
:end-at: print(f"Root position (in world): {cube_object.data.root_pos_w[:, :3]}")


The Code Execution
~~~~~~~~~~~~~~~~~~

Now that we have gone through the code, let's run the script and see the result:

.. code-block:: bash

./isaaclab.sh -p source/standalone/tutorials/01_assets/run_deformable_object.py


This should open a stage with a ground plane, lights, and several green cubes. Two of the four cubes must be dropping
Mayankm96 marked this conversation as resolved.
Show resolved Hide resolved
from a height and settling on to the ground. Meanwhile the other two cubes must be moving along the z-axis. You
should see a marker showing the kinematic target position for the nodes at the bottom-left corner of the cubes.
To stop the simulation, you can either close the window, or press ``Ctrl+C`` in the terminal

This tutorial showed how to spawn rigid objects and wrap them in a :class:`DeformableObject` class to initialize their
physics handles which allows setting and obtaining their state. In the next tutorial, we will see how to interact
with an articulated object which is a collection of rigid objects connected by joints.

.. _PhysX documentation: https://nvidia-omniverse.github.io/PhysX/physx/5.4.1/docs/SoftBodies.html
.. _partial kinematic: https://nvidia-omniverse.github.io/PhysX/physx/5.4.1/docs/SoftBodies.html#kinematic-soft-bodies
3 changes: 1 addition & 2 deletions docs/source/tutorials/05_controllers/run_diff_ik.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,4 @@ The script will start a simulation with 128 robots. The robots will be controlle
The current and desired end-effector poses should be displayed using frame markers. When the robot reaches
the desired pose, the command should cycle through to the next pose specified in the script.

To stop the simulation, you can either close the window, or press the ``STOP`` button in the UI, or
press ``Ctrl+C`` in the terminal.
To stop the simulation, you can either close the window, or press ``Ctrl+C`` in the terminal.
2 changes: 1 addition & 1 deletion source/extensions/omni.isaac.lab/config/extension.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

# Note: Semantic Versioning is used: https://semver.org/
version = "0.22.0"
version = "0.22.1"

# Description
title = "Isaac Lab framework for Robot Learning"
Expand Down
11 changes: 11 additions & 0 deletions source/extensions/omni.isaac.lab/docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Changelog
---------

0.22.1 (2024-08-17)
~~~~~~~~~~~~~~~~~~~

Added
^^^^^

* Added APIs to interact with the physics simulation of deformable objects. This includes setting the
material properties, setting kinematic targets, and getting the state of the deformable object.
For more information, please refer to the :mod:`omni.isaac.lab.assets.DeformableObject` class.


0.22.0 (2024-08-14)
~~~~~~~~~~~~~~~~~~~

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@
from .articulation import Articulation, ArticulationCfg, ArticulationData
from .asset_base import AssetBase
from .asset_base_cfg import AssetBaseCfg
from .deformable_object import DeformableObject, DeformableObjectCfg, DeformableObjectData
from .rigid_object import RigidObject, RigidObjectCfg, RigidObjectData
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,10 @@ def _initialize_impl(self):
# -- articulation
self._root_physx_view = self._physics_sim_view.create_articulation_view(root_prim_path_expr.replace(".*", "*"))

# check if the articulation was created
if self._root_physx_view._backend is None:
raise RuntimeError(f"Failed to create articulation at: {self.cfg.prim_path}. Please check PhysX logs.")
Comment on lines +913 to +914
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Can you add this and the other raised Exceptions to the Raises: section of docstring. Not critical by any means!


# log information about the articulation
carb.log_info(f"Articulation initialized at: {self.cfg.prim_path} with root '{root_prim_path_expr}'.")
carb.log_info(f"Is fixed root: {self.is_fixed_base}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2022-2024, The Isaac Lab Project Developers.
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause

"""Sub-module for deformable object assets."""

from .deformable_object import DeformableObject
from .deformable_object_cfg import DeformableObjectCfg
from .deformable_object_data import DeformableObjectData
Loading
Loading