Unverified Commit 8ed87a00 authored by Mayank Mittal's avatar Mayank Mittal Committed by GitHub

Uses PhysX accelerations for rigid body acceleration data (#760)

# Description

Previously, we used finite differencing to compute rigid body
accelerations. Since Isaac Sim 4.0, we can obtain the accelerations
directly from PhysX. This MR removes the need for finite differencing.

## Type of change

- New feature (non-breaking change which adds functionality)
- This change requires a documentation update

## Checklist

- [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
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
parent c3e4b0d0
[package] [package]
# Note: Semantic Versioning is used: https://semver.org/ # Note: Semantic Versioning is used: https://semver.org/
version = "0.20.1" version = "0.20.2"
# Description # Description
title = "Isaac Lab framework for Robot Learning" title = "Isaac Lab framework for Robot Learning"
......
Changelog Changelog
--------- ---------
0.20.1 (2024-07-26) 0.20.2 (2024-08-02)
~~~~~~~~~~~~~~~~~~~
Changed
^^^^^^^
* Modified the computation of body acceleration for rigid body data to use PhysX APIs instead of
numerical finite-differencing. This removes the need for computation of body acceleration at
every update call of the data buffer.
0.20.1 (2024-07-30)
~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
Fixed Fixed
......
...@@ -191,7 +191,6 @@ class RigidObject(AssetBase): ...@@ -191,7 +191,6 @@ class RigidObject(AssetBase):
# note: we need to do this here since tensors are not set into simulation until step. # note: we need to do this here since tensors are not set into simulation until step.
# set into internal buffers # set into internal buffers
self._data.root_state_w[env_ids, 7:] = root_velocity.clone() self._data.root_state_w[env_ids, 7:] = root_velocity.clone()
self._data._previous_body_vel_w[env_ids, 0] = root_velocity.clone()
self._data.body_acc_w[env_ids] = 0.0 self._data.body_acc_w[env_ids] = 0.0
# set into simulation # set into simulation
self.root_physx_view.set_velocities(self._data.root_state_w[:, 7:], indices=physx_env_ids) self.root_physx_view.set_velocities(self._data.root_state_w[:, 7:], indices=physx_env_ids)
......
...@@ -57,9 +57,6 @@ class RigidObjectData: ...@@ -57,9 +57,6 @@ class RigidObjectData:
self.GRAVITY_VEC_W = gravity_dir.repeat(self._root_physx_view.count, 1) self.GRAVITY_VEC_W = gravity_dir.repeat(self._root_physx_view.count, 1)
self.FORWARD_VEC_B = torch.tensor((1.0, 0.0, 0.0), device=self.device).repeat(self._root_physx_view.count, 1) self.FORWARD_VEC_B = torch.tensor((1.0, 0.0, 0.0), device=self.device).repeat(self._root_physx_view.count, 1)
# Initialize buffers for finite differencing
self._previous_body_vel_w = torch.zeros((self._root_physx_view.count, 1, 6), device=self.device)
# Initialize the lazy buffers. # Initialize the lazy buffers.
self._root_state_w = TimestampedBuffer() self._root_state_w = TimestampedBuffer()
self._body_acc_w = TimestampedBuffer() self._body_acc_w = TimestampedBuffer()
...@@ -71,9 +68,6 @@ class RigidObjectData: ...@@ -71,9 +68,6 @@ class RigidObjectData:
dt: The time step for the update. This must be a positive value. dt: The time step for the update. This must be a positive value.
""" """
self._sim_timestamp += dt self._sim_timestamp += dt
# Trigger an update of the body acceleration buffer at a higher frequency
# since we do finite differencing.
self.body_acc_w
## ##
# Names. # Names.
...@@ -119,12 +113,8 @@ class RigidObjectData: ...@@ -119,12 +113,8 @@ class RigidObjectData:
"""Acceleration of all bodies. Shape is (num_instances, 1, 6).""" """Acceleration of all bodies. Shape is (num_instances, 1, 6)."""
if self._body_acc_w.timestamp < self._sim_timestamp: if self._body_acc_w.timestamp < self._sim_timestamp:
# note: we use finite differencing to compute acceleration # note: we use finite differencing to compute acceleration
self._body_acc_w.data = (self.body_vel_w - self._previous_body_vel_w) / ( self._body_acc_w.data = self._root_physx_view.get_accelerations().unsqueeze(1)
self._sim_timestamp - self._body_acc_w.timestamp
)
self._body_acc_w.timestamp = self._sim_timestamp self._body_acc_w.timestamp = self._sim_timestamp
# update the previous velocity
self._previous_body_vel_w[:] = self.body_vel_w
return self._body_acc_w.data return self._body_acc_w.data
@property @property
......
...@@ -602,6 +602,7 @@ class TestRigidObject(unittest.TestCase): ...@@ -602,6 +602,7 @@ class TestRigidObject(unittest.TestCase):
with build_simulation_context( with build_simulation_context(
device=device, gravity_enabled=False, add_ground_plane=True, auto_add_lighting=True device=device, gravity_enabled=False, add_ground_plane=True, auto_add_lighting=True
) as sim: ) as sim:
# Create a scene with random cubes
cube_object, _ = generate_cubes_scene(num_cubes=num_cubes, height=1.0, device=device) cube_object, _ = generate_cubes_scene(num_cubes=num_cubes, height=1.0, device=device)
# Play sim # Play sim
...@@ -640,6 +641,7 @@ class TestRigidObject(unittest.TestCase): ...@@ -640,6 +641,7 @@ class TestRigidObject(unittest.TestCase):
for gravity_enabled in [True, False]: for gravity_enabled in [True, False]:
with self.subTest(num_cubes=num_cubes, device=device, gravity_enabled=gravity_enabled): with self.subTest(num_cubes=num_cubes, device=device, gravity_enabled=gravity_enabled):
with build_simulation_context(device=device, gravity_enabled=gravity_enabled) as sim: with build_simulation_context(device=device, gravity_enabled=gravity_enabled) as sim:
# Create a scene with random cubes
cube_object, _ = generate_cubes_scene(num_cubes=num_cubes, device=device) cube_object, _ = generate_cubes_scene(num_cubes=num_cubes, device=device)
# Obtain gravity direction # Obtain gravity direction
...@@ -663,6 +665,13 @@ class TestRigidObject(unittest.TestCase): ...@@ -663,6 +665,13 @@ class TestRigidObject(unittest.TestCase):
# update object # update object
cube_object.update(sim.cfg.dt) cube_object.update(sim.cfg.dt)
# Expected gravity value is the acceleration of the body
gravity = torch.zeros(num_cubes, 1, 6, device=device)
if gravity_enabled:
gravity[:, :, 2] = -9.81
# Check the body accelerations are correct
torch.testing.assert_close(cube_object.data.body_acc_w, gravity)
if __name__ == "__main__": if __name__ == "__main__":
run_tests() run_tests()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment