getObjectOrientation of a joint

Typically: "How do I... ", "How can I... " questions
Post Reply
kercos
Posts: 11
Joined: 07 Jul 2022, 08:51

getObjectOrientation of a joint

Post by kercos »

Hi,

according to the documentation, sim.getObjectOrientation applied to a joint "returns the orientation relative to the joint's moving frame". However, if I invoke this function on a joint before/after changing the joint position (angle) it returns the same result. So it seems the function returns the orientation relative to the joint's base frame by default.

Code: Select all

> sim.getJointPosition(79)
0.000155210495
> sim.getObjectOrientation(79, sim.handle_world)
{-4.565654308e-05, 0.0006102334009, -4.285298928e-05}
> sim.setJointPosition(79, 1.5)
> sim.getJointPosition(79)
1.5
> sim.getObjectOrientation(79, sim.handle_world)
{-4.565654308e-05, 0.0006102334009, -4.285298928e-05}
In addition, using sim.handleflag_reljointbaseframe doesn't alter the result, confirming the base frame is already used by default:

Code: Select all

> sim.getObjectOrientation(79+sim.handleflag_reljointbaseframe, sim.handle_world)
{-4.565654308e-05, 0.0006102334009, -4.285298928e-05}
Last edited by kercos on 01 Aug 2022, 12:51, edited 1 time in total.

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

Re: getObjectOrientation of a joint

Post by coppelia »

hello,

consider following 2 cases:

Code: Select all

shape --> joint1
joint2 --> shape
calling sim.getObjectOrientation (or sim.getObjectPosition and similar) relative to the parent's frame, i.e. sim.getObjectOrientation(objHandle,sim.handle_parent), will return the orientation of the item relative to the parent's moving frame. In the first situation, the parent's moving frame is not existent (the shape doesn't have a moving frame). In the second situation, the parent's moving frame is the moving frame of joint2.

Above two cases can be discribed as:

Code: Select all

shape --> joint1FixedFrame --> joint1MovingFrame
joint2FixedFrame --> joint2MovingFrame --> shape
Getting the orientation/position of object1 relative to object2 will always get the orientation/position of the fixed frame of object1 relative to the moving frame of object2.

Cheers

fferri
Posts: 1193
Joined: 09 Sep 2013, 19:28

Re: getObjectOrientation of a joint

Post by fferri »

The documentation says that when the second argument (i.e.: relativeToObjectHandle) is a joint, then you can combine the first argument (i.e.: objectHandle) with sim.handleflag_reljointbaseframe.

Everything works as expected for me.

Setup:

Code: Select all

> j=sim.createJoint(sim.joint_revolute_subtype,sim.jointmode_kinematic,0)
> d=sim.createDummy(0.1)
> sim.setObjectParent(d,j)
Test:

Code: Select all

> sim.getObjectOrientation(d+sim.handleflag_reljointbaseframe,j)
{0, 0, 0}
> sim.setJointPosition(j,0.3)
1
> sim.getObjectOrientation(d+sim.handleflag_reljointbaseframe,j)
{0, 0, 0.3000000119}
> sim.getObjectOrientation(d,j) -- relative to moving frame of j
{0, 0, 0}

kercos
Posts: 11
Joined: 07 Jul 2022, 08:51

Re: getObjectOrientation of a joint

Post by kercos »

Thank you very much @fferri and @coppelia for the clarification.
I misunderstood the documentation, as I thought that the handle in question was the one of the first argument and not the second one.
Would there be a simple way to obtain the orientation of a joint moving frame wrt the world (without dummy elements)?
Thank you!

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

Re: getObjectOrientation of a joint

Post by coppelia »

yes, simply do following for the orientation of the moving frame of a joint, relative to the world:

Code: Select all

sim.getObjectOrientation(jointHandle,sim.handle_world)
and following for the orientation of the fixed frame of a joint, relative to the world:

Code: Select all

sim.getObjectOrientation(jointHandle+sim.handleflag_reljointbaseframe,sim.handle_world)
Cheers

kercos
Posts: 11
Joined: 07 Jul 2022, 08:51

Re: getObjectOrientation of a joint

Post by kercos »

Now I'm very confused because this is exactly what I tried to do and documented in the very first post of this thread.
There I tried to show that after changing the joint position (and therefore the moving frame of the joint), the orientation wouldn't change (with or without the sim.handleflag_reljointbaseframe flag).

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

Re: getObjectOrientation of a joint

Post by coppelia »

Did you try the suggestion of fferri? This works fine here too.

Cheers

kercos
Posts: 11
Joined: 07 Jul 2022, 08:51

Re: getObjectOrientation of a joint

Post by kercos »

I think @fferri suggestion describes how to get the orientation of a dummy node with respect to a joint base/moving frame. I'm looking for the way around, i.e., to get the orientation of the joint moving frame with respect to another object (or the world).

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

Re: getObjectOrientation of a joint

Post by coppelia »

Ah, ok, now I understand, please excuse the confusion. If you want to get the intrinsic position of an object, use sim.getObjectChildPose. This will return the transformation of the joint's moving frame relative to the joint's fixed frame. This also works for other objects, e.g. in a dynamic simulation, depending on the selected physics engine, other objects such as force/torque sensors can see an internal error, which can be measured with that function.
You can also use sim.getJointMatrix, that would do the same.

So in order to get the matrix of the moving frame of a joint, relative to the world, you would do:

Code: Select all

    local relMatrixOfMovingFrame=sim.getJointMatrix(jointHandle)
    local absMatrixOfFixedFrame=sim.getObjectMatrix(jointHandle,sim.handle_world)
    local absMatrixOfMovingFrame=sim.multiplyMatrices(absMatrixOfFixedFrame,relMatrixOfMovingFrame)
Cheers

Post Reply