Skip to content

Creating a custom MuJoCo plugin #2045

Discussion options

You must be logged in to vote

I assume you're using the feedforward term for gravcomp? In that case, I think you can achieve the functionality you want without a plugin, using a combination of motor actuators and qfrc_applied.

def gravcomp(
    model: mujoco.MjModel,
    data: mujoco.MjData,
    body_ids: np.ndarray,
) -> np.ndarray:
    """Compute force to counteract gravity for the given bodies."""
    jac = np.empty((3, model.nv))
    qfrc_gravcomp = np.zeros((model.nv))
    for i in body_ids:
        body_weight = model.opt.gravity * model.body(i).mass
        mujoco.mj_jac(model, data, jac, None, data.body(i).xipos, i)
        q_weight = jac.T @ body_weight
        qfrc_gravcomp -= q_weight
    return qfrc_gravcomp

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@gavin-hyl
Comment options

Answer selected by gavin-hyl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants