[FEATURE] Add relative quaternion getter#2764
Conversation
💡 Codex Review
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
c6236e1 to
f6a4cb1
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f6a4cb1da1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| init_quat = qd_to_torch( | ||
| self._solver.qpos0, | ||
| envs_idx, | ||
| slice(q_start + 3, q_start + 7), | ||
| transpose=True, | ||
| copy=True, | ||
| ) |
There was a problem hiding this comment.
Preserve unbatched quaternion shape in relative getter
When scene.build() is used without parallel envs (n_envs == 0) and the base link is not fixed, this branch pulls init_quat from qpos0 without removing the singleton env dimension. abs_quat is 1D in this mode, so transform_quat_by_quat(...) returns a (1, 4) tensor instead of (4,), which breaks the documented/output shape parity with get_quat() and can cause silent broadcasting bugs in downstream quaternion math.
Useful? React with 👍 / 👎.
f6a4cb1 to
05673df
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 05673df30d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| q_start = self.base_link.q_start | ||
| init_quat = qd_to_torch( | ||
| self._solver.qpos0, | ||
| envs_idx, | ||
| slice(q_start + 3, q_start + 7), | ||
| transpose=True, |
There was a problem hiding this comment.
Handle attached fixed-base entities in relative quaternion getter
When relative=True, this branch assumes any non-fixed base link has a free-root quaternion in qpos0, but attach() can flip base_link.is_fixed to False for originally fixed-base entities attached to a non-fixed parent (see link._is_fixed &= parent_link.is_fixed). In that case the base link does not have a root quaternion slot, so slice(q_start + 3, q_start + 7) reads unrelated qpos0 entries (or from an invalid start), producing incorrect relative quaternions for attached entities. This regression is new because the previous get_quat() only returned absolute state and did not depend on q_start.
Useful? React with 👍 / 👎.
05673df to
0e19ff4
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e19ff4258
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| copy=True, | ||
| ) | ||
| if self._solver.n_envs == 0: | ||
| init_quat = init_quat[0] |
There was a problem hiding this comment.
Remove residual link axis in single-env relative get_quat
When relative=True and batch_links_info=True in a non-parallel scene (n_envs == 0), this branch keeps an extra link dimension ((1, 4)) instead of reducing to (4,). The subsequent quaternion composition broadcasts against abs_quat and returns (1, 4), which violates the documented single-environment return shape and can break consumers that expect a flat quaternion. Squeeze both env and link axes here (for example, index both dimensions) before calling inv_quat.
Useful? React with 👍 / 👎.
0e19ff4 to
6386ad7
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Superseded by #2765 with the same final patch in a clean review thread. |
Description
Adds a keyword-only
relativeparameter toKinematicEntity.get_quat(). Whenrelative=True, the method returns the base link orientation relative to the entity's initial quaternion. The default remainsrelative=False, so existing calls toget_quat()andget_quat(envs_idx)keep returning the same absolute quaternion as before.The relative getter mirrors the existing
set_quat(..., relative=True)behavior by using the same initial base-link quaternion reference as the setter, including per-environment initial quaternions for heterogeneous variants. The returned quaternion satisfiesabs_quat == transform_quat_by_quat(init_quat, delta).Related Issue
Resolves #2730
Motivation and Context
set_quat()already supports applying quaternions relative to the initial orientation, which is useful for domain randomization and RL observation pipelines. Without the matching getter, users have to manually track the initial quaternion and repeat the inverse-composition math in their own scripts.This change makes the API more symmetric, reduces boilerplate quaternion math for users, and keeps the absolute-orientation getter as the backwards-compatible default.
How Has This Been / Can This Be Tested?
The root-pose coverage now checks both the new relative path and the old absolute path:
get_quat(relative=True)returns the expected relative quaternion after both relative and absoluteset_quat()calls.get_quat(relative=False)matchesget_quat(), preserving the previous default behavior.Additional regression coverage verifies that:
envs_idxsubsetting keeps the relative getter aligned with the selected environments;batch_links_info=True;qpos0entries.Validated locally with Python 3.12.13:
Results:
tests/test_rigid_physics.py::test_merge_entities: 4 passedChecklist:
Submitting Code Changessection of CONTRIBUTING document.