@@ -140,17 +140,13 @@ def _initialize_impl(self):
140
140
141
141
def _update_buffers_impl (self , env_ids : Sequence [int ]):
142
142
"""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
+
148
144
# default to all sensors
149
145
if len (env_ids ) == self ._num_envs :
150
146
env_ids = slice (None )
151
147
# obtain the poses of the sensors
152
148
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 )
154
150
155
151
# store the poses
156
152
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]):
170
166
# numerical derivative
171
167
lin_acc_w = (lin_vel_w - self ._prev_lin_vel_w [env_ids ]) / self ._dt + self ._gravity_bias_w [env_ids ]
172
168
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 ]
176
177
# 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 ]
179
180
180
181
self ._prev_lin_vel_w [env_ids ] = lin_vel_w
181
182
self ._prev_ang_vel_w [env_ids ] = ang_vel_w
0 commit comments