Skip to content

Commit 439005a

Browse files
committed
optimize imu updates
1 parent caa1e94 commit 439005a

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
@@ -134,17 +134,13 @@ def _initialize_impl(self):
134134

135135
def _update_buffers_impl(self, env_ids: Sequence[int]):
136136
"""Fills the buffers of the sensor data."""
137-
# check if self._dt is set (this is set in the update function)
138-
if not hasattr(self, "_dt"):
139-
raise RuntimeError(
140-
"The update function must be called before the data buffers are accessed the first time."
141-
)
137+
142138
# default to all sensors
143139
if len(env_ids) == self._num_envs:
144140
env_ids = slice(None)
145141
# obtain the poses of the sensors
146142
pos_w, quat_w = self._view.get_transforms()[env_ids].split([3, 4], dim=-1)
147-
quat_w = math_utils.convert_quat(quat_w, to="wxyz")
143+
quat_w = quat_w.roll(1, dims=-1)
148144

149145
# store the poses
150146
self._data.pos_w[env_ids] = pos_w + math_utils.quat_apply(quat_w, self._offset_pos_b[env_ids])
@@ -164,12 +160,17 @@ def _update_buffers_impl(self, env_ids: Sequence[int]):
164160
# numerical derivative
165161
lin_acc_w = (lin_vel_w - self._prev_lin_vel_w[env_ids]) / self._dt + self._gravity_bias_w[env_ids]
166162
ang_acc_w = (ang_vel_w - self._prev_ang_vel_w[env_ids]) / self._dt
167-
# store the velocities
168-
self._data.lin_vel_b[env_ids] = math_utils.quat_apply_inverse(self._data.quat_w[env_ids], lin_vel_w)
169-
self._data.ang_vel_b[env_ids] = math_utils.quat_apply_inverse(self._data.quat_w[env_ids], ang_vel_w)
163+
# stack data in world frame and batch rotate
164+
dynamics_data = torch.stack((lin_vel_w, ang_vel_w, lin_acc_w, ang_acc_w), dim=0)
165+
dynamics_data_rot = math_utils.quat_apply_inverse(self._data.quat_w[env_ids].repeat(4, 1), dynamics_data).chunk(
166+
4, dim=0
167+
)
168+
# store the velocities.
169+
self._data.lin_vel_b[env_ids] = dynamics_data_rot[0]
170+
self._data.ang_vel_b[env_ids] = dynamics_data_rot[1]
170171
# store the accelerations
171-
self._data.lin_acc_b[env_ids] = math_utils.quat_apply_inverse(self._data.quat_w[env_ids], lin_acc_w)
172-
self._data.ang_acc_b[env_ids] = math_utils.quat_apply_inverse(self._data.quat_w[env_ids], ang_acc_w)
172+
self._data.lin_acc_b[env_ids] = dynamics_data_rot[2]
173+
self._data.ang_acc_b[env_ids] = dynamics_data_rot[3]
173174

174175
self._prev_lin_vel_w[env_ids] = lin_vel_w
175176
self._prev_ang_vel_w[env_ids] = ang_vel_w

0 commit comments

Comments
 (0)