Hello,
I am setting the inertia matrix for my robot links using the sim.setShapeMassAndInertia command (I know that this command has been separated into two subcommands in newer versions). I gave as input my desired inertia tensor at the center of mass of my robot's link, the position of the center of mass which I also gave its relative inertia tensor as I mentioned, and also the transformation matrix. I sat my desired inertia and mass values for each link, and after I got the inertia and mass using the getShapeMassAndInertia function. The mass and the COM (center of mass) position values I got from the sim.getShapeMassAndInertia were OK. But the Inertia matrix that I got was different from what I sat for links.
Set I L21:
[[ 0.00336948 -0.00094914 -0.0004642 ]
[-0.00094914 0.0028031 0.00086039]
[-0.0004642 0.00086039 0.00380723]]
Ret I L21:
[[ 4.09732107e-03 -1.19415701e-04 -3.92175352e-05]
[-1.19415541e-04 4.14834451e-03 5.65062743e-04]
[-3.92173752e-05 5.65062743e-04 5.57780266e-03]]
Set I L21 is the Inertia values I sat for the link L21 and the Ret I L21 is the inertia values I got for the Inertia tensor. Why are these values different from each other?
please try to use the new API functions instead: sim.setShapeInertia, sim.getShapeInertia, sim.setShapeMass and sim.getShapeMass, since there is a reason why sim.setShapeMassAndInertia is deprecated.
please try to use the new API functions instead: sim.setShapeInertia, sim.getShapeInertia, sim.setShapeMass and sim.getShapeMass, since there is a reason why sim.setShapeMassAndInertia is deprecated.
Cheers
Hello again,
I used the functions you mentioned for setting inertia, but the problem remains, and the returned inertia matrix is different from what I expected. As the sim.getShapeInertia returns the inertia matrix with respect to the returned transformation matrix, I rotated the returned inertia to reorient it in my desired reference frame (COM frame) using \(R^T_{COM} I R_{COM}\), which should give me the inertia matrix I used to set for the link, but it did not! I have also checked all the rotation matrices in the simulation environment, and I am confident they are correct. I think Coppelia has some issues in setting inertia matrices for links. Please let me know if there is any way to resolve this problem. Thanks.
The inertias that sim.getObjectMatrix returns will always be diagonal (the additional transformation matrix that is returned will be adjusted appropriately so that a diagonal matrix is returned). You can visualize the matrices with [right popup on view --> View --> visualize inertias]. Following will not modify the inertia of the shape, and you'll see that I is always diagonal:
h=sim.getObjectHandle(sim.handle_self)
local I,M=sim.getShapeInertia(h)
print(I)
print(M)
sim.setShapeInertia(h,I,M)
The diagonal inertia that is returned is built on the relative reference frame M (M itself is relative to the shape's reference frame). So the diagonal inertia that is returned is built on the absolute reference frame absM=shapeM*M.
In order to set the inertia of the shape relative to the absolute reference frame, you would have to do:
h=sim.getObjectHandle(sim.handle_self)
local I={...} -- 3x3 Inertia matrix (does not need to be diagonal)
local absIM={...} -- the absolute frame relative to which I is expressed (and also the desired COM of the shape)
local shapeM=sim.getObjectMatrix(h,-1)
sim.invertMatrix(shapeM)
local M=sim.multiplyMatrices(shapeM,absIM)
sim.setShapeInertia(h,I,M)