Skip to content

[BUG] Shape com ignores shape orientation #648

@JonathanKuelz

Description

@JonathanKuelz

Bug Description

When adding shapes to a body in warp.sim, their inertial attributes are automatically computed here. To my understanding, the computation of center of mass and inertia tensor happens in the local shape coordinate frame.

Next, the shape is added to the body, and its inertial contributions are updated. This update function ignores the orientation of the shape (the quaternion part of shape_transform) when updating the body center of mass. I believe this is a bug.

Minimal Code to demonstrate this:

import numpy as np
import trimesh
import warp as wp
import warp.sim


tm = trimesh.creation.uv_sphere(.5)

builder = wp.sim.ModelBuilder()
b = builder.add_body()
builder.add_shape_mesh(b, pos=wp.vec3(0., 0., 0.), rot=wp.quat_from_axis_angle(wp.vec3(0., 0., 1.), wp.pi),
                          mesh=wp.sim.Mesh(vertices=(tm.vertices + np.array([1., 0., 0.])).tolist(),
                                           indices=tm.faces.tolist()))
model = builder.finalize()
print(model.body_com)

Prints [[ 1.0000000e+00 8.6194635e-18 -5.8890343e-17]]. I would have expected the center of mass of the body to be in the negative x direction though.

System Information

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions