## Set dynamic mass from C++ plugin

Typically: "How do I... ", "How can I... " questions
neostek
Posts: 21
Joined: 15 Feb 2013, 10:26

### Set dynamic mass from C++ plugin

Hello everyone,

I have a simple question: is there a way to set a dynamic mass in V-REP from a C++ plugin? I explain my problem better:

I want that, while the simulation in running, the mass of a respondable object changes over time (with a certain timing law I decide). I tried with

simSetShapeMassAndInertia(handle, mass, inertia, CoM, NULL);

taking handle, inertia, CoM from the simGetShapeMassAndInertia, so everything is consistent.

The problem is that the first function (the set one) gives me -1 as return value. I guess it is related to the fact that, switching instantaneously the mass might cause instability of the simulation. Is that correct or am I missing something? Is there another way to do that from a plugin?

Thank you for any suggestion,

Neostek

neostek
Posts: 21
Joined: 15 Feb 2013, 10:26

### Re: Set dynamic mass from C++ plugin

just for the community knowledge, I think I solve by setting:

simSetObjectFloatParameter(handle, 3005, mass);
simResetDynamicObject(handle);

I think that it is working also with
simSetShapeMassAndInertia(handle, mass, inertia, CoM, NULL);
simResetDynamicObject(handle);

but I have to test it. The problem was that I did not refresh the dynamic object. I hope this will help someone that falls in the same issue.

Best,

Neostek

coppelia
Posts: 7396
Joined: 14 Dec 2012, 00:25

### Re: Set dynamic mass from C++ plugin

Hello Neostek,

yes, you can do it like that, when running a quasi-static simulation. When your mass has a larger velocity, then resetting it will result in a strange behaviour, since the reset shape then instantly has zero velocity. Unless you give it an initial velocity with:

Code: Select all

simSetObjectFloatParameter(3000,shapeHandle,xVel)
simSetObjectFloatParameter(3001,shapeHandle,yVel)
simSetObjectFloatParameter(3002,shapeHandle,zVel)
Another option when increasing the mass, would be to attach an auxiliary mass via a force/torque sensor to the shape.

Cheers