@@ -134,17 +134,13 @@ def _initialize_impl(self):
134
134
135
135
def _update_buffers_impl (self , env_ids : Sequence [int ]):
136
136
"""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
+
142
138
# default to all sensors
143
139
if len (env_ids ) == self ._num_envs :
144
140
env_ids = slice (None )
145
141
# obtain the poses of the sensors
146
142
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 )
148
144
149
145
# store the poses
150
146
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]):
164
160
# numerical derivative
165
161
lin_acc_w = (lin_vel_w - self ._prev_lin_vel_w [env_ids ]) / self ._dt + self ._gravity_bias_w [env_ids ]
166
162
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 ]
170
171
# 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 ]
173
174
174
175
self ._prev_lin_vel_w [env_ids ] = lin_vel_w
175
176
self ._prev_ang_vel_w [env_ids ] = ang_vel_w
0 commit comments