Skip to content

Commit 5293634

Browse files
Updates PhysX external forces default to True (#6523)
# Description Default enable_external_forces_every_iteration to true for PhysX and warn when users opt out with the deprecated flag. Add a deprecation warning and a breaking changelog fragment. ## Type of change <!-- As you go through the list, delete the ones that are not applicable. --> - Bug fix (non-breaking change which fixes an issue) - Breaking change (existing functionality will not work without user modification) ## Checklist - [x] I have read and understood the [contribution guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html) - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file - [ ] I have added my name to the `CONTRIBUTORS.md` or my name already exists there <!-- As you go through the checklist above, you can mark something as done by putting an x character in it For example, - [x] I have done this task - [ ] I have not done this task --> --------- Signed-off-by: Kelly Guo <kellyg@nvidia.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent 4947574 commit 5293634

6 files changed

Lines changed: 64 additions & 20 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Internal: adjusted operational-space controller tests for the updated PhysX solver behavior.

source/isaaclab/test/controllers/test_operational_space.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ def sim():
155155
)
156156
d_ratio_set = torch.tensor(
157157
[
158-
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
159-
[1.1, 1.1, 1.1, 1.1, 1.1, 1.1],
160-
[0.9, 0.9, 0.9, 0.9, 0.9, 0.9],
158+
[2.0, 2.0, 2.0, 2.0, 2.0, 2.0],
159+
[2.2, 2.2, 2.2, 2.2, 2.2, 2.2],
160+
[1.8, 1.8, 1.8, 1.8, 1.8, 1.8],
161161
],
162162
device=sim.device,
163163
)
@@ -333,6 +333,7 @@ def test_franka_pose_abs_with_partial_inertial_decoupling(sim):
333333
goal_marker,
334334
contact_forces,
335335
frame,
336+
rotation_tolerance=0.12,
336337
)
337338

338339

@@ -368,7 +369,7 @@ def test_franka_pose_abs_fixed_impedance_with_gravity_compensation(sim):
368369
partial_inertial_dynamics_decoupling=False,
369370
gravity_compensation=True,
370371
motion_stiffness_task=500.0,
371-
motion_damping_ratio_task=1.0,
372+
motion_damping_ratio_task=2.0,
372373
)
373374
osc = OperationalSpaceController(osc_cfg, num_envs=num_envs, device=sim_context.device)
374375

@@ -1121,6 +1122,7 @@ def test_franka_pose_abs_with_partial_inertial_decoupling_nullspace_centering(si
11211122
motion_stiffness_task=1000.0,
11221123
motion_damping_ratio_task=1.0,
11231124
nullspace_control="position",
1125+
nullspace_stiffness=1.0,
11241126
)
11251127
osc = OperationalSpaceController(osc_cfg, num_envs=num_envs, device=sim_context.device)
11261128

@@ -1136,6 +1138,7 @@ def test_franka_pose_abs_with_partial_inertial_decoupling_nullspace_centering(si
11361138
goal_marker,
11371139
contact_forces,
11381140
frame,
1141+
rotation_tolerance=0.12,
11391142
)
11401143

11411144

@@ -1172,6 +1175,7 @@ def test_franka_pose_abs_with_nullspace_centering(sim):
11721175
motion_stiffness_task=500.0,
11731176
motion_damping_ratio_task=1.0,
11741177
nullspace_control="position",
1178+
nullspace_stiffness=1.0,
11751179
)
11761180
osc = OperationalSpaceController(osc_cfg, num_envs=num_envs, device=sim_context.device)
11771181

@@ -1426,6 +1430,8 @@ def _run_op_space_controller(
14261430
contact_forces: ContactSensor | None,
14271431
frame: str,
14281432
convergence_steps: int = 500,
1433+
position_tolerance: float = 0.1,
1434+
rotation_tolerance: float = 0.1,
14291435
):
14301436
"""Run the operational space controller with the given parameters.
14311437
@@ -1442,6 +1448,8 @@ def _run_op_space_controller(
14421448
contact_forces (ContactSensor | None): The contact forces sensor.
14431449
frame (str): The reference frame for targets.
14441450
convergence_steps (int): Number of simulation steps to run before checking convergence. Defaults to 500.
1451+
position_tolerance (float): Maximum position error norm. Defaults to 0.1.
1452+
rotation_tolerance (float): Maximum rotation error norm. Defaults to 0.1.
14451453
"""
14461454
# Initialize the masks for evaluating target convergence according to selection matrices
14471455
pos_mask = torch.tensor(osc.cfg.motion_control_axes_task[:3], device=sim.device).view(1, 3)
@@ -1501,7 +1509,17 @@ def _run_op_space_controller(
15011509
# check that we converged to the goal
15021510
if count > 0:
15031511
_check_convergence(
1504-
osc, ee_pose_b, ee_target_pose_b, ee_force_b, command, pos_mask, rot_mask, force_mask, frame
1512+
osc,
1513+
ee_pose_b,
1514+
ee_target_pose_b,
1515+
ee_force_b,
1516+
command,
1517+
pos_mask,
1518+
rot_mask,
1519+
force_mask,
1520+
frame,
1521+
position_tolerance,
1522+
rotation_tolerance,
15051523
)
15061524
# reset joint state to default
15071525
default_joint_pos = robot.data.default_joint_pos.torch.clone()
@@ -1774,6 +1792,8 @@ def _check_convergence(
17741792
rot_mask: torch.tensor,
17751793
force_mask: torch.tensor,
17761794
frame: str,
1795+
position_tolerance: float,
1796+
rotation_tolerance: float,
17771797
):
17781798
"""Check the convergence to the target.
17791799
@@ -1787,6 +1807,8 @@ def _check_convergence(
17871807
rot_mask (torch.tensor): The rotation mask.
17881808
force_mask (torch.tensor): The force mask.
17891809
frame (str): The reference frame for targets.
1810+
position_tolerance (float): Maximum position error norm.
1811+
rotation_tolerance (float): Maximum rotation error norm.
17901812
17911813
Raises:
17921814
AssertionError: If the convergence is not achieved.
@@ -1803,8 +1825,8 @@ def _check_convergence(
18031825
# desired error (zer)
18041826
des_error = torch.zeros_like(pos_error_norm)
18051827
# check convergence
1806-
torch.testing.assert_close(pos_error_norm, des_error, rtol=0.0, atol=0.1)
1807-
torch.testing.assert_close(rot_error_norm, des_error, rtol=0.0, atol=0.1)
1828+
torch.testing.assert_close(pos_error_norm, des_error, rtol=0.0, atol=position_tolerance)
1829+
torch.testing.assert_close(rot_error_norm, des_error, rtol=0.0, atol=rotation_tolerance)
18081830
cmd_idx += 7
18091831
elif target_type == "pose_rel":
18101832
pos_error, rot_error = compute_pose_error(
@@ -1815,8 +1837,8 @@ def _check_convergence(
18151837
# desired error (zer)
18161838
des_error = torch.zeros_like(pos_error_norm)
18171839
# check convergence
1818-
torch.testing.assert_close(pos_error_norm, des_error, rtol=0.0, atol=0.1)
1819-
torch.testing.assert_close(rot_error_norm, des_error, rtol=0.0, atol=0.1)
1840+
torch.testing.assert_close(pos_error_norm, des_error, rtol=0.0, atol=position_tolerance)
1841+
torch.testing.assert_close(rot_error_norm, des_error, rtol=0.0, atol=rotation_tolerance)
18201842
cmd_idx += 6
18211843
elif target_type == "wrench_abs":
18221844
force_target_b = ee_target_b[:, cmd_idx : cmd_idx + 3].clone()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Changed
2+
^^^^^^^
3+
4+
* **Breaking:** Changed :attr:`~isaaclab_physx.physics.PhysxCfg.enable_external_forces_every_iteration`
5+
to default to ``True``. Remove explicit ``True`` overrides; explicit ``False``
6+
overrides emit a ``DeprecationWarning`` because the PhysX flag will be removed
7+
in a future release.

source/isaaclab_physx/isaaclab_physx/physics/physx_manager.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import re
1717
import time
18+
import warnings
1819
from collections.abc import Callable
1920
from datetime import datetime
2021
from enum import Enum
@@ -678,8 +679,18 @@ def _configure_physics(cls) -> None:
678679
sim_utils.bind_physics_material(sim_cfg.physics_prim_path, mat_path)
679680

680681
# warnings
681-
if cfg.solver_type == 1 and not cfg.enable_external_forces_every_iteration:
682-
logger.warning("TGS solver with enable_external_forces_every_iteration=False may cause noisy velocities.")
682+
if not cfg.enable_external_forces_every_iteration:
683+
warning_message = (
684+
"PhysxCfg.enable_external_forces_every_iteration is deprecated and will be removed in a future "
685+
"PhysX release. External forces are applied every iteration by default; remove this override."
686+
)
687+
if cfg.solver_type == 1:
688+
warning_message += " Disabling this behavior with the TGS solver may cause noisy velocities."
689+
warnings.warn(
690+
warning_message,
691+
DeprecationWarning,
692+
stacklevel=2,
693+
)
683694
if not cfg.enable_stabilization and sim_cfg.dt > 0.0333:
684695
logger.warning("Large timestep without stabilization may cause physics issues.")
685696

source/isaaclab_physx/isaaclab_physx/physics/physx_manager_cfg.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,21 @@ class PhysxCfg(PhysicsCfg):
147147
Enabling this flag may lead to incorrect contact forces report from the contact sensor.
148148
"""
149149

150-
enable_external_forces_every_iteration: bool = False
151-
"""Enable/disable external forces every position iteration in the TGS solver. Default is False.
150+
enable_external_forces_every_iteration: bool = True
151+
"""Enable/disable external forces every position iteration in the TGS solver. Default is True.
152152
153153
When using the TGS solver (:attr:`solver_type` is 1), this flag allows enabling external forces
154154
every solver position iteration. This can help improve the accuracy of velocity updates.
155-
Consider enabling this flag if the velocities generated by the simulation are noisy.
156-
Increasing the number of velocity iterations, together with this flag, can help improve
157-
the accuracy of velocity updates.
155+
Increasing the number of velocity iterations, together with this flag, can help improve the
156+
accuracy of velocity updates.
158157
159158
.. note::
160159
161160
This flag is ignored when using the PGS solver (:attr:`solver_type` is 0).
161+
162+
.. deprecated:: TBD
163+
164+
This flag is deprecated and will be removed in a future PhysX release.
162165
"""
163166

164167
enable_enhanced_determinism: bool = False

source/isaaclab_physx/test/assets/test_rigid_object.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def test_set_material_properties_via_view(num_cubes, device):
649649
@pytest.mark.parametrize("device", test_devices())
650650
@pytest.mark.isaacsim_ci
651651
def test_rigid_body_no_friction(num_cubes, device):
652-
"""Test that a rigid object with no friction will maintain it's velocity when sliding across a plane."""
652+
"""Test that a rigid object with no friction maintains its tangential velocity on a plane."""
653653
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
654654
sim._app_control_on_stop_handle = None
655655
# Generate cubes scene
@@ -701,7 +701,7 @@ def test_rigid_body_no_friction(num_cubes, device):
701701
tolerance = 1e-5
702702

703703
torch.testing.assert_close(
704-
cube_object.data.root_lin_vel_w.torch, initial_velocity[:, :3], rtol=1e-5, atol=tolerance
704+
cube_object.data.root_lin_vel_w.torch[:, :2], initial_velocity[:, :2], rtol=1e-5, atol=tolerance
705705
)
706706

707707

@@ -858,8 +858,8 @@ def test_rigid_body_with_restitution(num_cubes, device):
858858
curr_z_velocity = cube_object.data.root_lin_vel_w.torch[:, 2].clone()
859859

860860
if expected_collision_type == "inelastic":
861-
# assert that the block has not bounced by checking that the z velocity is less than or equal to 0
862-
assert (curr_z_velocity <= 0.0).all()
861+
# Allow a small contact separation velocity while ensuring that the block does not bounce.
862+
assert (curr_z_velocity <= 1e-3).all()
863863

864864
if torch.all(curr_z_velocity <= 0.0):
865865
# Still in the air

0 commit comments

Comments
 (0)