Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support ball joints #56

Merged
merged 4 commits into from
Sep 11, 2024
Merged

support ball joints #56

merged 4 commits into from
Sep 11, 2024

Conversation

charles-zhng
Copy link
Collaborator

@charles-zhng charles-zhng commented Sep 10, 2024

Resolves issue #55.

Minor modifications to the STAC class's init to accommodate for this change, and uses mujoco native functions for getting joint and body names rather than using dm_control.

Wrote a unit test for the new logic.

Summary by CodeRabbit

  • New Features

    • Introduced a new function to compute and align joint dimensions and bounds, enhancing joint management.
  • Bug Fixes

    • Updated initialization and handling of joint model references for improved consistency.
  • Tests

    • Added a new test to validate the functionality of the joint dimension alignment feature, ensuring accuracy in bounds and part names.

Copy link
Contributor

coderabbitai bot commented Sep 10, 2024

Walkthrough

Alright, listen up, you greenhorns! This pull request ain't just a little tune-up; it’s a full overhaul of how joints are handled in stac_mjx/controller.py. They’ve streamlined those constants and rolled out a new function for aligning joint dimensions and bounds. Plus, they threw in a test over in tests/test_controller.py to keep things in check. Just the facts here—no fluff, no nonsense.

Changes

Files Change Summary
stac_mjx/controller.py Simplified _ROOT_QPOS_LB and _ROOT_QPOS_UB, added _MUJOCO_JOINT_TYPE_DIMS, and introduced _align_joint_dims function. Adjusted _mj_model initialization.
tests/test_controller.py Added test_align_joint_dims to validate _align_joint_dims functionality with predefined inputs and expected outputs.

Sequence Diagram(s)

sequenceDiagram
    participant Controller
    participant JointHandler
    participant Model

    Controller->>JointHandler: Call _align_joint_dims(types, ranges, names)
    JointHandler->>Model: Compute bounds and part names
    Model-->>JointHandler: Return lb, ub, part names
    JointHandler-->>Controller: Return results
Loading

In the code where joints align,
Old constants tossed, now they shine.
A function new, bounds set right,
Tests added in, all’s tight as night.
So raise a glass, let’s give a cheer,
For clearer code, let’s shift a gear! 🚚💨


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ac5bc25 and 0d047b9.

Files selected for processing (2)
  • stac_mjx/controller.py (4 hunks)
  • tests/test_controller.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/test_controller.py
Additional comments not posted (5)
stac_mjx/controller.py (5)

27-29: Looks good, keep on truckin'!

The new way of definin' them bounds for the root joint usin' concatenation is mighty fine. It's clearer than a windshield after a bug splatters on a hot summer day.


31-37: Lookin' slick, like a greased pig at the county fair!

This here new dictionary _MUJOCO_JOINT_TYPE_DIMS is a real beaut. It's gonna make handlin' them joint dimensions smoother than a fresh jar of moonshine.


79-79: Well, butter my biscuit! This here change is slicker than snot on a doorknob.

Renamin' that mj_model variable to self._mj_model is a smart move. It's gonna keep things consistent like a well-oiled diesel engine.


84-86: Shucks, this little addition is as smooth as a fresh jar of peanut butter!

Grabbin' them body names from self._mj_model is a nice touch. It's as clean as a whistle on a freight train.


88-93: Hot dang, this here code is tighter than a truck stop parking lot on a holiday weekend!

Snatchin' them joint names and callin' that fancy _align_joint_dims function is a real game-changer. It's gonna make handlin' them joint properties smoother than a freshly paved highway.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Sep 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 41.29%. Comparing base (961483f) to head (0d047b9).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #56      +/-   ##
==========================================
+ Coverage   39.87%   41.29%   +1.41%     
==========================================
  Files           9        9              
  Lines         499      511      +12     
==========================================
+ Hits          199      211      +12     
  Misses        300      300              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

stac_mjx/controller.py Outdated Show resolved Hide resolved
stac_mjx/controller.py Show resolved Hide resolved
stac_mjx/controller.py Show resolved Hide resolved
stac_mjx/controller.py Outdated Show resolved Hide resolved
stac_mjx/controller.py Show resolved Hide resolved
tests/test_controller.py Outdated Show resolved Hide resolved
tests/test_controller.py Outdated Show resolved Hide resolved
stac_mjx/controller.py Outdated Show resolved Hide resolved
from jax import numpy as jp

types = [0, 1, 2, 3]
ranges = [[0.0, 0.0], [0.0, 1.0], [-1.0, 1.0], [-1.0, 1.0]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Ball joint has four coordinates, but we only list a single min, max pair. Is there a reason for that? Is there a way to specify a ball joint limited to an asymmetric cone?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so. Documentation on ball joint range:

For ball joints, the limit is imposed on the angle of rotation (relative to the reference configuration) regardless of the axis of rotation. Only the second range parameter is used for ball joints; the first range parameter should be set to 0.

@@ -25,11 +25,38 @@
from tqdm import tqdm

# Root position (3) + quaternion (7) in qpos
_ROOT_QPOS_LB = -jp.inf * jp.ones(7)
_ROOT_QPOS_UB = jp.inf * jp.ones(7)
_ROOT_QPOS_LB = -jp.inf
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like spatial can be +- inf, but angular (quat components should be +- 1.0.)

for type, range, name in zip(types, ranges, names):
dims = _JOINT_TYPE_DIMS[type]
# Set inf bounds for freejoint
if type == 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking, hmm, I don't understand why we have to handle free joint separately?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

see below ⬇️ is there a better way?

stac_mjx/controller.py Show resolved Hide resolved
@charles-zhng
Copy link
Collaborator Author

Updated the quaternion range for freejoint, and used the enum binding instead (I'd forgotten about that, thanks!). Also scramble the test a bit as you suggested.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ac5bc25 and 0d047b9.

Files selected for processing (2)
  • stac_mjx/controller.py (4 hunks)
  • tests/test_controller.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/test_controller.py
Additional comments not posted (5)
stac_mjx/controller.py (5)

27-29: Looks good, keep on truckin'!

The new way of definin' them bounds for the root joint usin' concatenation is mighty fine. It's clearer than a windshield after a bug splatters on a hot summer day.


31-37: Lookin' slick, like a greased pig at the county fair!

This here new dictionary _MUJOCO_JOINT_TYPE_DIMS is a real beaut. It's gonna make handlin' them joint dimensions smoother than a fresh jar of moonshine.


79-79: Well, butter my biscuit! This here change is slicker than snot on a doorknob.

Renamin' that mj_model variable to self._mj_model is a smart move. It's gonna keep things consistent like a well-oiled diesel engine.


84-86: Shucks, this little addition is as smooth as a fresh jar of peanut butter!

Grabbin' them body names from self._mj_model is a nice touch. It's as clean as a whistle on a freight train.


88-93: Hot dang, this here code is tighter than a truck stop parking lot on a holiday weekend!

Snatchin' them joint names and callin' that fancy _align_joint_dims function is a real game-changer. It's gonna make handlin' them joint properties smoother than a freshly paved highway.

stac_mjx/controller.py Show resolved Hide resolved
Copy link
Contributor

@jf514 jf514 left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, LGTM

@charles-zhng charles-zhng merged commit 7fef98f into main Sep 11, 2024
5 checks passed
@charles-zhng charles-zhng deleted the ball-joints branch September 11, 2024 01:18
@coderabbitai coderabbitai bot mentioned this pull request Sep 20, 2024
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.

2 participants