Joint position setting via quaternions

Typically: "How do I... ", "How can I... " questions
Post Reply
TomDelaney
Posts: 22
Joined: 31 Jul 2022, 19:48

Joint position setting via quaternions

Post by TomDelaney »

Hi,

I was wondering if there was any way if I could set the target position of a given joint (revolute for example) by quaternions?

Thanks.

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

Re: Joint position setting via quaternions

Post by coppelia »

Hello,

if your joint is a spherical joint, then you can use sim.setObjectChildPose(jointHandle,pose), where pose={x,y,z,qx,qy,qz,qw} and the position component of the pose is ignored.
If your joint is revolute or prismatic, you'll have to use sim.setJointPosition(jointHandle,v) instead, where v is either the angle in radians, or the displacement in meters.

Above works for static joints. If you have a dynamic joint in position control mode, you'll have to use sim.setJointTargetPosition for revolute and prismatic joints instead. A dynamic, spherical joint can only be in passive mode and can't directly be actuated. In that case, you should either construct your joint out of 3 revolute joints (using auxiliary shapes in-between if not using the MuJoCo engine), or you can directly apply a torque to the attached shape via sim.addForceAndTorque.

Cheers

TomDelaney
Posts: 22
Joined: 31 Jul 2022, 19:48

Re: Joint position setting via quaternions

Post by TomDelaney »

Yes thank you, just to specify my problem. I have a spherical joint which is made up from 3 dynamically enabled revolute joints in position control mode with auxilary shapes between them and I was wondering if there was any way I could set their positions with the use of quaternions and the sim.SetJointTargetPosition , without having to convert them to Euler angles.

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

Re: Joint position setting via quaternions

Post by coppelia »

Then have a look at the demo scene scenes/eulerAngles.ttt and this page related to Euler angles, matrices and quaternions, and sim.buildPose.

Cheers

Post Reply