Skip to content

Commit b0e1cbe

Browse files
Separates joint state setters inside Articulation class (#1751)
# Description Previously in the Articulation class, there was a single method for setting joint state. However, it is desirable at times to only set joint position or velocity. For instance, for randomization events that pushes a joint by adding a random velocity to it. This MR separates the `write_joint_state_to_sim` into separate setters for joint positions and joint velocities. This goes inline with the method to set root pose, root velocity or the root state. ## Type of change - New feature (non-breaking change which adds functionality) ## Checklist - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there --------- Signed-off-by: Mayank Mittal <[email protected]> Co-authored-by: Kelly Guo <[email protected]>
1 parent 4868e19 commit b0e1cbe

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

source/isaaclab/config/extension.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
# Note: Semantic Versioning is used: https://semver.org/
4-
version = "0.34.6"
4+
version = "0.34.7"
55

66
# Description
77
title = "Isaac Lab framework for Robot Learning"

source/isaaclab/docs/CHANGELOG.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
Changelog
22
---------
33

4+
0.34.7 (2025-03-04)
5+
~~~~~~~~~~~~~~~~~~~
6+
7+
Added
8+
^^^^^
9+
10+
* Added methods inside the :class:`omni.isaac.lab.assets.Articulation` class to set the joint
11+
position and velocity for the articulation. Previously, the joint position and velocity could
12+
only be set using the :meth:`omni.isaac.lab.assets.Articulation.write_joint_state_to_sim` method,
13+
which didn't allow setting the joint position and velocity separately.
14+
15+
416
0.34.6 (2025-03-02)
517
~~~~~~~~~~~~~~~~~~~
618

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

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,23 @@ def write_joint_state_to_sim(
484484
joint_ids: The joint indices to set the targets for. Defaults to None (all joints).
485485
env_ids: The environment indices to set the targets for. Defaults to None (all environments).
486486
"""
487+
# set into simulation
488+
self.write_joint_position_to_sim(position, joint_ids=joint_ids, env_ids=env_ids)
489+
self.write_joint_velocity_to_sim(velocity, joint_ids=joint_ids, env_ids=env_ids)
490+
491+
def write_joint_position_to_sim(
492+
self,
493+
position: torch.Tensor,
494+
joint_ids: Sequence[int] | slice | None = None,
495+
env_ids: Sequence[int] | slice | None = None,
496+
):
497+
"""Write joint positions to the simulation.
498+
499+
Args:
500+
position: Joint positions. Shape is (len(env_ids), len(joint_ids)).
501+
joint_ids: The joint indices to set the targets for. Defaults to None (all joints).
502+
env_ids: The environment indices to set the targets for. Defaults to None (all environments).
503+
"""
487504
# resolve indices
488505
physx_env_ids = env_ids
489506
if env_ids is None:
@@ -496,15 +513,41 @@ def write_joint_state_to_sim(
496513
env_ids = env_ids[:, None]
497514
# set into internal buffers
498515
self._data.joint_pos[env_ids, joint_ids] = position
499-
self._data.joint_vel[env_ids, joint_ids] = velocity
500-
self._data._previous_joint_vel[env_ids, joint_ids] = velocity
501-
self._data.joint_acc[env_ids, joint_ids] = 0.0
502516
# Need to invalidate the buffer to trigger the update with the new root pose.
503517
self._data._body_state_w.timestamp = -1.0
504518
self._data._body_link_state_w.timestamp = -1.0
505519
self._data._body_com_state_w.timestamp = -1.0
506520
# set into simulation
507521
self.root_physx_view.set_dof_positions(self._data.joint_pos, indices=physx_env_ids)
522+
523+
def write_joint_velocity_to_sim(
524+
self,
525+
velocity: torch.Tensor,
526+
joint_ids: Sequence[int] | slice | None = None,
527+
env_ids: Sequence[int] | slice | None = None,
528+
):
529+
"""Write joint velocities to the simulation.
530+
531+
Args:
532+
velocity: Joint velocities. Shape is (len(env_ids), len(joint_ids)).
533+
joint_ids: The joint indices to set the targets for. Defaults to None (all joints).
534+
env_ids: The environment indices to set the targets for. Defaults to None (all environments).
535+
"""
536+
# resolve indices
537+
physx_env_ids = env_ids
538+
if env_ids is None:
539+
env_ids = slice(None)
540+
physx_env_ids = self._ALL_INDICES
541+
if joint_ids is None:
542+
joint_ids = slice(None)
543+
# broadcast env_ids if needed to allow double indexing
544+
if env_ids != slice(None) and joint_ids != slice(None):
545+
env_ids = env_ids[:, None]
546+
# set into internal buffers
547+
self._data.joint_vel[env_ids, joint_ids] = velocity
548+
self._data._previous_joint_vel[env_ids, joint_ids] = velocity
549+
self._data.joint_acc[env_ids, joint_ids] = 0.0
550+
# set into simulation
508551
self.root_physx_view.set_dof_velocities(self._data.joint_vel, indices=physx_env_ids)
509552

510553
def write_joint_stiffness_to_sim(

0 commit comments

Comments
 (0)