This repository demonstrates how to achieve the following :
- Using Drake's C++ API and system's framework to make custom/derived objects
- Minimally binding the derived objects
- Packaging the extended functionalities as a separate Python Package/Module
The setup used in repository tries to combine the Drake CMake project example with pybind11's CMake setup and take the best of two examples.
The resulting implementation looks more straight forward and has additional steps to package and ship the resulting code.
Tip
One Cool application of this approach is creating back box systems and shipping it to others as a python package. This is great if you are Teacher/Lecturer and you would like to test your pupils. With this method, the dynamics of a system is obfuscated since it is already complied and your pupils won't be able see what is going on in the system.
If you think the current setup can be improved, please open an issue or a pull request. Contributions and suggestions are appreciated.
Note
The setup has only been tested with Ubuntu 22.04 (Jammy) operating system, Python 3.10 and Drake v1.32.0 If you encountered any issues feel free to leave an issue so we can fix it together. You are also welcome to make a PR and extend the support.
First, make sure you have all the essential tools installed:
Then we are ready to install Drake by following the official installation procedure.
Important
We just need the pre-compiled binaries as APT packages (*.deb) installation of Drake and we don't need to use pip to install pydrake.
Finally we need to install pybind11
simply by:
The whole process is made simple by just invoking this command at the root of the project:
pip3 install .
setuptool
and CMake magic will kick in and start the C++ compilation, python binding and packaging.
In order to make sure the process was fully successful, you can use pytest
to run the package test:
py.test
- Add a Dockerfile for more reproducibility of the setup.
- Add information about how to shared the packaged python wheel.