The Open Motion Planning Library
Maintained. Last release 5 months ago. Weaker on release cadence.
pip install omplOMPL Python Bindings
How to use Python binding
The Python bindings mirror OMPL’s C++ API. For detailed usage, refer to:
- The C++ OMPL documentation
- The sample scripts in the
pyexamples/directory
How is Nanobind organized?
We use Nanobind to generate Python bindings for OMPL. For every OMPL header, there is a corresponding binding file in the bindings/ directory, organized into subfolders that mirror OMPL’s module structure. For example, all bindings for ompl::base live under bindings/base.
The Nanobind documentation provides a comprehensive guide to writing bindings. The one thing to watch out for is overriding C++ virtual methods in Python. You need a trampoline class to forward calls correctly.
How to contribute to the bindings
Adding new bindings
General Instructions
The bindings/ directory mimics the layout of the src/ompl/ directory. If there is a new header file in src/ompl/ in the future release, you can add a new binding file in the corresponding subdirectory under bindings/. The binding file should have the same name as the header file, with a .cpp extension. If you add a new header file src/ompl/MODULE/SUBFOLERPATH/NEWFEATURE.h, you should create a binding file bindings/MODULE/SUBFOLERPATH/NEWFEATURE.cpp. Here are some examples:
src/ompl/base/StateSpace.h -> bindings/base/StateSpace.cpp
src/ompl/geometric/planners/rrt/RRT.h -> bindings/geometric/planners/rrt/RRT.cpp
src/ompl/control/spaces/RealVectorControlSpace.h -> bindings/control/spaces/RealVectorControlSpace.cpp
Then, in the bindings/MODULE/SUBFOLERPATH/NEWFEATURE.cpp, you should include the header file and use Nanobind to create the bindings. Here is a minimal example:
Step 1: In the bindings/MODULE/SUBFOLERPATH/NEWFEATURE.cpp, include the necessary headers and namespaces:
#include <nanobind/nanobind.h>
#include "ompl/MODULE/SUBFOLERPATH/NEWFEATURE.h"
#include "init.h" // or "../init.h", depending on the SUBFOLDERPATH
namespace nb = nanobind;
// Necessary namespaces
// namespace ob = ompl::base;
// namespace og = ompl::geometric;
// namespace oc = ompl::control;