Interoperability between C / C++ and other Python binding libraries?
See original GitHub issueHaven’t yet hit a need for this, but wanted to ask anywho:
We use pybind11
in Drake, and it’d be nice if we had the ability to get interop between rclpy
and rclcpp
within our own binding layer.
For some external examples, people have done this with packages like OpenCV, VTK, etc.: https://github.com/virtuald/pybind11_opencv_numpy https://github.com/EricCousineau-TRI/repro/tree/b9e02d6d5a71f6315b80759ba1628b4bb383c0b8/python/vtk_pybind (my stuff, but points to the motivating examples / questions)
Granted, VTK has a rich object model which makes it relatively easy to do the interop. OpenCV is implemented in pure C++, hence the ease of use with pybind C++.
My technical guesses:
- Interop between
rcl
C andrclpy
should be more or less straightforward, would just require experimental / unstable APIs to be exposed (or copied + pasted) from the bindings here. - Interop between
rclpp
andrclpy
would be much more challenging, as the C++ API (rightly so) encapsulates the underlying C structs.- This may be achievable by creating C++ Python bindings that have parity with the
rclpy
API. It would require more overhead in terms of maintenance, compilation, size, etc; however, the unittests here look very extensive, so it should be relatively easy to confirm useful parity 😃
- This may be achievable by creating C++ Python bindings that have parity with the
As an alternative, we can do what we do for LCM, where we introduce our own wrapper interface… but this has given me personally many sad faces for API interop + decoupling (heavy frameworks…), utilities, generalization, etc.:
https://drake.mit.edu/pydrake/pydrake.lcm.html
https://drake.mit.edu/doxygen_cxx/classdrake_1_1lcm_1_1_drake_lcm.html
(doc produced at or around drake@361223416
)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top GitHub Comments
It looks like your API expects an
rclcpp::Node::SharedPtr &
, but your example is passing it the Python classrclpy.node.Node
. Those are different types.Note that
rclpy
doesn’t userclcpp
, so it has no conversions torclcpp
types. It does have a way to get thercl
typercl_node_t
. Ifmoveit
has APIs usingrcl
types, then that’s your starting point. Otherwise you’d needrclcpp
to offer a way to create anrclcpp::Node
instance from a borrowedrcl_node_t *
, which I don’t think exists.There was a proof-of-concept developed, but it’s probably quite stale at this point: https://github.com/ros2/rclpy/tree/proof_of_concept_pybind11
@sloretz (the original author of this PoC) would probably be the best person to weigh in here.