mink - MuJoCo Inverse Kinematics

1.1.0 · active · verified Thu Apr 16

mink is a Python library for inverse kinematics (IK) based on MuJoCo, designed for robotics applications. It provides a flexible framework for defining kinematic tasks, joint limits, and collision avoidance, then solving for joint configurations. Currently at version 1.1.0, mink maintains an active development pace with recent releases focusing on performance improvements and stability.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a minimal MuJoCo model, define a `Configuration` object, create a `KinematicTask` to reach a target position for a specified body, and use `solve_ik` to find the joint angles. It then updates the MuJoCo data and prints the resulting end-effector position.

import mujoco
from mink import Configuration, KinematicTask, solve_ik
import numpy as np

# Create a very simple MuJoCo model for demonstration
model_xml = """
<mujoco>
  <worldbody>
    <body name="link0" pos="0 0 0.1">
      <joint name="joint0" type="hinge" axis="0 0 1" pos="0 0 0" />
      <geom type="capsule" size="0.05 0.1" fromto="0 0 0 0 0 0.1" />
      <body name="link1" pos="0 0 0.1">
        <joint name="joint1" type="hinge" axis="0 1 0" pos="0 0 0" />
        <geom type="capsule" size="0.05 0.1" fromto="0 0 0 0 0 0.1" />
        <body name="tip" pos="0 0 0.1">
            <geom type="sphere" size="0.02" rgba="1 0 0 1"/>
        </body>
      </body>
    </body>
  </worldbody>
</mujoco>
"""
model = mujoco.MjModel.from_xml_string(model_xml)
data = mujoco.MjData(model)

# Instantiate the configuration wrapper
config = Configuration(model, data)

# Define a kinematic task to reach a target position for the 'tip' body
target_position = np.array([0.0, 0.1, 0.3]) # Target in world coordinates

tasks = [
    KinematicTask(
        config=config,
        body="tip", # Target the 'tip' body defined in the XML
        target_pos=target_position,
        weight=1.0,
    )
]

# Solve Inverse Kinematics
q_sol, sol = solve_ik(tasks, config)

print(f"IK Solution (joint angles): {q_sol}")

# Update MuJoCo data with the solution to get the final tip position
config.set_joint_positions(q_sol)
mujoco.mj_fwdKin(model, data)
print(f"Final end-effector position: {config.get_body_position('tip')}")

view raw JSON →