Varying the center of mass of an object

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
alina
Posts: 1
Joined: Wed Nov 14, 2018 10:35 pm

Varying the center of mass of an object

Post by alina »

Hi everyone,

I'm trying to set up a simulation of a planar pusher-slider system for data-collection. For this I want to reuse a couple of different object shapes (given by meshes) and vary their centre of mass between different trials: Think of boxes filled with different content: this alters the mass distribution without changing the shape.

I've seen this post which is somewhat related, but as it is almost 10 years old I'm not sure if it is still valid in the current version.

What I've tried so far is to create a multiBody and offset the collisionFramePosition and visualFramePosition to emulate a com that is not at the
center of the mesh. However, I'm not sure if that correctly alters the center of mass for simulation or if I just offset frame positions without physical meaning.

Is my approach correct?
And if not, is there an easy (procedural) way of achieving what I need?


Thanks a lot,
Alina
richardbloemenkamp
Posts: 14
Joined: Tue Sep 18, 2018 7:50 pm

Re: Varying the center of mass of an object

Post by richardbloemenkamp »

A not-so-elegant solution may be to add a fixed-linked cube to you mesh object and position it inside the mesh-object. You can then position it where you want the center of mass to be. Then you give almost all the mass to that little cube and reduce the mass of the mess-object. Your moments of inertia may be wrong then but if you are modeling boxes with objects then I think most other solutions also give the wrong moments of inertia.
However I suspect there are more elegant solutions to what you want.
Another issue, you may have, is to get a realistic surface sliding friction.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Varying the center of mass of an object

Post by Erwin Coumans »

alina wrote: Wed Nov 14, 2018 10:57 pm
What I've tried so far is to create a multiBody and offset the collisionFramePosition and visualFramePosition to emulate a com that is not at the
center of the mesh. However, I'm not sure if that correctly alters the center of mass for simulation or if I just offset frame positions without physical meaning.

Is my approach correct?
Yes, it is OK. In PyBullet, when loading a URDF file, you would modify the center of mass using the <inertia> tag.
is there an easy (procedural) way of achieving what I need?
Instead of loading a URDF from file, you can also use PyBullet.createMultibody.
Similar to URDF loading, you can either shift the collision and visual frame, or you shift the baseInertialFramePosition.

See https://github.com/erwincoumans/bullet3 ... rOfMass.py
Shifting the visual+collision meshes has the same effect on COM to shifting the inertia COM the opposite direction.

There is also some rudimentary UrdfEditor that may help, you can initializeFromBulletBody, saveUrdf and createMultibody.
python -m pybullet_utils.examples.combineUrdf
Alvin
Posts: 1
Joined: Mon Mar 23, 2020 2:15 pm

Re: Varying the center of mass of an object

Post by Alvin »

Hi,

I am running a simulation where a robot arm hits a cylinder. This cylinder is meant to represent a water bottle, so when I vary the amount of water in the bottle, the center of mass should also change. I am able to successfully change the center of mass, but the resulting simulation is definitely wrong (as shown in this video: https://drive.google.com/file/d/1OwCuck ... sp=sharing).

As you saw in the video, I've changed the center of mass to be the very top of the bottle. I'm sure I'm doing something wrong though since the bottle shouldn't be flipping so strangely to have this center of mass be at the bottom. I am happy to share all my code, but here are the main components that define this simulation:

[EDIT] I realize that center of mass will never actually be the top of the bottle, but the water bottle is just an example. I would like to extend this simulation to other objects that could theoretically have a very high center of mass.

Any help would be greatly appreciated!

Code: Select all

import pybullet as p

BOTTLE_H = 0.1905  # bottle height (m)
center_of_mass = [0, 0, 0.1905]

col_id = p.createCollisionShape(
        shapeType=p.GEOM_CYLINDER,
        radius=bottle.radius, 
        height=bottle.height)
        
bottle_id = p.createMultiBody(
                baseMass=bottle_mass,
                baseInertialFramePosition=center_of_mass,
                baseCollisionShapeIndex=col_id,
                basePosition=[0, 0, 0])

p.changeDynamics(
                bodyUniqueId=bottle_id, 
                linkIndex=-1,  # no links, -1 refers to bottle base
                lateralFriction=0.1)  # static sliding friction

Notice I don't touch rollingFriction or spinningFriction. Some strange behavior occurs when I play with these values.
Post Reply