-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Separates setters inside Articulation for joint position and velocity #1751
Open
Mayankm96
wants to merge
2
commits into
main
Choose a base branch
from
feature/sep-joint-pos-vel-setters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+59
−4
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -482,6 +482,23 @@ def write_joint_state_to_sim( | |||||
joint_ids: The joint indices to set the targets for. Defaults to None (all joints). | ||||||
env_ids: The environment indices to set the targets for. Defaults to None (all environments). | ||||||
""" | ||||||
# set into simulation | ||||||
self.write_joint_position_to_sim(position, joint_ids=joint_ids, env_ids=env_ids) | ||||||
self.write_joint_velocity_to_sim(velocity, joint_ids=joint_ids, env_ids=env_ids) | ||||||
|
||||||
def write_joint_position_to_sim( | ||||||
self, | ||||||
position: torch.Tensor, | ||||||
joint_ids: Sequence[int] | slice | None = None, | ||||||
env_ids: Sequence[int] | slice | None = None, | ||||||
): | ||||||
"""Write joint positions to the simulation. | ||||||
|
||||||
Args: | ||||||
position: Joint positions. Shape is (len(env_ids), len(joint_ids)). | ||||||
joint_ids: The joint indices to set the targets for. Defaults to None (all joints). | ||||||
env_ids: The environment indices to set the targets for. Defaults to None (all environments). | ||||||
""" | ||||||
# resolve indices | ||||||
physx_env_ids = env_ids | ||||||
if env_ids is None: | ||||||
|
@@ -494,15 +511,41 @@ def write_joint_state_to_sim( | |||||
env_ids = env_ids[:, None] | ||||||
# set into internal buffers | ||||||
self._data.joint_pos[env_ids, joint_ids] = position | ||||||
self._data.joint_vel[env_ids, joint_ids] = velocity | ||||||
self._data._previous_joint_vel[env_ids, joint_ids] = velocity | ||||||
self._data.joint_acc[env_ids, joint_ids] = 0.0 | ||||||
# Need to invalidate the buffer to trigger the update with the new root pose. | ||||||
self._data._body_state_w.timestamp = -1.0 | ||||||
# self._data._body_link_state_w.timestamp = -1.0 | ||||||
# self._data._body_com_state_w.timestamp = -1.0 | ||||||
# set into simulation | ||||||
self.root_physx_view.set_dof_positions(self._data.joint_pos, indices=physx_env_ids) | ||||||
|
||||||
def write_joint_velocity_to_sim( | ||||||
self, | ||||||
velocity: torch.Tensor, | ||||||
joint_ids: Sequence[int] | slice | None = None, | ||||||
env_ids: Sequence[int] | slice | None = None, | ||||||
): | ||||||
"""Write joint velocities to the simulation. | ||||||
|
||||||
Args: | ||||||
velocity: Joint velocities. Shape is (len(env_ids), len(joint_ids)). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Velocities are rad/s for revolute and m/s for prismatic? |
||||||
joint_ids: The joint indices to set the targets for. Defaults to None (all joints). | ||||||
env_ids: The environment indices to set the targets for. Defaults to None (all environments). | ||||||
""" | ||||||
# resolve indices | ||||||
physx_env_ids = env_ids | ||||||
if env_ids is None: | ||||||
env_ids = slice(None) | ||||||
physx_env_ids = self._ALL_INDICES | ||||||
if joint_ids is None: | ||||||
joint_ids = slice(None) | ||||||
# broadcast env_ids if needed to allow double indexing | ||||||
if env_ids != slice(None) and joint_ids != slice(None): | ||||||
env_ids = env_ids[:, None] | ||||||
# set into internal buffers | ||||||
self._data.joint_vel[env_ids, joint_ids] = velocity | ||||||
self._data._previous_joint_vel[env_ids, joint_ids] = velocity | ||||||
self._data.joint_acc[env_ids, joint_ids] = 0.0 | ||||||
# set into simulation | ||||||
self.root_physx_view.set_dof_velocities(self._data.joint_vel, indices=physx_env_ids) | ||||||
|
||||||
def write_joint_stiffness_to_sim( | ||||||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.