Add articulation and robot joint limit APIs#359
Open
yuecideng wants to merge 11 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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(...)andArticulation.set_*_limits(...)APIs withenv_ids/joint_idsfiltering, 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
Robotlimit getters/setters that supportjoint_ids, keep backward-compatiblenameprecedence, 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.
| 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, | ||
| ) |
…robot-joint-limits
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 on lines
+1592
to
+1594
| qpos_limits: Union[ | ||
| torch.Tensor, np.ndarray, Sequence[float], Dict[str, List[float]], None | ||
| ] = None |
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]], | ||
| ] |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
namehandling andjoint_idssupport.Motivation and context:
RobotandArticulationset_joint_limits,set_joint_velocity_limit, andset_joint_effort_limitDependencies: 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
Screenshots
N/A
Checklist
black.