Replace one free joint with six scalar joints to use a joint equality constraint #2981
Replies: 3 comments
-
|
1 —Why the States Don’t Match It is not possible for a free joint and a chain of six scalar joints (3 slide + 3 hinge) to produce matching qpos, qvel, or qacc values for the rotational DoFs. A MuJoCo free joint represents orientation using a unit quaternion, while three hinge joints represent rotation using sequential Euler rotations. These two rotation representations are mathematically different, use different integration methods, and lead to different velocities and accelerations even if the initial states are identical. Translation can match, but rotation will always diverge. 2 — Why Replacing the Free Joint Doesn’t Work Replacing a free joint with six scalar joints creates a kinematically similar setup, but the dynamics and the state representation are not equivalent. Quaternion updates are smooth and globally minimal, while Euler hinge updates are sequential and axis-dependent. This causes divergence in rotation state, angular velocity, and angular acceleration immediately after stepping. Therefore, matching the free-joint state using scalar joints is not feasible. 3 — How to Correctly Couple Only the Z-Rotation There is no need to decompose a free joint into multiple scalar joints. MuJoCo already allows coupling or constraining only one rotational axis of a free joint using better tools than joint equality: Recommended methods: Weld equality with soft constraints Tendon-based equality Both approaches preserve the free joint (and its quaternion representation) without breaking the dynamics. 4 — Simpler Alternative (If Hard Constraint Not Required) If you only need the hinge joint to track the free joint’s z-rotation, you can extract the yaw angle from the free joint using: |
Beta Was this translation helpful? Give feedback.
-
|
Hello! Here is something:
Angular velocity and acceleration of a body attached with free joint is expressed in body-fixed frame. See issue 691 Editted your function (now your angular velocities match). You could do the same for acceleration. |
Beta Was this translation helpful? Give feedback.
-
Notes on replacing a free joint with six scalar joints in MuJoCo---------------------------------------------------------------1) A free joint uses a quaternion for rotation, while hinge joints usesequential Euler rotations. These two representations are notdynamically equivalent. Translation may match, but rotation (qpos,qvel, qacc) will not match. Divergence is expected.2) Angular velocity from a free joint is expressed in the body-fixedcoordinate frame. Using data.body(...).cvel mixes coordinate framesand will not match the free-joint angular velocity.3) To compare rotational velocities correctly, use mj_objectVelocitywith flg_local=1 so MuJoCo returns body-fixed velocities:import mujoco def get_qvel_single(model, data, body_name): 4) You can apply the same pattern with mj_objectAcceleration for matching qacc.5) Recommendation:Instead of decomposing a free joint into six scalar joints (which willnever match quaternion dynamics), use one of MuJoCo's built-inmechanisms to couple only the z-axis rotation of the free joint:- Weld equality (soft constraint via solref/solimp)- Tendon equality (build a tendon that measures yaw error)- Or extract yaw via mju_mat2Euler(...) and control a hinge jointto track that angle if a soft coupling is acceptable.Example: extracting yaw from the free joint orientationdef get_yaw(model, data, body_name): Summary:--------• Free joint (quaternion) and 6-joint Euler chain will not match.• Use mj_objectVelocity / mj_objectAcceleration for proper comparisons.• For coupling only yaw, prefer weld/tendon equality or yaw-tracking control. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Intro
Hi!
I am a PhD student at Bielefeld University, and I use MuJoCo for my research on Magnetic Robotics / magnetic levitation systems. In these systems, the so-called movers (moving permanent magnets) have six DoFs, and I represent one mover as a body with a free joint.
For my current project, I need to couple only the rotation around the z-axis of a mover with another hinge joint. I think the easiest way to do this is to use a joint equality constraint. However, this constraint can only be used with scalar joint types (slide and hinge) joints, and it is not possible to use it for a specific axis of a free joint. Therefore, I considered replacing the free joint with six scalar joints (3 slide joints, 3 hinge joints).
To ensure that I can replace the free joint with six scalar joints, I compared the qpos, qvel, and qacc of the bodies. All values for the translational axes are similar, but the values for the rotations diverge. I assume that the problem is related to how the rotation is internally represented and the order in which the rotation is performed for the scalar joints.
My setup
MuJoCo: 3.4.0 (Python API)
Python: 3.13.11
OS: Ubuntu 22.04.5 LTS
My question
Is it generally possible to obtain similar values for qpos, qvel, and qacc for one free joint and six scalar joints? If so, where is my mistake?
Is there a better way than using an equality constraint to couple only the rotation around the z-axis of a free joint with another hinge joint?
Many thanks in advance!
Minimal model and/or code that explain my question
Confirmations
Beta Was this translation helpful? Give feedback.
All reactions