MJJoint
-
class MJJoint : public MJObject<mjsJoint>
- #include <MJJoint.h>
Represents a MuJoCo joint.
Each joint owns its own
StateDatafor position and velocity (one or more, depending on joint type).Subclassed by MJBallJoint, MJFreeJoint, MJScalarJoint
Public Functions
-
inline MJJoint(mjsJoint *joint, MJBody &body)
Constructs an
MJJointwith a given joint and the body it’s attached to.- Parameters:
joint – Pointer to the MuJoCo joint.
body – Reference to the body the joint is associated with.
-
inline MJBody &getBody()
Retrieves the body that this joint is attached to.
- Returns:
Reference to the
MJScene.
-
void configure(const mjModel *m)
Configures the joint within a given MuJoCo model.
- Parameters:
m – Pointer to the MuJoCo model used for configuration.
-
inline size_t getQposAdr() const
Returns this joint’s address into
mjData::qpos.
-
inline size_t getQvelAdr() const
Returns this joint’s address into
mjData::qvel.
Protected Functions
-
void checkInitialized() const
Checks if the joint has been properly initialized.
Throws an exception if initialization has not been completed.
-
inline MJJoint(mjsJoint *joint, MJBody &body)
-
class MJScalarJoint : public MJJoint
- #include <MJJoint.h>
Represents a scalar joint in MuJoCo.
The
MJScalarJointclass provides additional functionality for single degree-of-freedom joints, both linear and angular. The position and velocity of this joint can be set.Owns a 1x1
StateDatafor position and a 1x1StateDatafor velocity.If
constrainedStateInMsgis linked, the value in this message will be read and applied to anMJSingleJointEqualitysuch that the joint is constrained to hold a specific state. This can be used to enforce joints to follow a specific path, while letting the MuJoCo engine figure out the necessary force/torque to produce this path.Public Functions
-
MJScalarJoint(mjsJoint *joint, MJBody &body)
Constructs an
MJScalarJointwith a given joint and body.- Parameters:
joint – Pointer to the MuJoCo joint.
body – Reference to the body the joint is associated with.
-
Eigen::Vector3d getAxis() const
Returns the axis of rotation for hinge joints and the direction of translation for slide joints.
Returned vector is normalized.
-
bool isHinge() const
Returns true if this is a rotational joint, false if it’s a translational slide joint.
-
void setPosition(double value)
Sets the position of the joint.
For revolute joints, this is the angle (in radians) of the joint with respect to its zero-pose.
For linear joints, this is the displacement (in meters) of the joint with respect to its zero-pose.
- Parameters:
value – The desired position value.
-
void setVelocity(double value)
Sets the velocity of the joint.
For revolute joints, this is the angular rate (in radians per second).
For linear joints, this is the displacement rate (in meters per second).
- Parameters:
value – The desired velocity value.
-
MJSingleJointEquality getConstrainedEquality()
Returns the equality constraint object associated with this scalar joint.
The returned MJSingleJointEquality can be used to enforce a specific state for the joint within the MuJoCo simulation. This is typically used when the joint is constrained to follow a particular position or velocity, as specified by an input message or control logic.
- Returns:
The MJSingleJointEquality object for this joint.
-
void configure(const mjModel *model)
Configures the scalar joint within the given MuJoCo model.
- Parameters:
model – Pointer to the MuJoCo model.
-
void updateConstrainedEquality()
Updates the constrained equality associated with the joint.
If
constrainedStateInMsgis connected, then activates the equality constraint of this joint and sets its ‘offset’ to the value in the message.
-
void writeJointStateMessage(uint64_t CurrentSimNanos)
Writes the joint state message based on the current simulation state.
- Parameters:
CurrentSimNanos – The current simulation time in nanoseconds.
Public Members
-
Message<ScalarJointStateMsgPayload> stateOutMsg
Message to output joint position state.
-
Message<ScalarJointStateMsgPayload> stateDotOutMsg
Message to output joint velocity state.
-
ReadFunctor<ScalarJointStateMsgPayload> constrainedStateInMsg
Functor to read constrained state input.
Protected Attributes
-
MJSingleJointEquality constrainedEquality
An equality used to enforce a specific state for the joint.
-
MJScalarJoint(mjsJoint *joint, MJBody &body)
-
class MJBallJoint : public MJJoint
- #include <MJJoint.h>
Represents a ball joint in MuJoCo.
The joint’s orientation quaternion and body angular velocity live in the scene’s bulk
qpos/qvelstates at this joint’s address. Not fully supported elsewhere yet.
-
class MJFreeJoint : public MJJoint
- #include <MJJoint.h>
Represents a free joint in MuJoCo.
The
MJFreeJointclass provides additional functionality for joints with three translational and three rotational degrees of freedom, including setting position, velocity, attitude, and attitude rate.The joint’s translation, orientation quaternion, translational velocity and body angular velocity all live in the scene’s bulk
qpos/qvelstates at this joint’s address.Public Functions
-
void setPosition(const Eigen::Vector3d &position)
Sets the position of the free joint.
- Parameters:
position – The desired 3D position vector with respect to the inertial frame.
-
void setVelocity(const Eigen::Vector3d &velocity)
Sets the translational velocity of the free joint.
- Parameters:
velocity – The desired 3D velocity vector with respect to the inertial frame.
-
void setAttitude(const Eigen::MRPd &attitude)
Sets the attitude (orientation) of the free joint.
- Parameters:
attitude – The orientation represented as Modified Rodrigues Parameters (MRP) with respect to the inertial frame.
-
void setAttitudeRate(const Eigen::Vector3d &attitudeRate)
Sets the attitude rate (angular velocity) of the free joint.
- Todo:
Verify if this matches the expected attitude rate conventions with Basilisk.
- Parameters:
attitudeRate – The desired 3D attitude rate vector with respect to the inertial frame.
-
Eigen::Vector3d getTranslationalVelocityFromData(const mjData *data) const
Reads the translational velocity directly from a MuJoCo data struct.
Operates on mjData rather than the Basilisk state, so it reflects the value currently visible to MuJoCo’s solver.
-
Eigen::Vector3d getTranslationalPositionFromData(const mjData *data) const
Reads the translational position directly from a MuJoCo data struct.
Operates on mjData rather than the Basilisk state, so it reflects the value currently visible to MuJoCo’s solver.
-
void setTranslationalVelocityInData(mjData *data, const Eigen::Vector3d &vel)
Writes a translational velocity directly into a MuJoCo data struct.
Operates on mjData rather than the Basilisk state. Used to temporarily reframe the scene at the origin before running MuJoCo’s dynamics, then restore the original value afterward.
-
void setTranslationalPositionInData(mjData *data, const Eigen::Vector3d &pos)
Writes a translational position directly into a MuJoCo data struct.
Operates on mjData rather than the Basilisk state. Used to temporarily reframe the scene at the origin before running MuJoCo’s dynamics, then restore the original value afterward.
-
void setPosition(const Eigen::Vector3d &position)