Offset Center of Gravity on a parsed model?

asked 2016-06-09 11:02:36 -0500

peci1 gravatar image

updated 2016-06-09 11:07:21 -0500

Hello, I have a physics::Model (i.e. not just its SDF representation, but the parsed model). I want to offset the center of gravity of one of its links during runtime (and reset the world afterwards to run a simulation with a different CoG).

I've tried virtually anything, and without success. I start with *link->GetInertial() = original_inertial_with_shifted_cog, then I call link->UpdateMass(). All of this is called inside the Load method of a model plugin. The robot shows correctly in the first step of the paused simulation, but after stepping further, the whole body goes wrong, flies away, or the CoG "tries" to get to its original position (shifting the link to an incorrect position and leaving large joint positional errors).

I tried "repairing" the relative pose of the link, relative parent pose of its joints (this is protected, but nevermind), virtually anything (before the call to UpdateMass). Always the same behavior.

If I modify the <inertial><pose> tag in the SDF, the model loads correctly with the CoG shifted, and the simulation can be run normally. The problem is I don't want to reload (delete, spawn) the model every time I want to move the CoG.

It seems to me there is some "ghost force" acting on the link that pushes its CoG always to the same position.

Is there a way to achieve this at runtime?

Before the first step of the simulation (everything's like I'd want): image description

After a few simulation steps (the CoG moved to its original position, shifting the main body): image description

edit retag flag offensive close merge delete


did you try one of the Inertial::SetCoG calls?

hsu gravatar imagehsu ( 2016-06-09 12:17:16 -0500 )edit

Yes, I did... It triggers no other updates than setting the whole Inertia...

peci1 gravatar imagepeci1 ( 2016-06-10 04:04:43 -0500 )edit

I've also tried to replicate the way it is done in `InertiaMsgsTest::SetCoG()` test (via publishing a Model message), but the behavior is the same. Could it mean the test is insufficient?

peci1 gravatar imagepeci1 ( 2016-06-10 05:10:11 -0500 )edit

After some more digging, I concluded it is possibly a bug. I've reported it here: .

peci1 gravatar imagepeci1 ( 2016-06-10 09:56:15 -0500 )edit