Numerical Inverse Kinematics based on JAX + MJX
Project description
MJINX
Mjinx is a library for auto-differentiable numerical inverse kinematics, powered by JAX and Mujoco MJX. The library was heavily inspired by the similar Pinocchio-based tool pink and Mujoco-based analogue mink.
Key features
- Flexibility. Each control problem is assembled via
Components, which enforce desired behaviour or keeps system in a safety set. - Different solution approaches.
JAX(i.e. it's efficient sampling and autodifferentiation) allows to implement variety of solvers, which might be more beneficial in different scenarios. - Fully Jax-compatible. Both optimal control problem and its solver are jax-compatible: jit-compilation and automatic vectorization are available for the whole problem.
- Convinience. The functionality is nicely wrapped to make the interaction with it easier.
Installation
The package is available in PyPI registry, and could be installed via pip:
pip install mjinx
Different installation versions:
- Visualization tool
mjinx.visualization.BatchVisualizeris available inmjinx[visual] - To run examples, install
mjinx[examples] - To install development version, install
mjinx[dev](preferably in editable mode) - To build docs, install
mjinx[docs] - To install the repository with all dependencies, install
mjinx[all]
Usage
Here is the example of mjinx usage:
from mujoco import mjx mjx
from mjinx.problem import Problem
# Initialize the robot model using MuJoCo
MJCF_PATH = "path_to_mjcf.xml"
mj_model = mj.MjModel.from_xml_path(MJCF_PATH)
mjx_model = mjx.put_model(mj_model)
# Create instance of the problem
problem = Problem(mjx_model)
# Add tasks to track desired behavior
frame_task = FrameTask("ee_task", cost=1, gain=20, body_name="link7")
problem.add_component(frame_task)
# Add barriers to keep robot in a safety set
joints_barrier = JointBarrier("jnt_range", gain=10)
problem.add_component(joints_barrier)
# Initialize the solver
solver = LocalIKSolver(mjx_model)
# Initializing initial condition
q0 = np.zeros(7)
# Initialize solver data
solver_data = solver.init()
# jit-compiling solve and integrate
solve_jit = jax.jit(solver.solve)
integrate_jit = jax.jit(integrate, static_argnames=["dt"])
# === Control loop ===
for t in np.arange(0, 5, 1e-2):
# Changing problem and compiling it
frame_task.target_frame = np.array([0.1 * np.sin(t), 0.1 * np.cos(t), 0.1, 1, 0, 0,])
problem_data = problem.compile()
# Solving the instance of the problem
opt_solution, solver_data = solve_jit(q, solver_data, problem_data)
# Integrating
q = integrate_jit(
mjx_model,
q,
opt_solution.v_opt,
dt,
)
Examples
The list of examples includes:
Kuka iiwalocal inverse kinematics (single item, vmap over desired trajectory)Kuka iiwaglobal inverse kinematics (single item, vmap over desired trajectory)Go2batched squats example
Note: The Global IK functionality is currently under development and not yet working properly as expected. It needs proper tuning and will be fixed in future updates. Use the Global IK examples with caution and expect suboptimal results.
Contributing
We are always open for the suggestions and contributions. For contribution guidelines, see the CONTRIBUTING.md file.
Acknowledgement
First of all, I would like to thank Simeon Nedelchev for his guidance and contributions during the development. Without his expertise and help, the repository would not exist.
The repository was highly inspired by pink and mink. Both authors, Stéphane Caron and Kevin Zakka, deeply inspire me to study robotics and contribute to the open source. Without them, this repository would not exist.
Some utility functions in this code are taken from source code of MuJoCo MJX. Apart from being a wonderful tool for batched computations and ML, the source code is compact yet readable and informative, and I encourage everyone to take a look at it to learn a little bit more about physical simulations, jax, and MuJoCo in general.
Finally, I would like to thank IRIS lab.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mjinx-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mjinx-0.1.1-py3-none-any.whl
- Upload date:
- Size: 50.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
547f0fb481eb42a68410b276b30444974eab5621dec046d564b639454d03024d
|
|
| MD5 |
93211fa2ed195c65c3317b55bf752326
|
|
| BLAKE2b-256 |
94cc7f51279bef8b3f9517543f7f3d498a3bfe8b0d9813ef7d9289e2566808fc
|
Provenance
The following attestation bundles were made for mjinx-0.1.1-py3-none-any.whl:
Publisher:
build.yml on based-robotics/mjinx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mjinx-0.1.1-py3-none-any.whl -
Subject digest:
547f0fb481eb42a68410b276b30444974eab5621dec046d564b639454d03024d - Sigstore transparency entry: 175732389
- Sigstore integration time:
-
Permalink:
based-robotics/mjinx@f4732c6a82f50c76fb2c2bd2a4987037f1c49319 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/based-robotics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@f4732c6a82f50c76fb2c2bd2a4987037f1c49319 -
Trigger Event:
push
-
Statement type: