Skip to content

[FEATURE] Add relative quaternion getter#2765

Open
Travor278 wants to merge 1 commit intoGenesis-Embodied-AI:mainfrom
Travor278:feature/relative-quat-getter
Open

[FEATURE] Add relative quaternion getter#2765
Travor278 wants to merge 1 commit intoGenesis-Embodied-AI:mainfrom
Travor278:feature/relative-quat-getter

Conversation

@Travor278
Copy link
Copy Markdown

@Travor278 Travor278 commented May 7, 2026

Description

Adds a keyword-only relative parameter to KinematicEntity.get_quat(). When relative=True, the method returns the base link orientation relative to the entity's initial quaternion. The default remains relative=False, so existing calls to get_quat() and get_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 satisfies abs_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 absolute set_quat() calls.
  • get_quat(relative=False) matches get_quat(), preserving the previous default behavior.

Additional regression coverage verifies that:

  • heterogeneous variants with different initial quaternions use the per-environment initial pose as the relative reference;
  • envs_idx subsetting keeps the relative getter aligned with the selected environments;
  • non-parallel scene paths return quaternion-shaped relative results, including batch_links_info=True;
  • attached entities without a free-root quaternion slot use the link initial orientation reference instead of reading unrelated qpos0 entries.

Validated locally with Python 3.12.13:

D:\Dev\conda-envs\py312\python.exe -m pytest tests/test_rigid_physics.py::test_get_quat_relative_heterogeneous_initial_quat tests/test_rigid_physics.py::test_get_quat_relative_non_parallel tests/test_rigid_physics.py::test_get_quat_relative_non_parallel_batched_link_info tests/test_rigid_physics.py::test_set_root_pose -q --numprocesses=0
D:\Dev\conda-envs\py312\python.exe -m pytest tests/test_rigid_physics.py::test_merge_entities -q --numprocesses=0

Results:

  • selected quaternion/root-pose cases: 7 passed
  • tests/test_rigid_physics.py::test_merge_entities: 4 passed

Checklist:

  • I read the CONTRIBUTING document.
  • I followed the Submitting Code Changes section of CONTRIBUTING document.
  • I tagged the title correctly (including BUG FIX/FEATURE/MISC/BREAKING)
  • I updated the documentation accordingly or no change is needed.
  • I tested my changes and added instructions on how to test it for reviewers.
  • I have added tests to cover my changes.

@Travor278
Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

ℹ️ 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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add get_quat(..., relative=True)

1 participant