Metadata-Version: 2.4
Name: mplib2
Version: 0.3.1
Summary: A lightweight motion planning library (actively maintained fork of MPlib)
Author-email: Minghua Liu <minghua@ucsd.edu>, Jiayuan Gu <jigu@ucsd.edu>, Kolin Guo <ruguo@ucsd.edu>, Xinsong Lin <x8lin@ucsd.edu>
Maintainer-email: Albert Khalikov <al.ry.ri@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/dd114/MPlib2
Project-URL: Repository, https://github.com/dd114/MPlib2
Project-URL: Issues, https://github.com/dd114/MPlib2/issues
Project-URL: Upstream, https://github.com/haosulab/MPlib
Keywords: robotics,motion planning
Classifier: Operating System :: POSIX :: Linux
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Other Audience
Classifier: Intended Audience :: Science/Research
Classifier: Natural Language :: English
Classifier: Framework :: Robot Framework :: Tool
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Education
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.26
Requires-Dist: toppra>=0.6.3
Requires-Dist: transforms3d>=0.3.1
Dynamic: license-file

# MPlib2: a Lightweight Motion Planning Library

<p align="center">
  <img src="https://raw.githubusercontent.com/dd114/MPlib2/main/docs/demo.gif">
</p>

[![PyPI](https://img.shields.io/pypi/v/mplib2)](https://pypi.org/project/mplib2/)
[![GitHub Release](https://img.shields.io/github/v/release/dd114/MPlib2)](https://github.com/dd114/MPlib2/releases)
[![CI](https://github.com/dd114/MPlib2/actions/workflows/ci.yml/badge.svg)](https://github.com/dd114/MPlib2/actions/workflows/ci.yml)
[![Python](https://img.shields.io/pypi/pyversions/mplib2)](https://pypi.org/project/mplib2/)
[![License](https://img.shields.io/github/license/dd114/MPlib2)](https://github.com/dd114/MPlib2/blob/main/LICENSE)
[![Upstream MPlib](https://img.shields.io/badge/fork%20of-haosulab%2FMPlib-lightgrey)](https://github.com/haosulab/MPlib)

MPlib2 is an actively maintained standalone fork of [MPlib](https://github.com/haosulab/MPlib) — a lightweight Python motion planning library decoupled from ROS. It brings modern dependency compatibility (Python 3.10–3.14, NumPy 2, Pinocchio 3, Boost 1.88+, modern `pybind11`) and stability fixes while remaining a drop-in `import mplib` replacement for existing ManiSkill, SAPIEN, and MPlib codebases.

## MPlib vs MPlib2

| | Upstream `mplib` (`haosulab/MPlib`) | `mplib2` (`dd114/MPlib2`) |
|---|---|---|
| PyPI package / import | `mplib` / `import mplib` | `mplib2` / `import mplib` |
| Python & NumPy | Python >= 3.8, legacy NumPy 1.x wheels | Python >= 3.10, NumPy 1.26 & 2.x |
| C++ dependency stack | Pinocchio 2, older Boost / vendored `pybind11` | Pinocchio 3 (`>=3,<4`), Boost 1.88+, `pybind11 >= 2.13` |
| Prebuilt wheels | `manylinux2014` (`x86_64`) | `manylinux_2_28` (`x86_64`, CPython 3.10–3.14) |
| Notable fixes | — | Read-only `Pose.q`, base-pose `AttachedBody`, OMPL/planner/IK/FCL fixes, scaled SAPIEN meshes |

See [CHANGELOG.md](CHANGELOG.md) for the full list of behavior changes and fixes when migrating from upstream `mplib`.

## Installation

### Standard Pip Installation

The PyPI distribution name is `mplib2`, while the Python import module remains `mplib`:

```bash
pip install mplib2
```

**Supported platforms:** Prebuilt wheels are published for Linux `x86_64` (`manylinux_2_28`, Python 3.10–3.14). On other platforms or Python versions, build from source using the instructions below.

> **Note (migrating from upstream `mplib`)**: Because `mplib2` provides the `mplib` Python module as a drop-in replacement, it cannot coexist with upstream `mplib` in the same environment. Uninstall upstream `mplib` first to avoid package shadowing:
> ```bash
> pip uninstall -y mplib && pip install mplib2
> ```

### Building from Source & Editable Installation

#### Prerequisites

Building MPlib2 from source requires Python >= 3.10, a C++17 compiler (`g++` or `clang++`), CMake (>= 3.12), Ninja, `pybind11` (>= 2.13, required for NumPy 2 compatibility), and C++ dependency libraries:
- Eigen3 (>= 3.4.0)
- Pinocchio (>= 3.0, < 4.0)
- FCL / Coal
- OMPL (>= 1.5)
- Boost (>= 1.70: `filesystem`; `system` linked conditionally if present)
- Orocos-KDL
- URDFDOM
- Assimp

#### Option A: Managed Environment with Pixi (Recommended)

[Pixi](https://pixi.sh/) automatically installs required C++ libraries and Python toolchains (Python >= 3.10, < 3.15):

```bash
# Clone the repository
git clone https://github.com/dd114/MPlib2.git
cd MPlib2

# Install development environment and execute test suite
pixi run pytest tests
```

#### Option B: Editable Installation via Pip (Python 3.10–3.14)

Within an existing Conda or system environment providing the prerequisite C++ libraries:

```bash
# Install runtime Python dependencies
pip install "numpy>=1.26" "toppra>=0.6.3" "transforms3d>=0.3.1"

# Build C++ pybind11 extension in-place and install editable package
pip install -e . --no-build-isolation
```

## Quickstart

This self-contained snippet works out of the box after `pip install mplib2` using a minimal primitive-geometry 6-DoF arm URDF (no external mesh files required):

```python
import tempfile
from pathlib import Path
import numpy as np
import mplib

# Minimal 6-DoF arm URDF + adjacent-link SRDF (primitive geometries only)
axes = ["0 0 1", "0 1 0", "0 1 0", "1 0 0", "0 1 0", "1 0 0"]
origins = ["0 0 0.1", "0 0 0.2", "0 0 0.3", "0 0 0.25", "0 0 0.15", "0 0 0.1"]
links = ['<link name="base_link"/>']
joints, srdf_pairs = [], []
for i, (origin, axis) in enumerate(zip(origins, axes), start=1):
    parent = "base_link" if i == 1 else f"link_{i - 1}"
    child = f"link_{i}"
    links.append(
        f'<link name="{child}"><collision><origin xyz="0 0 0.05"/>'
        f'<geometry><cylinder radius="0.03" length="0.1"/></geometry></collision></link>'
    )
    joints.append(
        f'<joint name="joint_{i}" type="revolute">'
        f'<parent link="{parent}"/><child link="{child}"/>'
        f'<origin xyz="{origin}"/><axis xyz="{axis}"/>'
        f'<limit lower="-3.14" upper="3.14" effort="100" velocity="2"/></joint>'
    )
    srdf_pairs.append(
        f'<disable_collisions link1="{parent}" link2="{child}" reason="Adjacent"/>'
    )

with tempfile.TemporaryDirectory() as tmp:
    urdf, srdf = Path(tmp) / "arm.urdf", Path(tmp) / "arm.srdf"
    urdf.write_text('<robot name="arm">' + "".join(links + joints) + "</robot>")
    srdf.write_text('<robot name="arm">' + "".join(srdf_pairs) + "</robot>")

    planner = mplib.Planner(urdf=urdf, srdf=srdf, move_group="link_6")

    # Forward Kinematics: compute current end-effector pose
    start_qpos = np.array([0.0, 0.4, -0.8, 0.0, 0.5, 0.0])
    planner.robot.set_qpos(start_qpos, full=True)
    planner.pinocchio_model.compute_forward_kinematics(start_qpos)
    target_pose = planner.pinocchio_model.get_link_pose(planner.link_name_2_idx["link_6"])

    # Inverse Kinematics & Motion Planning
    target_pose.p[0] += 0.1  # Translate 10 cm in X
    status, ik_qpos = planner.IK(target_pose, start_qpos, return_closest=True)
    result = planner.plan_pose(target_pose, start_qpos)

    print(f"IK: {status}, Plan: {result['status']}")
    if result["status"] == "Success":
        print(f"Duration: {result['duration']:.2f} s, Waypoints: {len(result['position'])}")
```

### Example with a Full Robot Model (Franka Panda)

If you have cloned this repository (which includes the Franka Panda URDF, SRDF, and meshes under `data/panda/` — not bundled in the PyPI wheel), you can load it directly:

```python
import numpy as np
import mplib

# Initialize planner for Franka Emika Panda arm
planner = mplib.Planner(
    urdf="data/panda/panda.urdf",
    srdf="data/panda/panda.srdf",
    move_group="panda_hand",
)

# Set initial joint configuration (7 arm joints + 2 gripper fingers)
start_qpos = np.array([0.0, 0.2, 0.0, -2.6, 0.0, 2.9, 0.8, 0.02, 0.02])
planner.robot.set_qpos(start_qpos, full=True)

# Forward Kinematics: compute end-effector pose
planner.pinocchio_model.compute_forward_kinematics(start_qpos)
ee_idx = planner.link_name_2_idx["panda_hand"]
target_pose = planner.pinocchio_model.get_link_pose(ee_idx)

# Inverse Kinematics: solve for joint angles matching target pose
status, ik_qpos = planner.IK(target_pose, start_qpos, return_closest=True)
if status == "Success":
    print("IK Solution found:", ik_qpos[:7])

# Motion Planning: plan collision-free trajectory to target pose
target_pose.p[0] += 0.1  # Translate 10 cm in X
result = planner.plan_pose(target_pose, start_qpos)

if result["status"] == "Success":
    print(f"Planned trajectory duration: {result['duration']:.2f} s")
    print(f"Waypoints: {len(result['position'])}")
```

## Documentation, Contributing & Attribution

- **Changelog & migration notes:** [CHANGELOG.md](CHANGELOG.md)
- **Contributing guide:** [CONTRIBUTING.md](CONTRIBUTING.md)
- **Upstream API reference and tutorials** (applicable to the `mplib` Python API): [motion-planning-lib.readthedocs.io](https://motion-planning-lib.readthedocs.io/latest/tutorials/getting_started.html)
- **Attribution & Citing:** MPlib was originally created by Hao Su's Lab, UC San Diego ([haosulab/MPlib](https://github.com/haosulab/MPlib)); MPlib2 is maintained at [dd114/MPlib2](https://github.com/dd114/MPlib2) under the MIT License. If you use this software in research, please cite the original MPlib authors (see [CITATION.cff](CITATION.cff)) and optionally mention the MPlib2 fork.
