Skip to content

Commit 39fb0b9

Browse files
fixed reset issues + brought up to speed with IsaacLab 2.0.2
1 parent a1ef18a commit 39fb0b9

File tree

2 files changed

+178
-388
lines changed

2 files changed

+178
-388
lines changed

source/isaaclab/isaaclab/assets/articulation/articulation.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,6 @@ def write_data_to_sim(self):
190190
indices=self._ALL_INDICES,
191191
is_global=False,
192192
)
193-
# Reset the external wrench after writing to the simulation.
194-
self.uses_external_wrench_positions = False
195-
# Fill the positions tensor with zeros to avoid applying the wrench at the same position in the next step.
196-
self._external_wrench_positions_b.fill_(0.0)
197193
else:
198194
self.root_physx_view.apply_forces_and_torques_at_position(
199195
force_data=self._external_force_b.view(-1, 3),
@@ -838,8 +834,7 @@ def set_external_force_and_torque(
838834
body_ids: Sequence[int] | slice | None = None,
839835
env_ids: Sequence[int] | None = None,
840836
):
841-
"""Set external force and torque to apply on the asset's bodies in their local frame. Optionally, set the position
842-
to apply the external wrench at (in the local frame of the bodies).
837+
"""Set external force and torque to apply on the asset's bodies in their local frame.
843838
844839
For many applications, we want to keep the applied external force on rigid bodies constant over a period of
845840
time (for instance, during the policy control). This function allows us to store the external force and torque
@@ -885,15 +880,26 @@ def set_external_force_and_torque(
885880
elif not isinstance(body_ids, torch.Tensor):
886881
body_ids = torch.tensor(body_ids, dtype=torch.long, device=self.device)
887882

888-
# note: we need to do this complicated indexing since torch doesn't support multi-indexing
889-
# create global body indices from env_ids and env_body_ids
890-
# (env_id * total_bodies_per_env) + body_id
891-
indices = body_ids.repeat(len(env_ids), 1) + env_ids.unsqueeze(1) * self.num_bodies
892-
indices = indices.view(-1)
893-
# set into internal buffers
894-
# note: these are applied in the write_to_sim function
895-
self._external_force_b.flatten(0, 1)[indices] = forces.flatten(0, 1)
896-
self._external_torque_b.flatten(0, 1)[indices] = torques.flatten(0, 1)
883+
# note: we need to do this complicated indexing since torch doesn't support multi-indexing
884+
# create global body indices from env_ids and env_body_ids
885+
# (env_id * total_bodies_per_env) + body_id
886+
indices = body_ids.repeat(len(env_ids), 1) + env_ids.unsqueeze(1) * self.num_bodies
887+
indices = indices.view(-1)
888+
# set into internal buffers
889+
# note: these are applied in the write_to_sim function
890+
self._external_force_b.flatten(0, 1)[indices] = forces.flatten(0, 1)
891+
self._external_torque_b.flatten(0, 1)[indices] = torques.flatten(0, 1)
892+
893+
# If the positions are not provided, the behavior and performance of the simulation should not be affected.
894+
if positions is not None:
895+
# Generates a flag that is set for the whole simulation. This is done to avoid discarding
896+
# the external wrench positions when multiple calls to this functions are made with and without positions.
897+
self.uses_external_wrench_positions = True
898+
self._external_wrench_positions_b.flatten(0, 1)[indices] = positions.flatten(0, 1)
899+
else:
900+
# If the positions are not provided, and the flag is set, then we need to ensure that the desired positions are zeroed.
901+
if self.uses_external_wrench_positions:
902+
self._external_wrench_positions_b.flatten(0, 1)[indices].fill_(0.0)
897903

898904
def set_joint_position_target(
899905
self, target: torch.Tensor, joint_ids: Sequence[int] | slice | None = None, env_ids: Sequence[int] | None = None

0 commit comments

Comments
 (0)