Skip to content

Commit b257249

Browse files
committed
optimize imu updates
1 parent 8f28454 commit b257249

File tree

1 file changed

+12
-11
lines changed
  • source/isaaclab/isaaclab/sensors/imu

1 file changed

+12
-11
lines changed

source/isaaclab/isaaclab/sensors/imu/imu.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,13 @@ def _initialize_impl(self):
140140

141141
def _update_buffers_impl(self, env_ids: Sequence[int]):
142142
"""Fills the buffers of the sensor data."""
143-
# check if self._dt is set (this is set in the update function)
144-
if not hasattr(self, "_dt"):
145-
raise RuntimeError(
146-
"The update function must be called before the data buffers are accessed the first time."
147-
)
143+
148144
# default to all sensors
149145
if len(env_ids) == self._num_envs:
150146
env_ids = slice(None)
151147
# obtain the poses of the sensors
152148
pos_w, quat_w = self._view.get_transforms()[env_ids].split([3, 4], dim=-1)
153-
quat_w = math_utils.convert_quat(quat_w, to="wxyz")
149+
quat_w = quat_w.roll(1, dims=-1)
154150

155151
# store the poses
156152
self._data.pos_w[env_ids] = pos_w + math_utils.quat_apply(quat_w, self._offset_pos_b[env_ids])
@@ -170,12 +166,17 @@ def _update_buffers_impl(self, env_ids: Sequence[int]):
170166
# numerical derivative
171167
lin_acc_w = (lin_vel_w - self._prev_lin_vel_w[env_ids]) / self._dt + self._gravity_bias_w[env_ids]
172168
ang_acc_w = (ang_vel_w - self._prev_ang_vel_w[env_ids]) / self._dt
173-
# store the velocities
174-
self._data.lin_vel_b[env_ids] = math_utils.quat_apply_inverse(self._data.quat_w[env_ids], lin_vel_w)
175-
self._data.ang_vel_b[env_ids] = math_utils.quat_apply_inverse(self._data.quat_w[env_ids], ang_vel_w)
169+
# stack data in world frame and batch rotate
170+
dynamics_data = torch.stack((lin_vel_w, ang_vel_w, lin_acc_w, ang_acc_w), dim=0)
171+
dynamics_data_rot = math_utils.quat_apply_inverse(self._data.quat_w[env_ids].repeat(4, 1), dynamics_data).chunk(
172+
4, dim=0
173+
)
174+
# store the velocities.
175+
self._data.lin_vel_b[env_ids] = dynamics_data_rot[0]
176+
self._data.ang_vel_b[env_ids] = dynamics_data_rot[1]
176177
# store the accelerations
177-
self._data.lin_acc_b[env_ids] = math_utils.quat_apply_inverse(self._data.quat_w[env_ids], lin_acc_w)
178-
self._data.ang_acc_b[env_ids] = math_utils.quat_apply_inverse(self._data.quat_w[env_ids], ang_acc_w)
178+
self._data.lin_acc_b[env_ids] = dynamics_data_rot[2]
179+
self._data.ang_acc_b[env_ids] = dynamics_data_rot[3]
179180

180181
self._prev_lin_vel_w[env_ids] = lin_vel_w
181182
self._prev_ang_vel_w[env_ids] = ang_vel_w

0 commit comments

Comments
 (0)