Unverified Commit 212de427 authored by James Tigue's avatar James Tigue Committed by GitHub

Gives sensor_base tracking of dt (#2504)

# Description

<!--
Thank you for your interest in sending a pull request. Please make sure
to check the contribution guidelines.

Link:
https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html
-->

This PR give sensors knowledge of dt changing on
scene.update/sensor.update. This does two things:

- This allows for physics update rates to be changed after
initialization so that the contact_sensor correctly fetches the right
data from physics tensors.
- This also removes any issues with IMU calculating the numerical
derivative at time=0 because now it will have an initialized value.

<!-- As a practice, it is recommended to open an issue to have
discussions on the proposed pull request.
This makes it easier for the community to keep track of what is being
developed or added, and if a given feature
is demanded by more than one party. -->

## 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)

## Screenshots

Please attach before and after screenshots of the change if applicable.

<!--
Example:

| Before | After |
| ------ | ----- |
| _gif/png before_ | _gif/png after_ |

To upload images to a PR -- simply drag and drop an image while in edit
mode and it should upload the image directly. You can then paste that
source into the above before/after sections.
-->

## Checklist

- [ ] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [ ] 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
-->
Co-authored-by: 's avatarKelly Guo <kellyg@nvidia.com>
parent e5584baf
...@@ -326,7 +326,7 @@ class ContactSensor(SensorBase): ...@@ -326,7 +326,7 @@ class ContactSensor(SensorBase):
# obtain the contact forces # obtain the contact forces
# TODO: We are handling the indexing ourself because of the shape; (N, B) vs expected (N * B). # TODO: We are handling the indexing ourself because of the shape; (N, B) vs expected (N * B).
# This isn't the most efficient way to do this, but it's the easiest to implement. # This isn't the most efficient way to do this, but it's the easiest to implement.
net_forces_w = self.contact_physx_view.get_net_contact_forces(dt=self._sim_physics_dt) net_forces_w = self.contact_physx_view.get_net_contact_forces(dt=self._dt)
self._data.net_forces_w[env_ids, :, :] = net_forces_w.view(-1, self._num_bodies, 3)[env_ids] self._data.net_forces_w[env_ids, :, :] = net_forces_w.view(-1, self._num_bodies, 3)[env_ids]
# update contact force history # update contact force history
if self.cfg.history_length > 0: if self.cfg.history_length > 0:
...@@ -338,7 +338,7 @@ class ContactSensor(SensorBase): ...@@ -338,7 +338,7 @@ class ContactSensor(SensorBase):
# shape of the filtering matrix: (num_envs, num_bodies, num_filter_shapes, 3) # shape of the filtering matrix: (num_envs, num_bodies, num_filter_shapes, 3)
num_filters = self.contact_physx_view.filter_count num_filters = self.contact_physx_view.filter_count
# acquire and shape the force matrix # acquire and shape the force matrix
force_matrix_w = self.contact_physx_view.get_contact_force_matrix(dt=self._sim_physics_dt) force_matrix_w = self.contact_physx_view.get_contact_force_matrix(dt=self._dt)
force_matrix_w = force_matrix_w.view(-1, self._num_bodies, num_filters, 3) force_matrix_w = force_matrix_w.view(-1, self._num_bodies, num_filters, 3)
self._data.force_matrix_w[env_ids] = force_matrix_w[env_ids] self._data.force_matrix_w[env_ids] = force_matrix_w[env_ids]
......
...@@ -102,12 +102,6 @@ class Imu(SensorBase): ...@@ -102,12 +102,6 @@ class Imu(SensorBase):
self._data.lin_acc_b[env_ids] = 0.0 self._data.lin_acc_b[env_ids] = 0.0
self._data.ang_acc_b[env_ids] = 0.0 self._data.ang_acc_b[env_ids] = 0.0
def update(self, dt: float, force_recompute: bool = False):
# save timestamp
self._dt = dt
# execute updating
super().update(dt, force_recompute)
""" """
Implementation. Implementation.
""" """
......
...@@ -196,6 +196,7 @@ class SensorBase(ABC): ...@@ -196,6 +196,7 @@ class SensorBase(ABC):
def update(self, dt: float, force_recompute: bool = False): def update(self, dt: float, force_recompute: bool = False):
# Update the timestamp for the sensors # Update the timestamp for the sensors
self._dt = dt
self._timestamp += dt self._timestamp += dt
self._is_outdated |= self._timestamp - self._timestamp_last_update + 1e-6 >= self.cfg.update_period self._is_outdated |= self._timestamp - self._timestamp_last_update + 1e-6 >= self.cfg.update_period
# Update the buffers # Update the buffers
...@@ -218,7 +219,7 @@ class SensorBase(ABC): ...@@ -218,7 +219,7 @@ class SensorBase(ABC):
# Obtain device and backend # Obtain device and backend
self._device = sim.device self._device = sim.device
self._backend = sim.backend self._backend = sim.backend
self._sim_physics_dt = sim.get_physics_dt() self._dt = sim.get_physics_dt()
# Count number of environments # Count number of environments
env_prim_path_expr = self.cfg.prim_path.rsplit("/", 1)[0] env_prim_path_expr = self.cfg.prim_path.rsplit("/", 1)[0]
self._parent_prims = sim_utils.find_matching_prims(env_prim_path_expr) self._parent_prims = sim_utils.find_matching_prims(env_prim_path_expr)
......
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