Skip to content

Commit dc06012

Browse files
Remove ensure_nonstatic_links option from importers (#1682)
Signed-off-by: adenzler-nvidia <adenzler@nvidia.com>
1 parent a16e12b commit dc06012

6 files changed

Lines changed: 7 additions & 67 deletions

File tree

newton/_src/sim/builder.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,8 +1504,6 @@ def add_urdf(
15041504
force_show_colliders: bool = False,
15051505
enable_self_collisions: bool = True,
15061506
ignore_inertial_definitions: bool = False,
1507-
ensure_nonstatic_links: bool = False,
1508-
static_link_mass: float = 1e-2,
15091507
joint_ordering: Literal["bfs", "dfs"] | None = "dfs",
15101508
bodies_follow_joint_ordering: bool = True,
15111509
collapse_fixed_joints: bool = False,
@@ -1590,8 +1588,6 @@ def add_urdf(
15901588
force_show_colliders (bool): If True, the collision shapes are always shown, even if there are visual shapes.
15911589
enable_self_collisions (bool): If True, self-collisions are enabled.
15921590
ignore_inertial_definitions (bool): If True, the inertial parameters defined in the URDF are ignored and the inertia is calculated from the shape geometry.
1593-
ensure_nonstatic_links (bool): If True, links with zero mass are given a small mass (see `static_link_mass`) to ensure they are dynamic.
1594-
static_link_mass (float): The mass to assign to links with zero mass (if `ensure_nonstatic_links` is set to True).
15951591
joint_ordering (str): The ordering of the joints in the simulation. Can be either "bfs" or "dfs" for breadth-first or depth-first search, or ``None`` to keep joints in the order in which they appear in the URDF. Default is "dfs".
15961592
bodies_follow_joint_ordering (bool): If True, the bodies are added to the builder in the same order as the joints (parent then child body). Otherwise, bodies are added in the order they appear in the URDF. Default is True.
15971593
collapse_fixed_joints (bool): If True, fixed joints are removed and the respective bodies are merged.
@@ -1619,8 +1615,6 @@ def add_urdf(
16191615
force_show_colliders=force_show_colliders,
16201616
enable_self_collisions=enable_self_collisions,
16211617
ignore_inertial_definitions=ignore_inertial_definitions,
1622-
ensure_nonstatic_links=ensure_nonstatic_links,
1623-
static_link_mass=static_link_mass,
16241618
joint_ordering=joint_ordering,
16251619
bodies_follow_joint_ordering=bodies_follow_joint_ordering,
16261620
collapse_fixed_joints=collapse_fixed_joints,
@@ -1859,8 +1853,6 @@ def add_mjcf(
18591853
force_show_colliders: bool = False,
18601854
enable_self_collisions: bool = True,
18611855
ignore_inertial_definitions: bool = False,
1862-
ensure_nonstatic_links: bool = False,
1863-
static_link_mass: float = 1e-2,
18641856
collapse_fixed_joints: bool = False,
18651857
verbose: bool = False,
18661858
skip_equality_constraints: bool = False,
@@ -1959,8 +1951,6 @@ def add_mjcf(
19591951
force_show_colliders (bool): If True, the collision shapes are always shown, even if there are visual shapes.
19601952
enable_self_collisions (bool): If True, self-collisions are enabled.
19611953
ignore_inertial_definitions (bool): If True, the inertial parameters defined in the MJCF are ignored and the inertia is calculated from the shape geometry.
1962-
ensure_nonstatic_links (bool): If True, links with zero mass are given a small mass (see `static_link_mass`) to ensure they are dynamic.
1963-
static_link_mass (float): The mass to assign to links with zero mass (if `ensure_nonstatic_links` is set to True).
19641954
collapse_fixed_joints (bool): If True, fixed joints are removed and the respective bodies are merged.
19651955
verbose (bool): If True, print additional information about parsing the MJCF.
19661956
skip_equality_constraints (bool): Whether <equality> tags should be parsed. If True, equality constraints are ignored.
@@ -2001,8 +1991,6 @@ def add_mjcf(
20011991
force_show_colliders=force_show_colliders,
20021992
enable_self_collisions=enable_self_collisions,
20031993
ignore_inertial_definitions=ignore_inertial_definitions,
2004-
ensure_nonstatic_links=ensure_nonstatic_links,
2005-
static_link_mass=static_link_mass,
20061994
collapse_fixed_joints=collapse_fixed_joints,
20071995
verbose=verbose,
20081996
skip_equality_constraints=skip_equality_constraints,

newton/_src/utils/import_mjcf.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ def parse_mjcf(
155155
force_show_colliders: bool = False,
156156
enable_self_collisions: bool = True,
157157
ignore_inertial_definitions: bool = False,
158-
ensure_nonstatic_links: bool = False,
159-
static_link_mass: float = 1e-2,
160158
collapse_fixed_joints: bool = False,
161159
verbose: bool = False,
162160
skip_equality_constraints: bool = False,
@@ -256,8 +254,6 @@ def parse_mjcf(
256254
force_show_colliders (bool): If True, the collision shapes are always shown, even if there are visual shapes.
257255
enable_self_collisions (bool): If True, self-collisions are enabled.
258256
ignore_inertial_definitions (bool): If True, the inertial parameters defined in the MJCF are ignored and the inertia is calculated from the shape geometry.
259-
ensure_nonstatic_links (bool): If True, links with zero mass are given a small mass (see `static_link_mass`) to ensure they are dynamic.
260-
static_link_mass (float): The mass to assign to links with zero mass (if `ensure_nonstatic_links` is set to True).
261257
collapse_fixed_joints (bool): If True, fixed joints are removed and the respective bodies are merged.
262258
verbose (bool): If True, print additional information about parsing the MJCF.
263259
skip_equality_constraints (bool): Whether <equality> tags should be parsed. If True, equality constraints are ignored.
@@ -1455,16 +1451,6 @@ def parse_body(
14551451
builder.body_inv_inertia[link] = wp.inverse(I_m)
14561452
else:
14571453
builder.body_inv_inertia[link] = I_m
1458-
if m == 0.0 and ensure_nonstatic_links:
1459-
# set the mass to something nonzero to ensure the body is dynamic
1460-
m = static_link_mass
1461-
# cube with side length 0.5
1462-
I_m = wp.mat33(np.eye(3)) * m / 12.0 * (0.5 * scale) ** 2 * 2.0
1463-
I_m += wp.mat33(builder.default_body_armature * np.eye(3))
1464-
builder.body_mass[link] = m
1465-
builder.body_inv_mass[link] = 1.0 / m
1466-
builder.body_inertia[link] = I_m
1467-
builder.body_inv_inertia[link] = wp.inverse(I_m)
14681454

14691455
# -----------------
14701456
# recurse

newton/_src/utils/import_urdf.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ def parse_urdf(
8080
force_show_colliders: bool = False,
8181
enable_self_collisions: bool = True,
8282
ignore_inertial_definitions: bool = False,
83-
ensure_nonstatic_links: bool = False,
84-
static_link_mass: float = 1e-2,
8583
joint_ordering: Literal["bfs", "dfs"] | None = "dfs",
8684
bodies_follow_joint_ordering: bool = True,
8785
collapse_fixed_joints: bool = False,
@@ -167,8 +165,6 @@ def parse_urdf(
167165
force_show_colliders (bool): If True, the collision shapes are always shown, even if there are visual shapes.
168166
enable_self_collisions (bool): If True, self-collisions are enabled.
169167
ignore_inertial_definitions (bool): If True, the inertial parameters defined in the URDF are ignored and the inertia is calculated from the shape geometry.
170-
ensure_nonstatic_links (bool): If True, links with zero mass are given a small mass (see `static_link_mass`) to ensure they are dynamic.
171-
static_link_mass (float): The mass to assign to links with zero mass (if `ensure_nonstatic_links` is set to True).
172168
joint_ordering (str): The ordering of the joints in the simulation. Can be either "bfs" or "dfs" for breadth-first or depth-first search, or ``None`` to keep joints in the order in which they appear in the URDF. Default is "dfs".
173169
bodies_follow_joint_ordering (bool): If True, the bodies are added to the builder in the same order as the joints (parent then child body). Otherwise, bodies are added in the order they appear in the URDF. Default is True.
174170
collapse_fixed_joints (bool): If True, fixed joints are removed and the respective bodies are merged.
@@ -651,16 +647,6 @@ def parse_shapes(link: int, geoms, density, incoming_xform=None, visible=True, j
651647
m = float(el_mass.get("value", 0))
652648
builder.body_mass[link] = m
653649
builder.body_inv_mass[link] = 1.0 / m if m > 0.0 else 0.0
654-
if m == 0.0 and ensure_nonstatic_links:
655-
# set the mass to something nonzero to ensure the body is dynamic
656-
m = static_link_mass
657-
# cube with side length 0.5
658-
I_m = wp.mat33(np.eye(3)) * m / 12.0 * (0.5 * scale) ** 2 * 2.0
659-
I_m += wp.mat33(builder.default_body_armature * np.eye(3))
660-
builder.body_mass[link] = m
661-
builder.body_inv_mass[link] = 1.0 / m
662-
builder.body_inertia[link] = I_m
663-
builder.body_inv_inertia[link] = wp.inverse(I_m)
664650

665651
end_shape_count = len(builder.shape_type)
666652

newton/tests/test_import_mjcf.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6125,15 +6125,14 @@ def test_frictionloss_from_default_class(self):
61256125

61266126

61276127
class TestZeroMassBodies(unittest.TestCase):
6128-
"""Verify that ``ensure_nonstatic_links`` correctly handles zero-mass bodies.
6128+
"""Verify that zero-mass bodies are preserved as-is during import.
61296129
61306130
Models may contain zero-mass bodies (sensor frames, reference links).
6131-
These tests ensure the default (False) preserves zero mass and that
6132-
opting in (True) assigns a small surrogate mass.
6131+
These should keep their zero mass after import.
61336132
"""
61346133

6135-
def test_ensure_nonstatic_links_default_false(self):
6136-
"""Verify zero-mass bodies keep zero mass with the default setting."""
6134+
def test_zero_mass_body_preserved(self):
6135+
"""Verify zero-mass bodies keep zero mass after import."""
61376136
mjcf = """
61386137
<mujoco>
61396138
<worldbody>
@@ -6150,22 +6149,3 @@ def test_ensure_nonstatic_links_default_false(self):
61506149

61516150
empty_idx = next(i for i in range(builder.body_count) if builder.body_key[i] == "empty_body")
61526151
self.assertEqual(builder.body_mass[empty_idx], 0.0)
6153-
6154-
def test_ensure_nonstatic_links_opt_in(self):
6155-
"""Verify zero-mass bodies receive surrogate mass when opted in."""
6156-
mjcf = """
6157-
<mujoco>
6158-
<worldbody>
6159-
<body name="robot" pos="0 0 1">
6160-
<freejoint name="root"/>
6161-
<inertial pos="0 0 0" mass="1.0" diaginertia="0.01 0.01 0.01"/>
6162-
</body>
6163-
<body name="empty_body" pos="0.5 0 0"/>
6164-
</worldbody>
6165-
</mujoco>
6166-
"""
6167-
builder = newton.ModelBuilder()
6168-
builder.add_mjcf(mjcf, ensure_nonstatic_links=True)
6169-
6170-
empty_idx = next(i for i in range(builder.body_count) if builder.body_key[i] == "empty_body")
6171-
self.assertGreater(builder.body_mass[empty_idx], 0.0)

newton/tests/test_import_urdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ def add_link(self, *args, key=None, **kwargs):
15951595

15961596
builder = _SkippingLinkBuilder()
15971597
with self.assertWarnsRegex(UserWarning, "was not created, skipping mimic constraint"):
1598-
builder.add_urdf(urdf, joint_ordering=None, ensure_nonstatic_links=False)
1598+
builder.add_urdf(urdf, joint_ordering=None)
15991599

16001600
# No mimic constraint should be created because the follower joint was skipped.
16011601
self.assertEqual(len(builder.constraint_mimic_joint0), 0)

newton/tests/test_mujoco_solver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6087,8 +6087,8 @@ class TestMuJoCoSolverZeroMassBody(unittest.TestCase):
60876087
def test_zero_mass_body(self):
60886088
"""SolverMuJoCo accepts models with zero-mass bodies (e.g. sensor frames).
60896089
6090-
With ensure_nonstatic_links=False (the default), zero-mass bodies keep
6091-
their zero mass. MuJoCo handles these natively when they have fixed joints.
6090+
Zero-mass bodies keep their zero mass. MuJoCo handles these natively
6091+
when they have fixed joints.
60926092
"""
60936093
mjcf = """
60946094
<mujoco>

0 commit comments

Comments
 (0)