Skip to content

Add articulation and robot joint limit APIs#359

Open
yuecideng wants to merge 11 commits into
mainfrom
feature/articulation-robot-joint-limits
Open

Add articulation and robot joint limit APIs#359
yuecideng wants to merge 11 commits into
mainfrom
feature/articulation-robot-joint-limits

Conversation

@yuecideng

Copy link
Copy Markdown
Contributor

Description

This PR adds articulation-level joint position, velocity, and effort limit getters plus DexSim-backed setters, and exposes matching robot APIs with backward-compatible name handling and joint_ids support.

Motivation and context:

  • unify joint limit API naming between Robot and Articulation
  • add direct support for DexSim set_joint_limits, set_joint_velocity_limit, and set_joint_effort_limit
  • keep limit caches synchronized after drive updates and cover the behavior with regression tests

Dependencies: None.

Issue reference: N/A

Verification:

  • pytest tests/sim/objects/test_articulation.py tests/sim/objects/test_robot.py -q (62 passed)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which improves an existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (existing functionality will not work without user modification)
  • Documentation update

Screenshots

N/A

Checklist

  • I have verified the modified files are formatted with black.
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature works
  • Dependencies have been updated, if applicable.

Copilot AI review requested due to automatic review settings July 4, 2026 14:54
@yuecideng yuecideng added enhancement New feature or request dexsim Things related to dexsim robot Module related to robot labels Jul 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends EmbodiChain’s simulation object layer by adding articulation-level joint limit getters/setters (position/velocity/effort) with DexSim-backed writes, and exposes matching robot APIs that support both control-part (name) selection and explicit joint_ids filtering while preserving prior precedence behavior.

Changes:

  • Added Articulation.get_*_limits(...) and Articulation.set_*_limits(...) APIs with env_ids/joint_ids filtering, input shape coercion, and cache updates.
  • Updated Articulation.set_qpos(...) to clamp against per-environment joint position limits (instead of using a single env’s limits).
  • Added Robot limit getters/setters that support joint_ids, keep backward-compatible name precedence, and are covered by new regression tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
tests/sim/objects/test_robot.py Adds regression tests validating Robot limit APIs for control parts, joint_ids, and setter precedence.
tests/sim/objects/test_articulation.py Adds comprehensive tests for limit getter/setter filtering, cache synchronization, failure behavior, and qpos clamping.
embodichain/lab/sim/objects/robot.py Introduces a shared joint-id resolution helper and adds Robot limit getters/setters delegating to Articulation.
embodichain/lab/sim/objects/articulation.py Implements limit caching in ArticulationData, adds limit getter/setter APIs, and updates clamping/cache sync behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings July 9, 2026 09:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

env_ids (Sequence[int] | None): The environment ids to get the qpos limits for. If None, all environments are used.

Returns:
torch.Tensor: Joint position limits with shape (N, dof, 2), where N is the number of environments.
env_ids (Sequence[int] | None): The environment ids to get the qvel limits for. If None, all environments are used.

Returns:
torch.Tensor: Joint velocity limits with shape (N, dof), where N is the number of environments.
env_ids (Sequence[int] | None): The environment ids to get the qf limits for. If None, all environments are used.

Returns:
torch.Tensor: Joint effort limits with shape (N, dof), where N is the number of environments.
Comment on lines +1128 to +1132
for i, env_idx in enumerate(local_env_ids.detach().cpu().tolist()):
result = self._entities[env_idx].set_joint_position_limits(
qpos_limits[i].detach().cpu().numpy(),
joint_ids_np,
)
Copilot AI review requested due to automatic review settings July 9, 2026 14:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Comment on lines +153 to +157
def _resolve_limit_joint_ids(
self,
name: str | None,
joint_ids: Sequence[int] | None,
) -> Sequence[int] | None:
Comment on lines 191 to 192
Returns:
torch.Tensor: Joint position limits with shape (N, dof, 2), where N is the number of environments.
Comment on lines 217 to 218
Returns:
torch.Tensor: Joint velocity limits with shape (N, dof), where N is the number of environments.
Comment on lines 243 to 244
Returns:
torch.Tensor: Joint effort limits with shape (N, dof), where N is the number of environments.
Comment on lines +525 to +529
"""Recompute effective qpos limits by intersecting user limits with asset limits.

The user limits are clamped to the asset limits and then intersected with them.
Inverted user ranges (lower > upper) are swapped with a warning.

Comment thread embodichain/lab/sim/cfg.py Outdated
Comment on lines +1592 to +1594
qpos_limits: Union[
torch.Tensor, np.ndarray, Sequence[float], Dict[str, List[float]], None
] = None
Comment thread embodichain/lab/sim/cfg.py Outdated
Comment on lines +1609 to +1611
user_qpos_limits: Union[
torch.Tensor, np.ndarray, Sequence[float], Dict[str, List[float]], None
] = None
Comment on lines +420 to +424
joint_names = self.robot.get_joint_ids(name=arm_name, remove_mimic=False)
first_two_names = [
self.robot.joint_names[joint_names[0]],
self.robot.joint_names[joint_names[1]],
]
Copilot AI review requested due to automatic review settings July 9, 2026 15:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Comment on lines +153 to +157
def _resolve_limit_joint_ids(
self,
name: str | None,
joint_ids: Sequence[int] | None,
) -> Sequence[int] | None:
Comment on lines +335 to +338
"""Set user-defined joint position limits for the robot.

The user limits are intersected with the asset limits, so they can only
further restrict the allowed range.
*,
joint_ids: Sequence[int] | torch.Tensor | None = None,
) -> None:
"""Reset joint position limits to the original asset limits.
Comment on lines +107 to +109
| `set_user_qpos_limits(..., name="part")` | Set user-defined position limits for a specific part. |
| `get_user_qpos_limits(..., name="part")` | Get user-defined position limits for a specific part. |
| `reset_qpos_limits(..., name="part")` | Reset position limits to asset limits for a specific part. |
Comment on lines +420 to +424
joint_names = self.robot.get_joint_ids(name=arm_name, remove_mimic=False)
first_two_names = [
self.robot.joint_names[joint_names[0]],
self.robot.joint_names[joint_names[1]],
]
init_qpos: Union[torch.Tensor, np.ndarray, Sequence[float]] = None
"""Initial joint positions of the articulation.
init_qpos: torch.Tensor | np.ndarray | Sequence[float] = None
Comment on lines +1592 to +1611
qpos_limits: (
torch.Tensor | np.ndarray | Sequence[float] | Dict[str, List[float]] | None
) = None
"""Override joint position limits of the articulation.

If None, the joint position limits from the asset file (URDF/USD) are used.
If provided as a tensor/array of shape (num_joints, 2), it is applied to all
joints in the order of ``joint_names``.
If provided as a dictionary, keys are joint names or regular expressions and
values are ``[min, max]`` limits.

Unlike :attr:`user_qpos_limits`, this field replaces the asset limits and
can be used to expand the allowed range. When both are provided,
``qpos_limits`` is applied first to set the baseline and ``user_qpos_limits``
further restricts that baseline.
"""

user_qpos_limits: (
torch.Tensor | np.ndarray | Sequence[float] | Dict[str, List[float]] | None
) = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dexsim Things related to dexsim enhancement New feature or request robot Module related to robot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants