Skip to content

Commit

Permalink
Remove grid from composite types.
Browse files Browse the repository at this point in the history
Replaced it with flexcomp in the models.

PiperOrigin-RevId: 730070619
Change-Id: Icbc69e4c6784c6252743f689a1eafb6482d0c393
  • Loading branch information
quagla authored and copybara-github committed Feb 23, 2025
1 parent b90ff3f commit 0fcd20f
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 568 deletions.
37 changes: 1 addition & 36 deletions doc/XMLreference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2982,7 +2982,7 @@ coordinates results in compiler error. See :ref:`CComposite` in the modeling gui

.. _body-composite-type:

:at:`type`: :at-val:`[particle, grid, cable, rope, loop, cloth, box, cylinder, ellipsoid], required`
:at:`type`: :at-val:`[particle, cable], required`
This attribute determines the type of composite object. The remaining attributes and sub-elements are then
interpreted according to the type. Default settings are also adjusted depending on the type.

Expand All @@ -2993,48 +2993,13 @@ coordinates results in compiler error. See :ref:`CComposite` in the modeling gui
and replace the default sphere with a custom geom. Note that the particle composite type is deprecated and might be
removed in a future version. Instead of particle, it is recommended to use :ref:`replicate`.

The **grid** type creates a 1D or 2D grid of bodies, each having a sphere geom, a sphere site, and 3 orthogonal
sliding joints by default. The :el:`pin` sub-element can be used to specify that some bodies should not have joints,
and instead should be pinned to the parent body. Unlike the particle type, here each two neighboring bodies are
connected with a spatial tendon whose length is equality-constrained to its initial value (the sites are needed to
define the tendons). The "main" tendons are parallel to the axes of the grid. In addition one can create diagonal
"shear" tendons, using the :el:`tendon` sub-element. This type is suitable for simulating strings as well as cloth.

The **cable** type creates a 1D chain of bodies connected with ball joints, each having a geom with user-defined type
(cylinder, capsule or box). The geometry can either be defined with an array of 3D vertex coordinates :at:`vertex`
or with prescribed functions with the option :at:`curve`. Currently, only linear and trigonometric functions are
supported. For example, an helix can be obtained with curve="cos(s) sin(s) s". The size is set with the option
:at:`size`, resulting in :math:`f(s)=\{\text{size}[1]\cdot\cos(2\pi\cdot\text{size}[2]),\;
\text{size}[1]\cdot\sin(2\pi\cdot\text{size}[2]),\; \text{size}[0]\cdot s\}`.

The **cloth** type is a different way to model cloth, beyond type="grid". Here the elements are connected with
universal joints and form a kinematic spanning tree. The root of the tree is the parent body, and its coordinates in
the grid are inferred from its name - similar to rope but here the naming format is "CB2_0". Neighboring bodies that
are not connected with joints are then connected with equality-constrained spatial tendons. The resulting cloth is
non-homogeneous, because the kinematic constraints cannot be violated while the tendon equality constraints are soft.
One can make it more homogeneous by adding stretch and twist joints (similar to rope) and adjusting the strength of
their equality constraints. Shear tendons can also be added. In addition to the different physics, cloth can do
things that a 2D grid cannot do. This is because the elements of cloth have both position and orientation, while the
elements of grid can only translate. The geoms used in cloth can be ellipsoids and capsules in addition to spheres.
When elongated geoms are used, they are rotated and interleaved in a pattern that fills the holes, preventing objects
from penetrating the cloth. Furthermore the inertia of the cloth elements can be modified with the flatinertia
attribute, and can then be used with lift and drag forces to simulate ripple effects.

The **box** type creates a 3D arrangement of bodies forming the outer shell of a (soft) box. The parent body is at
the center of the box. Each element body has a geom (sphere, ellipsoid or capsule) and a single sliding joint
pointing away from the center of the box. The sliding joints are equality-constrained to their initial value.
Furthermore, to achieve smooth deformations of the sides of the box, each joint is equality-constrained to remain
equal to its neighbor joints. To preserve the volume of the soft box approximately, a fixed tendon is used to
constrain the sum of all joints to remain constant. When the user specifies elongated geoms (capsules or ellipsoids)
their long axis is aligned with the sliding joint axis. This makes the shell thicker for collision detection
purposes, preventing objects from penetrating the box. It is important to disable contacts between the elements of
the box. This is done by setting the default geom contype to 0. The user can change it of course, but if the geoms
comprising the soft box are allowed to contact each other the model will not work as intended.

The **cylinder** and **ellipsoid** types are the same as box, except the elements are projected on the surface of an
ellipsoid or a cylinder respectively. Thus the composite soft body shape is different, while everything else is the
same as in the box type.

.. _body-composite-count:

:at:`count`: :at-val:`int(3), required`
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ General

Previously, if the volumetric inertia computation failed (for example due to a very flat mesh), the compiler
would silently fall back to surface inertia computation. Now, the compiler will throw an informative error.
- Removed the composite type ``grid``. Users should instead use :ref:`flexcomp<body-flexcomp>`.

MJX
^^^
Expand Down
43 changes: 3 additions & 40 deletions doc/modeling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1193,47 +1193,10 @@ a more complete treatment, see again the :ref:`deformable <CDeformable>` section
flex, see the folder `elasticity/ <https://github.com/google-deepmind/mujoco/tree/main/model/plugin/elasticity>`__ for
several examples.

**1D grid**.
**Grid**.

|image6| |image7|

.. code-block:: xml
<composite type="grid" count="20 1 1" spacing="0.045" offset="0 0 1">
<joint kind="main" damping="0.001"/>
<tendon kind="main" width="0.01"/>
<geom size=".02" rgba=".8 .2 .1 1"/>
<pin coord="1"/>
<pin coord="13"/>
</composite>
The grid type can create 1D or 2D grids, depending on the :at:`count` attribute. Here we illustrate 1D grids. These
are strings of spheres connected with tendons whose length is soft-equality-constrained. The softness can be adjusted.
Similar to particles, the element bodies here have slider joints but no rotational joints. The plot on the right
illustrates pinning. The :el:`pin` sub-element is used to specify the grid coordinates of the pinned bodies, and the
model compiler does not generate joints for these bodies, thereby fixing them rigidly to the parent body (in this case
the world). This makes the string in the right plot hang in space. The same mechanism can be used to model a whip for
example; in that case the parent body would be moving, and the first element body would be pinned to the parent.

**2D grid**.

|image8| |image9|

.. code-block:: xml
<composite type="grid" count="9 9 1" spacing="0.05" offset="0 0 1">
<skin material="matcarpet" inflate="0.001" subgrid="3" texcoord="true"/>
<geom size=".02"/>
<pin coord="0 0"/>
<pin coord="8 0"/>
</composite>
A 2D grid can be used to simulate cloth. What it really simulates is a 2D grid of spheres connected with
equality-constrained tendons (not shown). The model compiler can also generate skin, enabled with the :el:`skin`
sub-element in the above XML. Some of the element bodies can also be pinned, similar to 1D grids but using two grid
coordinates. The plot on the right shows a cloth pinned to the world body at the two corners, and draping over our
capsule probe. The skin on the right is subdivided using bi-cubic interpolation, which increases visual quality in the
absence of textures. When textures are present (left) the benefits of subdivision are less visible.
The grid composite type has been removed. It is recommended to use 2D flex :ref:`deformable objects <CDeformable>` for
simulating thin elastic structures.

**Cable**.

Expand Down
29 changes: 0 additions & 29 deletions model/composite/grid2pin.xml

This file was deleted.

23 changes: 11 additions & 12 deletions model/hammock/hammock.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Simple humanoid on a hammock, implemented as a 2D grid composite, pinned at the corners.
-->

<option timestep="0.005" solver="CG" iterations="30" tolerance="1e-6"/>
<option timestep="0.001" solver="CG" iterations="30" tolerance="1e-6"/>

<size memory="20M"/>

Expand All @@ -41,23 +41,22 @@
width="512" height="512" mark="edge" markrgb=".8 .8 .8"/>
<material name="plane" reflectance="0.3" texture="plane" texrepeat="1 1" texuniform="true"/>
<material name="hammock" texture="hammock"/>
<model name="humanoid" file="../humanoid/humanoid.xml"/>
</asset>

<include file="humanoid_body.xml"/>

<worldbody>
<geom name="floor" pos="0 0 -1" size="0 0 .25" type="plane" material="plane" condim="3"/>
<light directional="true" diffuse=".2 .2 .2" specular="0 0 0" pos="0 0 5" dir="0 0 -1" castshadow="false"/>
<light directional="false" diffuse=".8 .8 .8" specular="0.3 0.3 0.3" pos="0 0 4" dir="0 0 -1"/>
<composite type="grid" count="11 9 1" spacing="0.2" offset="0. 0. 0">
<skin texcoord="true" material="hammock" inflate="0.01" subgrid="3"/>
<pin coord="0 0"/>
<pin coord="10 0"/>
<pin coord="0 8"/>
<pin coord="10 8"/>
<geom size=".095"/>
<joint kind="main" damping="10"/>
</composite>
<flexcomp name="hammock" type="grid" count="11 9 1" spacing="0.2 0.2 0.2" material="hammock"
radius="0.04" dim="2">
<pin id="0 8 90 98"/>
<edge equality="true" solref="0.002 5"/>
<contact selfcollide="none" internal="false" solimp=".99 .999 .00001"/>
</flexcomp>
<frame euler="0 180 -15" pos="-.4 -.2 2">
<attach model="humanoid" body="torso" prefix="humanoid_"/>
</frame>
</worldbody>

</mujoco>
157 changes: 0 additions & 157 deletions model/hammock/humanoid_body.xml

This file was deleted.

Loading

0 comments on commit 0fcd20f

Please sign in to comment.