question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Interoperability between C / C++ and other Python binding libraries?

See original GitHub issue

Haven’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 and rclpy 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 and rclpy 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 😃

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:open
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sloretzcommented, Jun 20, 2022

I am currently encountering issues in doing so, I have a class whose constructor accepts a shared pointer reference to a node instance. I wish to create this node using rclpy and pass it to MoveIt as follows.

It looks like your API expects an rclcpp::Node::SharedPtr &, but your example is passing it the Python class rclpy.node.Node. Those are different types.

I was hoping that users would be able to leverage the rclpy library to create nodes which could be passed to MoveIt through the Python API.

Note that rclpy doesn’t use rclcpp, so it has no conversions to rclcpp types. It does have a way to get the rcl type rcl_node_t. If moveit has APIs using rcl types, then that’s your starting point. Otherwise you’d need rclcpp to offer a way to create an rclcpp::Node instance from a borrowed rcl_node_t *, which I don’t think exists.

1reaction
mjcarrollcommented, Mar 25, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Bindings: Calling C or C++ From Python
If so, then Python bindings allow you to call functions and pass data from Python to C or C++, letting you take advantage...
Read more >
1. Extending Python with C or C++ — Python 3.11.1 ...
These modules let you write Python code to interface with C code and are more portable between implementations of Python than writing and...
Read more >
Interfacing with C/C++ Libraries
CFFI provides a simple to use mechanism for interfacing with C from both CPython and PyPy. It supports two modes: an inline ABI...
Read more >
Calling C/C++ from Python? [closed] - Stack Overflow
Since cppyy is used to bind C++ code, I presume handling some more C++ code should be fine. And that code is not...
Read more >
A New PyROOT: Modern, Interoperable and More Pythonic
PyROOT, the Python bindings of the ROOT software toolkit, plays a key role here, since it allows to automatically and dynamically invoke C++ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found