Repository navigation
Fix action clipping for task-space action terms - #8715
Conversation
ActionTermCfg.clip keys are regular expressions that the joint action terms match against joint names. DifferentialInverseKinematicsAction did the same but indexed its task-space clip buffer with the resulting joint indices, which raises an IndexError when more joints match than the action has components and otherwise applies joint ranges to pose components. OperationalSpaceControllerAction only copied the setting into its IO descriptor and never applied it. Both terms now expose action_names, the component names in the order of the action vector (pos_x, rot_x, quat_x, force_x, stiffness_x, ...), and resolve the clip keys against them. Keys that match nothing raise, and so do keys that match quaternion components, since clamping those does not give a valid orientation. The OSC term applies the clip after its scaling and keeps the controller limits on the impedance parameters. Fixes isaac-sim#1548
[Medium impact] Fixes action clipping logic for task-space control modes. Fix the quaternion rejection for prefixed action names before merging. Findings
SummaryFixes task-space clipping by matching ranges against action component names rather than joint names.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Configured targets] --> B[Build action names]
B --> C[Match clip keys]
C --> D[Reject quaternion matches]
D --> E[Clip scaled actions]
E --> F[Controller clamps gains]
F --> G[Controller sets targets]
Reviews (1) · Last reviewed commit: "Fix action clipping for task-space actio..." · Reviewed by Greptile |
| if not isinstance(clip, dict): | ||
| raise ValueError(f"Unsupported clip type: {type(clip)}. Supported types are dict.") | ||
| index_list, matched_names, value_list = string_utils.resolve_matching_names_values(clip, action_names) | ||
| quat_names = [name for name in matched_names if name in _QUATERNION_NAMES] |
There was a problem hiding this comment.
Quaternion clips escape rejection
With target_types=("pose_rel", "pose_abs"), _resolve_action_names produces names such as pose_abs_quat_x. This check only recognizes unprefixed names, so clip={"pose_abs_quat_.*": (-0.1, 0.1)} is accepted and clamps quaternion components instead of raising. The controller then normalizes the altered quaternion, which can change the requested orientation.
Recognize quaternion components even when their names have a block prefix, and add a regression test for this configuration.
There was a problem hiding this comment.
Isaac Lab Review Bot
Needs attention: Scope and over-engineering (1), API (1), Compatibility and deprecation (1), Implementation (2), Style consistency (1), Test quality (2). Other reviewed categories look good.
- PR description: Correct the claim that controller limits narrow OSC clip ranges, because clipping currently runs afterward, and state that DiffIK position commands expose only position names.
- Design and architecture: Architecture looks good.
- Scope and over-engineering: Minimal implementation: keep
_resolve_task_space_clipintask_space_actions.py, merge OSC name generation into command-index resolution, and retain the cfg, changelog, and focused tests; no source modules were added. Scope is cohesive; no split recommended. - API: Prefixing every OSC block on pose-name collisions produces undocumented
stiffness_stiffness_*anddamping_ratio_damping_ratio_*names; prefix only colliding pose blocks. - Compatibility and deprecation: Breaking changes: previously accepted joint-name clip dictionaries now fail without a functional deprecation bridge; preserve them temporarily with a targeted warning and documented migration.
- Implementation: OSC clipping runs after controller gain clamps, allowing configured clip minima to exceed controller limits; apply user clipping before the controller limits.
- Style consistency: The private clip resolver precedes public classes, violating repository file ordering; move it below the public classes.
- Test quality: Of eight added cases, one DiffIK position row repeats the same path and the OSC unmatched-key case duplicates shared-resolver coverage; remove both.
Significant concerns. Posted 8 inline findings.
Automated review; human maintainers own approval decisions.
| min=self.cfg.controller_cfg.motion_damping_ratio_limits_task[0], | ||
| max=self.cfg.controller_cfg.motion_damping_ratio_limits_task[1], | ||
| ) | ||
| # Clip the processed actions. The controller limits above still apply, so a user range only narrows them. |
There was a problem hiding this comment.
🔴 Critical · Implementation — Clip can exceed controller gain limits
Clipping runs after the stiffness and damping clamps, so a clip range above the controller limit raises the clamped value past it, contradicting this comment and the cfg docs. Clip before the limits.
| self._clip = torch.tensor([[-float("inf"), float("inf")]], device=self.device).repeat( | ||
| self.num_envs, self.action_dim, 1 | ||
| ) | ||
| index_list, _, value_list = string_utils.resolve_matching_names_values(self.cfg.clip, self._joint_names) |
There was a problem hiding this comment.
🟡 Warning · Compatibility — Clip key namespace changed without transition
Joint-name clip dictionaries that previously resolved here (including .* when joint and action counts matched) now raise at construction. Keep them working with a deprecation warning, or raise an error naming the accepted action names.
| _TASK_AXES = ("x", "y", "z", "rx", "ry", "rz") | ||
|
|
||
|
|
||
| def _resolve_task_space_clip( |
There was a problem hiding this comment.
🟡 Warning · Style Consistency — Private helper precedes public classes
The guide's file order is public functions, public classes, then private functions. Move _resolve_task_space_clip below the two action classes.
| if not isinstance(clip, dict): | ||
| raise ValueError(f"Unsupported clip type: {type(clip)}. Supported types are dict.") | ||
| index_list, matched_names, value_list = string_utils.resolve_matching_names_values(clip, action_names) | ||
| quat_names = [name for name in matched_names if name in _QUATERNION_NAMES] |
There was a problem hiding this comment.
🟡 Warning · Implementation — Quaternion guard misses prefixed names
With both pose targets, names become pose_abs_quat_x, which is not in _QUATERNION_NAMES, so quaternion clipping is silently accepted despite the documented rejection. Match the component suffix or track quaternion indices.
| targets), every name is prefixed with the name of its block. | ||
| """ | ||
| blocks: list[tuple[str, tuple[str, ...]]] = [] | ||
| for target_type in self.cfg.controller_cfg.target_types: |
There was a problem hiding this comment.
🟡 Warning · Scope Complexity — Duplicate target-type layout switch
_resolve_command_indexes already enumerates each target type's block size; this second switch must stay in sync and silently skips unknown types. Produce the names inside the existing index resolution and delete this method.
| blocks.append(("damping_ratio", tuple(f"damping_ratio_{axis}" for axis in _TASK_AXES))) | ||
| names = [name for _, block_names in blocks for name in block_names] | ||
| if len(set(names)) != len(names): | ||
| names = [f"{block}_{name}" for block, block_names in blocks for name in block_names] |
There was a problem hiding this comment.
🟡 Warning · Api — Prefixing breaks documented impedance keys
A pose_abs plus pose_rel collision prefixes every block, yielding stiffness_stiffness_x and damping_ratio_damping_ratio_x, so the stiffness_<axis> keys documented in the cfg no longer match. Prefix only the colliding pose blocks.
| ("command_type", "use_relative_mode", "expected"), | ||
| [ | ||
| ("position", False, ["pos_x", "pos_y", "pos_z"]), | ||
| ("position", True, ["pos_x", "pos_y", "pos_z"]), |
There was a problem hiding this comment.
🟡 Warning · Test Quality — Duplicate position parametrize row
action_names branches only on command_type == "pose", so the position/True row runs the same path and asserts the same list as position/False. Drop one row.
| torch.testing.assert_close(processed[:, :2], raw[:, :2]) | ||
|
|
||
|
|
||
| def test_osc_clip_unknown_key_raises(): |
There was a problem hiding this comment.
🟡 Warning · Test Quality — Duplicate unmatched-key error test
The no-match ValueError comes from the shared _resolve_task_space_clip, already proven by test_diff_ik_clip_with_joint_names_raises, and OSC clip wiring is proven by the clipping test. Remove this replay.
|
Addressed the review findings in e49bc4c:
|
AntoineRichard
left a comment
There was a problem hiding this comment.
Thanks @Lynn-hh for the PR! Moved the tests, and added a small fix. Thanks again!
|
run-ci |
|
Thanks for consolidating the tests and for the empty-dict guard, @AntoineRichard! |
|
Thank you @AntoineRichard for the review and the test consolidation, and @hujc7 for merging! |
# Description Follow-up to #8715 for the two action terms it didn't cover. `RMPFlowAction` and `NonHolonomicAction` still resolved `ActionTermCfg.clip` keys against joint names and then indexed the action vector with those joint indices: - `RMPFlowAction` has a task-space action (6-D relative, 7-D absolute pose). With a 7-joint arm in relative mode, `clip={".*": ...}` raised `IndexError: index 6 is out of bounds for dimension 0 with size 6`; with fewer joints, joint ranges were applied to pose components. - `NonHolonomicAction` has a 2-D action (forward velocity, turning rate) but matched the keys against its three dummy base joints. Both terms now expose `action_names` and resolve `clip` against them, as #8715 did for DiffIK and OSC: - RMPFlow: `pos_x`, `pos_y`, `pos_z`, then `rot_x`, `rot_y`, `rot_z` (relative) or `quat_x`, `quat_y`, `quat_z`, `quat_w` (absolute). It reuses `_resolve_task_space_clip`, so keys that match nothing or a quaternion component raise. - Non-holonomic: `lin_vel_x`, `ang_vel_z`. Unmatched keys raise through the strict name resolver. No task in the repo sets `clip` on either term. Fixes #1732 (together with #2019 for raw-action clipping in the RL wrappers and #8715 for the other task-space terms). ## Type of change - Bug fix - Breaking change: `clip` keys that name joints on these two terms now raise a `ValueError`; use the action names listed above (recorded as **Breaking** in the changelog, with a major bump) ## Checklist - [x] I have read and understood the [contribution guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html) - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `uv run isaaclab --format` - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have validated the changed behavior with focused coverage and applied the [test-audit criteria](https://github.com/isaac-sim/IsaacLab/blob/HEAD/skills/developer/test-audit/SKILL.md) to any test changes - [x] I have added a changelog fragment under `source/<pkg>/changelog.d/` for every touched package (do **not** edit `CHANGELOG.rst` or bump package versions — CI handles that) - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there Testing: the existing DiffIK clip tests are parametrized over RMPFlow: valid keys clip the processed pose actions, joint-name keys raise, and quaternion keys raise. On `main` the RMPFlow cases fail (joint-name keys hit `IndexError: index 6 is out of bounds for dimension 0 with size 6`; the other keys don't match any joint name). With this change all 20 tests in `source/isaaclab/test/envs/mdp/test_actions.py` pass. The non-holonomic change has no test coverage here.
Description
ActionTermCfg.clipkeys are regular expressions that the joint action terms match against joint names. The task-space terms could not do anything sensible with that:DifferentialInverseKinematicsActionresolved the keys against the joint names and then indexed its task-space clip buffer(num_envs, action_dim, 2)with the resulting joint indices. With seven matching joints and a 6-dimensionalpose_relaction this raisesIndexError; with fewer, joint ranges are silently applied to pose components.OperationalSpaceControllerActioncopiedclipinto its IO descriptor and never applied it.This follows the direction from #1548 (action-specific key names, interpreted by each action class):
action_names, the component names in the order of the action vector. DiffIK:pos_x, pos_y, pos_zplusrot_x, rot_y, rot_z(relative pose) orquat_x, quat_y, quat_z, quat_w(absolute pose). OSC: the components of each target type in order (pos_*/rot_*,pos_*/quat_*,force_*/torque_*), thenstiffness_<axis>anddamping_ratio_<axis>for the variable impedance modes; if both pose targets are configured, the pose components are prefixed with their target type (pose_abs_pos_x,pose_rel_pos_x, ...); the impedance names are unchanged.clipkeys are resolved against these names. A key that matches nothing raises, and so does a key that matches a quaternion component, because clamping quaternion components does not give a valid orientation (the concern raised in [Bug Report] Issues with recently added action clipping for task space actions #1548).action_namesis also added to the IO descriptors, and theclipdocstrings onActionTermCfgand the two task-space cfgs describe the keys.#1732 proposes the alternative of removing processed-action clipping from the task-space terms altogether and relying on raw-action clipping in the RL wrappers (
RslRlOnPolicyRunnerCfg.clip_actionsexists today). If the maintainers prefer that, I am happy to reduce this PR to raising a clear error forclipon task-space terms plus the documentation changes.Fixes #1548
Related to #1732
Type of change
action_namespropertyValidation
Kit-less unit tests (no simulator), new file
source/isaaclab/test/envs/test_task_space_action_clip.py:With the three source files reverted to
develop, all 11 new tests fail (IndexError / missingaction_names/ unclipped OSC actions / noValueError). The tests build the action terms on a stub articulation and environment, the same waytest_diffik_jacobian_aliasing.pydoes, and cover: the names for every DiffIK command layout and for OSC target/impedance combinations, DiffIK clipping of selected components, OSC clipping of position and stiffness including the interaction with the controller limits, and the error cases (joint-name keys, quaternion keys with and without a block prefix). The simulator-based controller tests were not run locally; arun-ciwould be appreciated.Release backport
developChecklist
pre-commitchecks (all hooks pass on the changed files)source/<pkg>/changelog.d/for every touched package (do not editCHANGELOG.rstor bump package versions — CI handles that)CONTRIBUTORS.mdor my name already exists there