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 17 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
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,13 @@ def write_root_pose_to_sim(self, root_pose: torch.Tensor, env_ids: Sequence[int]
self.root_physx_view.set_root_transforms(root_poses_xyzw, indices=physx_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 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
Expand All @@ -326,6 +329,26 @@ def write_root_velocity_to_sim(self, root_velocity: torch.Tensor, env_ids: Seque
# set into simulation
self.root_physx_view.set_root_velocities(self._data.root_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.
"""
root_com_velocity = root_velocity.clone()
quat = self._data.root_state_w[env_ids, :7]
com_pos_b = self._data._com_pos_b[env_ids,:]
# transform given velocity to center of mass
root_com_velocity[:,:3] += torch.linalg.cross(
root_com_velocity[:, 10:13], math_utils.quat_rotate(quat, com_pos_b), dim=-1
)
# write center of mass velocity to sim
self.write_root_velocity_to_sim(root_velocity=root_com_velocity,env_ids=env_ids)

def write_joint_state_to_sim(
self,
position: torch.Tensor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def __init__(self, root_physx_view: physx.ArticulationView, device: str):
self._joint_acc = TimestampedBuffer()
self._joint_vel = TimestampedBuffer()

# Link center of mass
self._com_pos_b, _ = self._root_physx_view.get_coms().to(self.device).split([3, 4], dim=-1)
jtigue-bdai marked this conversation as resolved.
Show resolved Hide resolved

def update(self, dt: float):
# update the simulation timestamp
self._sim_timestamp += dt
Expand Down Expand Up @@ -256,8 +259,8 @@ def update(self, dt: float):
def root_state_w(self):
"""Root state ``[pos, quat, lin_vel, ang_vel]`` in simulation world frame. Shape is (num_instances, 13).

The position and quaternion are of the articulation root's actor frame. Meanwhile, the linear and angular
velocities are of the articulation root's center of mass frame.
The position and quaternion are of the articulation root's actor frame relative to the world. Meanwhile,
the linear and angular velocities are of the articulation root's center of mass frame.
"""
if self._root_state_w.timestamp < self._sim_timestamp:
# read data from simulation
Expand All @@ -269,6 +272,35 @@ def root_state_w(self):
self._root_state_w.timestamp = self._sim_timestamp
return self._root_state_w.data

@property
def root_state_link_w(self):
"""Root state ``[pos, quat, lin_vel, ang_vel]`` in simulation world frame. Shape is (num_instances, 13).

The position, quaternion, and linear/angular velocity are of the articulation root's actor frame relative to the
world.
"""
state = self.root_state_w.clone()
quat = state[:, 3:7]
# adjust linear velocity to link
state[:, 7:10] += torch.linalg.cross(
state[:, 10:13], math_utils.quat_rotate(quat, -self._com_pos_b[:, 0, :]), dim=-1
)
return state
jtigue-bdai marked this conversation as resolved.
Show resolved Hide resolved

@property
def root_state_com_w(self):
"""Root state ``[pos, quat, lin_vel, ang_vel]`` in simulation world frame. Shape is (num_instances, 13).

The position, quaternion, and linear/angular velocity are of the articulation root link's center of mass frame
relative to the world. Center of mass frame is assumed to be the same orientation as the link rather than the
orientation of the principle inertia.
"""
state = self.root_state_w.clone()
quat = state[:, 3:7]
# adjust position to center of mass
state[:, :3] += math_utils.quat_rotate(quat, self._com_pos_b[:, 0, :])
return state

@property
def body_state_w(self):
"""State of all bodies `[pos, quat, lin_vel, ang_vel]` in simulation world frame.
Expand All @@ -287,15 +319,46 @@ def body_state_w(self):
self._body_state_w.timestamp = self._sim_timestamp
return self._body_state_w.data

@property
def body_state_link_w(self):
"""State of all bodies `[pos, quat, lin_vel, ang_vel]` in simulation world frame.
Shape is (num_instances, num_bodies, 13).

The position, quaternion, and linear/angular velocity are of the body's link frame relative to the world.
"""
state = self.body_state_w.clone()
jtigue-bdai marked this conversation as resolved.
Show resolved Hide resolved
quat = state[..., 3:7]
# adjust linear velocity to link
state[..., 7:10] += torch.linalg.cross(
state[..., 10:13], math_utils.quat_rotate(quat, -self._com_pos_b), dim=-1
)
return state

@property
def body_state_com_w(self):
"""State of all bodies `[pos, quat, lin_vel, ang_vel]` in simulation world frame.
Shape is (num_instances, num_bodies, 13).

The position, quaternion, and linear/angular velocity are of the body's center of mass frame relative to the
world. Center of mass frame is assumed to be the same orientation as the link rather than the orientation of the
principle inertia.
"""
state = self.body_state_w.clone()
quat = state[..., 3:7]
# adjust position to center of mass
jtigue-bdai marked this conversation as resolved.
Show resolved Hide resolved
state[..., :3] -= math_utils.quat_rotate(quat, self._com_pos_b)
return state

@property
def body_acc_w(self):
"""Acceleration of all bodies. Shape is (num_instances, num_bodies, 6).
"""Acceleration of all bodies (center of mass). Shape is (num_instances, num_bodies, 6).

This quantity is the acceleration of the articulation links' center of mass frame.
All values are relative to the world.
"""
if self._body_acc_w.timestamp < self._sim_timestamp:
# read data from simulation and set the buffer data and timestamp
self._body_acc_w.data = self._root_physx_view.get_link_accelerations()

self._body_acc_w.timestamp = self._sim_timestamp
return self._body_acc_w.data

Expand Down Expand Up @@ -353,113 +416,114 @@ def joint_acc(self):
def root_pos_w(self) -> torch.Tensor:
"""Root position in simulation world frame. Shape is (num_instances, 3).

This quantity is the position of the actor frame of the articulation root.
This quantity is the position of the actor frame of the articulation root relative to the world.
"""
return self.root_state_w[:, :3]

@property
def root_quat_w(self) -> torch.Tensor:
"""Root orientation (w, x, y, z) in simulation world frame. Shape is (num_instances, 4).

This quantity is the orientation of the actor frame of the articulation root.
This quantity is the orientation of the actor frame of the articulation root relative to the world.
"""
return self.root_state_w[:, 3:7]

@property
def root_vel_w(self) -> torch.Tensor:
"""Root velocity in simulation world frame. Shape is (num_instances, 6).

This quantity contains the linear and angular velocities of the articulation root's center of
mass frame.
This quantity contains the linear and angular velocities of the articulation root's center of mass frame
relative to the world.
"""
return self.root_state_w[:, 7:13]

@property
def root_lin_vel_w(self) -> torch.Tensor:
"""Root linear velocity in simulation world frame. Shape is (num_instances, 3).

This quantity is the linear velocity of the articulation root's center of mass frame.
This quantity is the linear velocity of the articulation root's center of mass frame relative to the world.
"""
return self.root_state_w[:, 7:10]

@property
def root_ang_vel_w(self) -> torch.Tensor:
"""Root angular velocity in simulation world frame. Shape is (num_instances, 3).

This quantity is the angular velocity of the articulation root's center of mass frame.
This quantity is the angular velocity of the articulation root's center of mass frame relative to the world.
"""
return self.root_state_w[:, 10:13]

@property
def root_lin_vel_b(self) -> torch.Tensor:
"""Root linear velocity in base frame. Shape is (num_instances, 3).

This quantity is the linear velocity of the articulation root's center of mass frame with
respect to the articulation root's actor frame.
This quantity is the linear velocity of the articulation root's center of mass frame relative to the world
with respect to the articulation root's actor frame.
"""
return math_utils.quat_rotate_inverse(self.root_quat_w, self.root_lin_vel_w)

@property
def root_ang_vel_b(self) -> torch.Tensor:
"""Root angular velocity in base world frame. Shape is (num_instances, 3).

This quantity is the angular velocity of the articulation root's center of mass frame with respect to the
articulation root's actor frame.
This quantity is the angular velocity of the articulation root's center of mass frame relative to the world with
respect to the articulation root's actor frame.
"""
return math_utils.quat_rotate_inverse(self.root_quat_w, self.root_ang_vel_w)

@property
def body_pos_w(self) -> torch.Tensor:
"""Positions of all bodies in simulation world frame. Shape is (num_instances, num_bodies, 3).

This quantity is the position of the rigid bodies' actor frame.
This quantity is the position of the rigid bodies' actor frame relative to the world.
"""
return self.body_state_w[..., :3]

@property
def body_quat_w(self) -> torch.Tensor:
"""Orientation (w, x, y, z) of all bodies in simulation world frame. Shape is (num_instances, num_bodies, 4).

This quantity is the orientation of the rigid bodies' actor frame.
This quantity is the orientation of the rigid bodies' actor frame relative to the world.
"""
return self.body_state_w[..., 3:7]

@property
def body_vel_w(self) -> torch.Tensor:
"""Velocity of all bodies in simulation world frame. Shape is (num_instances, num_bodies, 6).

This quantity contains the linear and angular velocities of the rigid bodies' center of mass frame.
This quantity contains the linear and angular velocities of the rigid bodies' center of mass frame relative
to the world.
"""
return self.body_state_w[..., 7:13]

@property
def body_lin_vel_w(self) -> torch.Tensor:
"""Linear velocity of all bodies in simulation world frame. Shape is (num_instances, num_bodies, 3).

This quantity is the linear velocity of the rigid bodies' center of mass frame.
This quantity is the linear velocity of the rigid bodies' center of mass frame relative to the world.
"""
return self.body_state_w[..., 7:10]

@property
def body_ang_vel_w(self) -> torch.Tensor:
"""Angular velocity of all bodies in simulation world frame. Shape is (num_instances, num_bodies, 3).

This quantity is the angular velocity of the rigid bodies' center of mass frame.
This quantity is the angular velocity of the rigid bodies' center of mass frame relative to the world.
"""
return self.body_state_w[..., 10:13]

@property
def body_lin_acc_w(self) -> torch.Tensor:
"""Linear acceleration of all bodies in simulation world frame. Shape is (num_instances, num_bodies, 3).

This quantity is the linear acceleration of the rigid bodies' center of mass frame.
This quantity is the linear acceleration of the rigid bodies' center of mass frame relative to the world.
"""
return self.body_acc_w[..., 0:3]

@property
def body_ang_acc_w(self) -> torch.Tensor:
"""Angular acceleration of all bodies in simulation world frame. Shape is (num_instances, num_bodies, 3).

This quantity is the angular acceleration of the rigid bodies' center of mass frame.
This quantity is the angular acceleration of the rigid bodies' center of mass frame relative to the world.
"""
return self.body_acc_w[..., 3:6]
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def __init__(self, root_physx_view: physx.RigidBodyView, device: str):
self._root_state_w = TimestampedBuffer()
self._body_acc_w = TimestampedBuffer()

# Link center of mass
# com_pos_b, _ = self._root_physx_view.get_coms().to(self.device).split([3, 4], dim=-1)
self._com_pos_b, _ = self._root_physx_view.get_coms().to(self.device).split([3, 4], dim=-1)

def update(self, dt: float):
"""Updates the data for the rigid object.

Expand Down Expand Up @@ -117,6 +121,33 @@ def root_state_w(self):
self._root_state_w.timestamp = self._sim_timestamp
return self._root_state_w.data

@property
def root_state_link_w(self):
"""Root state ``[pos, quat, lin_vel, ang_vel]`` in simulation world frame. Shape is (num_instances, 13).

The position, quaternion, and linear/angular velocity are of the rigid body root frame relative to the
world.
"""
state = self.root_state_w.clone()
quat = state[:, 3:7]
# adjust linear velocity to link
state[:, 7:10] += torch.linalg.cross(state[:, 10:13], math_utils.quat_rotate(quat, -self._com_pos_b), dim=-1)
return state

@property
def root_state_com_w(self):
"""Root state ``[pos, quat, lin_vel, ang_vel]`` in simulation world frame. Shape is (num_instances, 13).

The position, quaternion, and linear/angular velocity are of the rigid body's center of mass frame
relative to the world. Center of mass frame is assumed to be the same orientation as the link rather than the
orientation of the principle inertia.
"""
state = self.root_state_w.clone()
quat = state[:, 3:7]
# adjust position to center of mass
state[:, :3] += math_utils.quat_rotate(quat, self._com_pos_b)
return state

@property
def body_state_w(self):
"""State of all bodies `[pos, quat, lin_vel, ang_vel]` in simulation world frame. Shape is (num_instances, 1, 13).
Expand All @@ -126,6 +157,26 @@ def body_state_w(self):
"""
return self.root_state_w.view(-1, 1, 13)

@property
def body_state_link_w(self):
"""State of all bodies `[pos, quat, lin_vel, ang_vel]` in simulation world frame.
Shape is (num_instances,1, 13).

The position, quaternion, and linear/angular velocity are of the body's link frame relative to the world.
"""
return self.root_state_link_w.view(-1, 1, 13)

@property
def body_state_com_w(self):
"""State of all bodies `[pos, quat, lin_vel, ang_vel]` in simulation world frame.
Shape is (num_instances, num_bodies, 13).

The position, quaternion, and linear/angular velocity are of the body's center of mass frame relative to the
world. Center of mass frame is assumed to be the same orientation as the link rather than the orientation of the
principle inertia.
"""
return self.root_state_com_w.view(-1, 1, 13)

@property
def body_acc_w(self):
"""Acceleration of all bodies. Shape is (num_instances, 1, 6).
Expand Down Expand Up @@ -186,7 +237,7 @@ def root_vel_w(self) -> torch.Tensor:
def root_lin_vel_w(self) -> torch.Tensor:
"""Root linear velocity in simulation world frame. Shape is (num_instances, 3).

This quantity is the linear velocity of the root rigid body's center of mass frame.
This quantity is the linear velocity of the root rigid body's center of mass frame relative to the world.
"""
return self.root_state_w[:, 7:10]

Expand Down
Loading
Loading