Rigid body dynamic properties

Typically: "How do I... ", "How can I... " questions
Post Reply
Ark27
Posts: 9
Joined: 07 Jun 2020, 12:19

Rigid body dynamic properties

Post by Ark27 »

Hi,

I am trying to simulate pick and place with two different objects (a cube) imported into coppelia sim differently.
a. Manual Import
b. Using API sim.importShape()

In case of option a, I am setting the Rigid body dynamic properties in the scene where the body is set to be respondable and the properties below are
Local respondable mask - > [x] [x] [x] [x] [] [] [] []
Global respondable mask -> [x] [x] [x] [x] [x] [x] [x] [x]

In case of option b, Imported using the API, I used the following lines of code,

Code: Select all

importObject = sim.importShape(0,"location",32,0,0.001)
objectRespondable = sim.convexDecompose(importObject,8,{1,2000,200,4,0,100000,20,4,4,200},{0.1,30,0.25,0.0,0.0,0.0,0.0,0.0,0.0,0.0})
sim.setObjectInt32Param(objectRespondable,3004,1) 
sim.setObjectFloatParam(objectRespondable,3005,objectMass)
sim.setObjectInt32Param (objectRespondable,3019,65520)
sim.setObjectInt32Param(objectRespondable,3003,0) 
sim.setObjectInt32Param(objectRespondable,10,256) 
sim.setObjectParent(importObject, objectRespondable, true)
sim.resetDynamicObject(objectRespondable)
In this case, the Rigid body dynamic properties in the scene are Body is Respondable
Local respondable mask - > [] [] [] [] [x] [x] [x] [x]
Global respondable mask -> [x] [x] [x] [x] [x] [x] [x] [x]

1. My question is how to make the set the local respondable mask in the case of 2, as same as case 1.
Does this any way affect the pick and place? (I read the documentation, however, if I'd really appreciate if you can give me a simpler explanation if possible please? )

2. Should this be called before or after setting/changing the physics properties via API?

Code: Select all

sim.resetDynamicObject(objectRespondable)



3. Final question. I have to set Principal Moments of inertia / mass properties via API. At the moment, I am successfully able to send the values from my external script to Coppelia sim. I divide the Principal Moments of inertia with the mass of the object before sending to coppeliasim.

Code: Select all

PInertiaX = 6.2768122006673e-05
PInertiaY = 6.3094194047153e-05
PInertiaZ = 6.2768122006673e-05
[sandboxScript:info] Simulation suspended.
[sandboxScript:info] Simulation resumed.
[sandboxScript:info] simulation stopping...
[sandboxScript:info] Simulation stopped.
By using this as reference https://forum.coppeliarobotics.com/view ... tia#p36278, I tried to set the Principal Moments of inertia / mass properties. Please find the code from my script below (same to the object mentioned in question 1).

Code: Select all

local transf=sim.getObjectMatrix(objectRespondable,-1)
local mass=objectMass
sim.setShapeInertia(objectRespondable,{inertialPropertyX, 0, 0, 0, inertialPropertyY, 0, 0, 0, inertialPropertyZ},transf)
My question the values, printed are different to those seen in the GUI. Can you tell how to set the values please?

Thanks for you time in Advance

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: Rigid body dynamic properties

Post by coppelia »

Hello,

for 1., use:

Code: Select all

sim.setObjectInt32Param(shapeHandle,sim.shapeintparam_respondable_mask,0xff0f)
2. yes, but If your code runs non-threaded, you won't even need to call sim.resetDynamicObject, if you import the mesh and prepare it in one shot. If on the other hand your code runs threaded, make sure you do everything at once, without being interrupted. You can do this with:

local l=sim.setThreadAutomaticSwitch(false)

-- import and prepare your shape here

sim.setThreadAutomaticSwitch(l)

So technically, you don't need sim.resetDynamicObject in both cases

3. You are taking transf from your imported shape: that represents the transformation of the shape's frame, which is kind of random (well, it is always at the geometric center of the shape, and the orientation is selected to be the one that minimizes the bounding box's volume).

You'd rather need something like:

Code: Select all

local inertiaLocalTransf=...
local mass=objectMass
sim.setShapeInertia(objectRespondable,{inertialPropertyX, 0, 0, 0, inertialPropertyY, 0, 0, 0, inertialPropertyZ},inertiaLocalTransf)
Where you will have to decide what the inertia's local transformation is. i.e. the transformation of the inertia relative to the shape's frame. If you do not have the inertia's local transformation, but only its absolute transformation (which is my guess), then you can obtain it with:

Code: Select all

local inertiaAbsTransf=...
local shapeTransfInv=sim.getObjectMatrix(objectRespondable,sim.handle_inverse)
local inertiaLocalTransf=sim.multiplyMatrices(shapeTransfInv,inertiaAbsTransf)
Cheers

Ark27
Posts: 9
Joined: 07 Jun 2020, 12:19

Re: Rigid body dynamic properties

Post by Ark27 »

Perfect, thanks for your reply.


For point 3, I got the following error when tried.

Code: Select all

67: cannot use '...' outside a vararg function near '...'
Therefore, I replaced from

Code: Select all

local inertiaAbsTransf=...
with

Code: Select all

local inertiaAbsTransf={1,0,0,0,1,0,0,0,1}
. Is this correct? I did not see an error, however, would like to check?

Also, after the changes I made above, I got the following error.
68: One of the function's argument type is not correct. (in function 'sim.getObjectMatrix')
stack traceback:
[C]: in function 'sim.getObjectMatrix'
[string "CodeDummy@childScript"]:68: in function <[string "CodeDummy@childScript"]:28>
[CoppeliaSim:error] External call to simCallScriptFunction failed (importObject@CodeDummy): Error in script function.
Like 68 is the following:

Code: Select all

shapeTransfInv=sim.getObjectMatrix(objectRespondable,sim.handle_inverse)
.

Could you kindly help me with fixing this error please? I am using CoppeliaSim 4.2 at the moment.

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: Rigid body dynamic properties

Post by coppelia »

The three dots (...) are meant for you to replace with the actual desired absolute position and orientation of your inertia frame. If your inertia frame is located at the origin, then use the identity matrix {1,0,0,0,0,1,0,0,0,0,1,0}.

if

Code: Select all

shapeTransfInv=sim.getObjectMatrix(objectRespondable,sim.handle_inverse)
generates an error, this is probably because you are not using the latest CoppeliaSim version. Then try with following instead:

Code: Select all

local inertiaAbsTransf=...
local shapeTransfInv=sim.getObjectMatrix(objectRespondable,-1)
sim.invertMatrix(shapeTransfInv)
local inertiaLocalTransf=sim.multiplyMatrices(shapeTransfInv,inertiaAbsTransf)
Cheers

Ark27
Posts: 9
Joined: 07 Jun 2020, 12:19

Re: Rigid body dynamic properties

Post by Ark27 »

Perfect, thanks!!

I was able to successfully import the object and check the Principal moments of inertia value in the rigid body dynamic properties box.

In my scenario, I use an object whose weight is very less approx. 0.019 Kg and it Principal Moments are
I1 = 1.193 Kg mm^2, I2 = 1.199 Kg mm^2, I3 = 1.193 Kg mm^2 for the pick and place task. These values are converted to Kg m^2 before sending to CoppeliaSim from my external python script.

However, in the simulation, I notice the object flies away. On looking at various other or similar issues, I came across this particular topic Design consideration 8 here https://www.coppeliarobotics.com/helpFi ... ations.htm .


As a debugging step, I had an object which i had manually imported into the scene previously. For that object, I changed the weight and the principal moment values from its original to the values above and started the simulation to notice if it is thrown away from the table. (The objects are present on a table). In this case, the object seemed to stay where it is.

I use Vortex physics engine and custom simulation settings.
With the object mass and dynamic properties configured, could help me what are the other settings that I should look at to make sure the object does not fly away in the simulation. Is there something I am missing ?

Really appreciate for your time and thanks again

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: Rigid body dynamic properties

Post by coppelia »

Keep in mind that in CoppeliaSim, the inertia is always expressed as the mass-less diagonal inertia, i.e. the diagonal inertia divided by the mass of the body.

Vortex and Newton are pretty robust and allow realistic inertia and masses for your simulation. So things should not fly away. There are probably items colliding with each other? Try turning contact display on and see what is happening.

On another note, we will soon release CoppeliaSim V4.4, which will include the Mujoco engine, which has very good overall characteristics.

Cheers

Post Reply