Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moveit/py_binding_tools
Python binding tools for C++
https://github.com/moveit/py_binding_tools
Last synced: 4 days ago
JSON representation
Python binding tools for C++
- Host: GitHub
- URL: https://github.com/moveit/py_binding_tools
- Owner: moveit
- License: bsd-3-clause
- Created: 2024-03-05T15:27:59.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-12-19T08:52:47.000Z (17 days ago)
- Last Synced: 2024-12-19T09:26:50.985Z (17 days ago)
- Language: C++
- Size: 34.2 KB
- Stars: 1
- Watchers: 16
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.rst
- License: LICENSE.txt
Awesome Lists containing this project
README
## Python binding tools for C++
This package provides some tools to facilitate the generation of python bindings for C++ code, based on [pybind11](https://github.com/pybind/pybind11).
### Automatic type conversion for ROS message types
Conversion between native C++ and python types is performed via ROS message serialization and deserialization, which is implemented via C++ templates. It suffices to include:
```cpp
#include
```The `PoseStamped` message from the `geometry_msgs` package also accepts a single string as an argument.
In this case, the string is interpreted as the `header.frame_id` field of the message and the pose becomes the identity transform. To use this extension, include the following header instead:```cpp
#include
```### C++ ROS initialization
C++ and Python use their own ROS implementations (`rospy` and `roscpp`).
Thus, it is necessary to initialize ROS in the C++ domain additionally to the Python domain before calling any ROS-related functions from wrapped C++ functions or classes.
To this end, the package provides the python function `roscpp_init()` and the C++ class `ROScppInitializer`. The latter is intended to be used as a base class for your python wrapper classes:```cpp
class FooWrapper : protected ROScppInitializer, public Foo {
// ...
};
```to ensure that the ROS infrastructure is initialized before usage in the wrapped C++ class. Ensure to list `ROScppInitializer` as the _first_ base class, if ROS functionality is required in the constructor already!
`ROScppInitializer` registers an anonymous C++ ROS node named `python_wrapper_xxx`. If you need a specific node name or if you want to pass remappings, use the manual initialization function `roscpp_init(name="", remappings={}, options=0)` instead, which effectively calls `ros::init` with the given arguments. Note, that an empty name will map to the above-mentioned node name `python_wrapper_xxx`.