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

Refactors pose and velocities to link frame and COM frame APIs #966

Merged
merged 50 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b0556db
transform rigid object and articualtion data root_state_w and body_st…
jtigue-bdai Sep 9, 2024
8599a6a
formatting
jtigue-bdai Sep 9, 2024
06d88b5
clean up acceleration code
jtigue-bdai Sep 9, 2024
7eec51e
formatting long lines
jtigue-bdai Sep 9, 2024
bec7031
fix shapes and pass rigidobject and articulation tests
jtigue-bdai Sep 9, 2024
1dfdc72
Merge branch 'main' into fix/root_state_w_vel_at_link
jtigue-bdai Sep 10, 2024
681d968
precommit
jtigue-bdai Sep 10, 2024
edc9929
consolidate generation and saving of com variables
jtigue-bdai Sep 12, 2024
8d71b6e
creat explicit link and com state properties and add no offset com test
jtigue-bdai Sep 20, 2024
3020d95
adding offest test wip
jtigue-bdai Sep 20, 2024
7c87035
add test for com offset from link
jtigue-bdai Sep 23, 2024
b6d7210
remove body_acc_link_w
jtigue-bdai Sep 24, 2024
7fd61fa
cleanup
jtigue-bdai Sep 24, 2024
c3bebd8
docstring cleanup
jtigue-bdai Sep 24, 2024
7902f1c
clean up rigid_object_data docstring
jtigue-bdai Sep 24, 2024
ece6e61
add rigid_object tests
jtigue-bdai Sep 24, 2024
e9ac3c7
add write_root_link_velocity and consolidate some tests
jtigue-bdai Sep 27, 2024
796effb
add seperate link and com writers and dep warnings for implicit methods
jtigue-bdai Oct 8, 2024
1244516
add explicit sub properties
jtigue-bdai Oct 8, 2024
8d8c82b
fix com_pos_b references
jtigue-bdai Oct 8, 2024
d93a307
change orientation of the com properties to principle axes of inertia
jtigue-bdai Oct 8, 2024
aa74715
fix root and body state properties tests for articulation
jtigue-bdai Oct 9, 2024
8d57d79
fix write_root_com_pose_to_sim
jtigue-bdai Oct 10, 2024
df7e8a6
add rigidobject tests and deprecation warnings
jtigue-bdai Oct 10, 2024
9f621e8
make new properties lazy buffers and clean up dep warning
jtigue-bdai Oct 10, 2024
ac0bbdd
format
jtigue-bdai Oct 10, 2024
490ce5b
change calls to deprecated properties to the appropriate link or com…
jtigue-bdai Oct 11, 2024
08c53e5
Merge branch 'main' into fix/root_state_w_vel_at_link
Dhoeller19 Oct 21, 2024
e7df6a4
Formatting
Dhoeller19 Oct 21, 2024
dd4d74b
Call kinematics update before accessing root_view
jtigue-bdai Oct 22, 2024
1b588e6
Merge branch 'main' into fix/root_state_w_vel_at_link
jtigue-bdai Oct 23, 2024
9c80ca9
formatting
jtigue-bdai Oct 11, 2024
c90778c
throttle deprecation warnings
jtigue-bdai Oct 25, 2024
31e0745
Merge branch 'main' into fix/root_state_w_vel_at_link
kellyguo11 Dec 8, 2024
0731418
add propery name changes to rigid object collection data
jtigue-bdai Dec 13, 2024
933de2d
add new object state writers for link and com
jtigue-bdai Dec 13, 2024
3ac79ca
add functioning and passing tests
jtigue-bdai Dec 13, 2024
f4417b9
add functioning uncomment other tests
jtigue-bdai Dec 13, 2024
2baa182
reduce reference to data.object_state in tests
jtigue-bdai Dec 13, 2024
ba6f16f
format
jtigue-bdai Dec 13, 2024
f359110
Merge branch 'main' into fix/root_state_w_vel_at_link
kellyguo11 Dec 15, 2024
3f16ec5
update pose/velocity APIs used in scripts/envs to new APIs
kellyguo11 Dec 15, 2024
340bf37
Merge branch 'fix/root_state_w_vel_at_link' of github.com:isaac-sim/I…
kellyguo11 Dec 15, 2024
604e4f6
update root_state_w when updating link_state and com_state
kellyguo11 Dec 15, 2024
b70d5ca
Merge branch 'main' of github.com:isaac-sim/IsaacLab into fix/root_st…
kellyguo11 Dec 15, 2024
33d8ce9
fix scripts
kellyguo11 Dec 15, 2024
88cd06e
Merge branch 'main' of github.com:isaac-sim/IsaacLab into fix/root_st…
kellyguo11 Dec 15, 2024
a9b194e
Merge branch 'fix/root_state_w_vel_at_link' of github.com:isaac-sim/I…
kellyguo11 Dec 15, 2024
887125f
don't compute full state for link pose and com vel
kellyguo11 Dec 15, 2024
9d8a721
format
kellyguo11 Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/tutorials/05_controllers/run_diff_ik.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ joint positions, current end-effector pose, and the Jacobian matrix.

While the attribute :attr:`assets.ArticulationData.joint_pos` provides the joint positions,
we only want the joint positions of the robot's arm, and not the gripper. Similarly, while
the attribute :attr:`assets.ArticulationData.body_state_w` provides the state of all the
the attribute :attr:`assets.ArticulationData.body_link_state_w` provides the state of all the
robot's bodies, we only want the state of the robot's end-effector. Thus, we need to
index into these arrays to obtain the desired quantities.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,66 @@ def write_root_state_to_sim(self, root_state: torch.Tensor, env_ids: Sequence[in
root_state: Root state in simulation frame. Shape is (len(env_ids), 13).
env_ids: Environment indices. If None, then all indices are used.
"""
# deprecation warning
carb.log_warn(
"DeprecationWarning: Articluation.write_root_state_to_sim will be removed in a future release. Please use"
" write_root_link_state_to_sim or write_root_com_state_to_sim instead."
)

# set into simulation
self.write_root_pose_to_sim(root_state[:, :7], env_ids=env_ids)
self.write_root_velocity_to_sim(root_state[:, 7:], env_ids=env_ids)

def write_root_com_state_to_sim(self, root_state: torch.Tensor, env_ids: Sequence[int] | None = None):
"""Set the root center of mass state over selected environment indices into the simulation.

The root state comprises of the cartesian position, quaternion orientation in (w, x, y, z), and linear
and angular velocity. All the quantities are in the simulation frame.

Args:
root_state: Root state in simulation frame. Shape is (len(env_ids), 13).
env_ids: Environment indices. If None, then all indices are used.
"""
# set into simulation
self.write_root_com_pose_to_sim(root_state[:, :7], env_ids=env_ids)
self.write_root_com_velocity_to_sim(root_state[:, 7:], env_ids=env_ids)

def write_root_link_state_to_sim(self, root_state: torch.Tensor, env_ids: Sequence[int] | None = None):
"""Set the root link state over selected environment indices into the simulation.

The root state comprises of the cartesian position, quaternion orientation in (w, x, y, z), and linear
and angular velocity. All the quantities are in the simulation frame.

Args:
root_state: Root state in simulation frame. Shape is (len(env_ids), 13).
env_ids: Environment indices. If None, then all indices are used.
"""
# set into simulation
self.write_root_link_pose_to_sim(root_state[:, :7], env_ids=env_ids)
self.write_root_link_velocity_to_sim(root_state[:, 7:], env_ids=env_ids)

def write_root_pose_to_sim(self, root_pose: torch.Tensor, env_ids: Sequence[int] | None = None):
"""Set the root pose over selected environment indices into the simulation.

The root pose comprises of the cartesian position and quaternion orientation in (w, x, y, z).

Args:
root_pose: Root poses in simulation frame. Shape is (len(env_ids), 7).
env_ids: Environment indices. If None, then all indices are used.
"""
# deprecation warning
carb.log_warn(
"DeprecationWarning: Articluation.write_root_pos_to_sim will be removed in a future release. Please use"
" write_root_link_pose_to_sim or write_root_com_pose_to_sim instead."
)

self.write_root_link_pose_to_sim(root_pose, env_ids)

def write_root_link_pose_to_sim(self, root_pose: torch.Tensor, env_ids: Sequence[int] | None = None):
"""Set the root link pose over selected environment indices into the simulation.

The root pose comprises of the cartesian position and quaternion orientation in (w, x, y, z).

Args:
root_pose: Root poses in simulation frame. Shape is (len(env_ids), 7).
env_ids: Environment indices. If None, then all indices are used.
Expand All @@ -300,33 +351,106 @@ def write_root_pose_to_sim(self, root_pose: torch.Tensor, env_ids: Sequence[int]
physx_env_ids = self._ALL_INDICES
# note: we need to do this here since tensors are not set into simulation until step.
# set into internal buffers
self._data.root_state_w[env_ids, :7] = root_pose.clone()
self._data.root_link_state_w[env_ids, :7] = root_pose.clone()
# convert root quaternion from wxyz to xyzw
root_poses_xyzw = self._data.root_state_w[:, :7].clone()
root_poses_xyzw = self._data.root_link_state_w[:, :7].clone()
root_poses_xyzw[:, 3:] = math_utils.convert_quat(root_poses_xyzw[:, 3:], to="xyzw")
# Need to invalidate the buffer to trigger the update with the new root pose.
self._data._body_state_w.timestamp = -1.0
# set into simulation
self.root_physx_view.set_root_transforms(root_poses_xyzw, indices=physx_env_ids)

def write_root_com_pose_to_sim(self, root_pose: torch.Tensor, env_ids: Sequence[int] | None = None):
"""Set the root center of mass pose over selected environment indices into the simulation.

The root pose comprises of the cartesian position and quaternion orientation in (w, x, y, z).
The orientation is the orientation of the principle axes of inertia.

Args:
root_pose: Root center of mass poses in simulation frame. Shape is (len(env_ids), 7).
env_ids: Environment indices. If None, then all indices are used.
"""
# resolve all indices
if env_ids is None:
local_env_ids = slice(None)

com_pos = self.data.com_pos_b[local_env_ids, 0, :]
com_quat = self.data.com_quat_b[local_env_ids, 0, :]

root_link_pos, root_link_quat = math_utils.combine_frame_transforms(
root_pose[..., :3],
root_pose[..., 3:7],
math_utils.quat_rotate(math_utils.quat_inv(com_quat), -com_pos),
math_utils.quat_inv(com_quat),
)

root_link_pose = torch.cat((root_link_pos, root_link_quat), dim=-1)
self.write_root_link_pose_to_sim(root_pose=root_link_pose, env_ids=env_ids)

def write_root_velocity_to_sim(self, root_velocity: torch.Tensor, env_ids: Sequence[int] | None = None):
jtigue-bdai marked this conversation as resolved.
Show resolved Hide resolved
"""Set the root velocity over selected environment indices into the simulation.
"""Set the root center of mass velocity over selected environment indices into the simulation.

The velocity comprises linear velocity (x, y, z) and angular velocity (x, y, z) in that order.
NOTE: This sets the velocity of the root's center of mass rather than the roots frame.

Args:
root_velocity: Root center of mass velocities in simulation world frame. Shape is (len(env_ids), 6).
env_ids: Environment indices. If None, then all indices are used.
"""
# deprecation warning
carb.log_warn(
"DeprecationWarning: Articluation.write_root_velocity_to_sim will be removed in a future release. Please"
" use write_root_link_velocity_to_sim or write_root_com_velocity_to_sim instead."
)

self.write_root_com_velocity_to_sim(root_velocity=root_velocity, env_ids=env_ids)

def write_root_com_velocity_to_sim(self, root_velocity: torch.Tensor, env_ids: Sequence[int] | None = None):
"""Set the root center of mass velocity over selected environment indices into the simulation.

The velocity comprises linear velocity (x, y, z) and angular velocity (x, y, z) in that order.
NOTE: This sets the velocity of the root's center of mass rather than the roots frame.

Args:
root_velocity: Root velocities in simulation frame. Shape is (len(env_ids), 6).
root_velocity: Root center of mass velocities in simulation world frame. Shape is (len(env_ids), 6).
env_ids: Environment indices. If None, then all indices are used.
"""

# resolve all indices
physx_env_ids = env_ids
if env_ids is None:
env_ids = slice(None)
physx_env_ids = self._ALL_INDICES
# note: we need to do this here since tensors are not set into simulation until step.
# set into internal buffers
self._data.root_state_w[env_ids, 7:] = root_velocity.clone()
self._data.root_com_state_w[env_ids, 7:] = root_velocity.clone()
self._data.body_acc_w[env_ids] = 0.0
# set into simulation
self.root_physx_view.set_root_velocities(self._data.root_state_w[:, 7:], indices=physx_env_ids)
self.root_physx_view.set_root_velocities(self._data.root_com_state_w[:, 7:], indices=physx_env_ids)

def write_root_link_velocity_to_sim(self, root_velocity: torch.Tensor, env_ids: Sequence[int] | None = None):
"""Set the root link velocity over selected environment indices into the simulation.

The velocity comprises linear velocity (x, y, z) and angular velocity (x, y, z) in that order.
NOTE: This sets the velocity of the root's frame rather than the roots center of mass.

Args:
root_velocity: Root frame velocities in simulation world frame. Shape is (len(env_ids), 6).
env_ids: Environment indices. If None, then all indices are used.
"""
# resolve all indices
if env_ids is None:
local_env_ids = slice(None)

root_com_velocity = root_velocity.clone()
quat = self.data.root_link_state_w[local_env_ids, 3:7]
com_pos_b = self.data.com_pos_b[local_env_ids, 0, :]
# transform given velocity to center of mass
root_com_velocity[:, :3] += torch.linalg.cross(
root_com_velocity[:, 3:], math_utils.quat_rotate(quat, com_pos_b), dim=-1
)
# write center of mass velocity to sim
self.write_root_com_velocity_to_sim(root_velocity=root_com_velocity, env_ids=env_ids)

def write_joint_state_to_sim(
self,
Expand Down
Loading
Loading