-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[py] Make it easier to pass C++ node pointers in Python #285
[py] Make it easier to pass C++ node pointers in Python #285
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+@sloretz Might you have time to review this?
\cc @dmcconachie-tri @calderpg-tri @IanTheEngineer
Reviewable status: 0 of 6 files reviewed, all discussions resolved (waiting on @sloretz)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 6 files reviewed, 1 unresolved discussion (waiting on @EricCousineau-TRI and @sloretz)
drake_ros/drake_ros/core/cc_pybind.cc
line 143 at r1 (raw file):
py::class_<rclcpp::Node, std::shared_ptr<rclcpp::Node>>(m, "CppNode", py::module_local())
Working: This seems to cause a segfault in Anzu. Removing py::module_local()
makes things a bit happier.
a2e94fd
to
43c13c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 6 files reviewed, 1 unresolved discussion (waiting on @sloretz)
a discussion (no related file):
There seems to be a new CI failure, most likely unrelated to this PR:
https://github.com/RobotLocomotion/drake-ros/actions/runs/5272233626/jobs/9534218327?pr=285#step:7:345
CMake Error at drake_ros/CMakeLists.txt:7 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:fastcdr,TYPE>
Target "fastcdr" not found.
@sloretz Is this something we need to work around, or is there something else going awry here?
drake_ros/drake_ros/core/cc_pybind.cc
line 143 at r1 (raw file):
Previously, EricCousineau-TRI (Eric Cousineau) wrote…
Working: This seems to cause a segfault in Anzu. Removing
py::module_local()
makes things a bit happier.
Done. For now, making this global; can take a step back if/when it interferes with another library's bindings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 6 files reviewed, 2 unresolved discussions (waiting on @EricCousineau-TRI and @sloretz)
drake_ros/drake_ros/test/core_test.py
line 122 at r2 (raw file):
assert not cpp_node_options.use_global_arguments node_cpp = CppNode("direct_node", node_options=cpp_node_options) assert node_cpp.get_name() == "direct_node"
-
If we are planning to expose existing rclcpp nodes to python, what APIs are we planning to connect ? i.e. can we add subscribers, publishers, callbacks, etc ?
It'd be nice to add tests for and document the features that we'll be exposing as a docstring, and also the limitations of this binding. -
I'd be great if we can add a test that shows that this node can actually spin and receive / send msgs, and play alongside existing "vanilla" rclpy nodes. I'm curious to see how rclpy.spin() and rclcpp::spin() interact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're planning to bind subscribers or publishers, this automatically requires a generic typecaster for data types : #257
Reviewable status: 0 of 6 files reviewed, 2 unresolved discussions (waiting on @EricCousineau-TRI and @sloretz)
43c13c0
to
b8884d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 6 files reviewed, 2 unresolved discussions (waiting on @sloretz)
drake_ros/drake_ros/test/core_test.py
line 122 at r2 (raw file):
Previously, adityapande-1995 (Aditya Pande) wrote…
If we are planning to expose existing rclcpp nodes to python, what APIs are we planning to connect ? i.e. can we add subscribers, publishers, callbacks, etc ?
It'd be nice to add tests for and document the features that we'll be exposing as a docstring, and also the limitations of this binding.I'd be great if we can add a test that shows that this node can actually spin and receive / send msgs, and play alongside existing "vanilla" rclpy nodes. I'm curious to see how rclpy.spin() and rclcpp::spin() interact.
Working: Per Slack DM, the intent of this is to only bind the minimum amount of the C++ Node API in Python so we don't need too much creativity in writing downstream bindings.
I'm going to hold off on binding additional facets, but I will add a quick test.
(I think functionality that consumes DrakeRos
effectively shows it, but yes, it'd be nice to just test directly.)
Useful when writing Python bindings against C++ code drake_ros: Switch to shared_ptr to eleverage enable_shared_from_this core: Ensure we import DrakeRos; add CppNode and CppNodeOptions
b8884d4
to
f5868b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 7 files reviewed, 2 unresolved discussions (waiting on @adityapande-1995 and @sloretz)
drake_ros/drake_ros/test/core_test.py
line 122 at r2 (raw file):
Previously, EricCousineau-TRI (Eric Cousineau) wrote…
Working: Per Slack DM, the intent of this is to only bind the minimum amount of the C++ Node API in Python so we don't need too much creativity in writing downstream bindings.
I'm going to hold off on binding additional facets, but I will add a quick test.(I think functionality that consumes
DrakeRos
effectively shows it, but yes, it'd be nice to just test directly.)
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with the linter error resolved !
Reviewable status: 0 of 7 files reviewed, 2 unresolved discussions (waiting on @sloretz)
Done, I think. I had an odd failure of CMake-based ROS failing, but will see if CI shows the same issue. |
@adityapande-1995 CI seems to have failed. Can I ask if you can reproduce this (Bazel passes, CMake fails) and, if so, what might be the problem? # Bazel
cd drake-ros
cd drake_ros
bazel run //drake_ros:core_test
# Passes
# CMake
cd ros_ws
colcon build --packages-up-to drake_ros --symlink-install
# "Shortcut" - not sure how to run single test
source install/setup.bash
( cd build/drake_ros && ctest -V -R core_test_py; )
# Fails |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 8 files reviewed, 1 unresolved discussion (waiting on @adityapande-1995 and @sloretz)
a discussion (no related file):
Previously, EricCousineau-TRI (Eric Cousineau) wrote…
There seems to be a new CI failure, most likely unrelated to this PR:
https://github.com/RobotLocomotion/drake-ros/actions/runs/5272233626/jobs/9534218327?pr=285#step:7:345CMake Error at drake_ros/CMakeLists.txt:7 (target_link_libraries): Error evaluating generator expression: $<TARGET_PROPERTY:fastcdr,TYPE> Target "fastcdr" not found.
@sloretz Is this something we need to work around, or is there something else going awry here?
Done (I think) - I did not see this error once I rebased onto latest main
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be an RMW implementation issue. I've addressed it with a workaround, will file an issue.
Reviewable status: 0 of 9 files reviewed, 1 unresolved discussion (waiting on @adityapande-1995 and @sloretz)
Core bazel testing of |
…tLocomotion#285)" This reverts commit 4ca38a8.
I would like to not get too creative when trying to bind C++ code that has
rclcpp::Node
arguments. This is one approach.Relates ros2/rclpy#291
This change is