Repository navigation
Closed
Description
Bug report
Required Info:
- Operating System: Ubuntu 22.04 Jammy
- Installation type: Source
- Version or commit hash: rolling
- DDS implementation: Rolling Default
Description
The TransformBroadcaster constructor should take a NodeT, but tests in tf2_ros/test/test_transform_broadcaster.cpp pass a pointer to a rclcpp::Node to the broadcaster (and the tests pass although they shouldn't).
Changes in #552 exposed this issue, as it depends on NodeT being a pointer to a rclcpp::Node.
In Writing a broadcaster (C++), a node instance is passed to the constructor as below:
tf_broadcaster_ = std::make_unique<tf2_ros::TransformBroadcaster>(*this);But in the tf2_ros/test/test_transform_broadcaster.cpp, a shared pointer is provided.
TEST(tf2_test_transform_broadcaster, transform_broadcaster_rclcpp_node)
{
auto node = rclcpp::Node::make_shared("tf2_ros_message_filter");
tf2_ros::TransformBroadcaster tfb(node);
}This was originally reported in ros-perception/image_pipeline#775.
FYI @alsora
Steps to reproduce issue
mkdir -p geometry2_ws/src
cd "$_"
git clone [email protected]:ijnek/geometry2 -b ijnek-bug-test-case
cd ../
colcon build
Expected behavior
Compiles fine.
Actual behavior
Doesn't compile.
--- stderr: tf2_ros
In file included from /home/ijnek/tmp_workspaces/geometry2_ws/src/geometry2/tf2_ros/test/test_transform_broadcaster.cpp:31:
/home/ijnek/tmp_workspaces/geometry2_ws/src/geometry2/tf2_ros/include/tf2_ros/transform_broadcaster.h: In instantiation of ‘tf2_ros::TransformBroadcaster::TransformBroadcaster(NodeT&&, const rclcpp::QoS&, const rclcpp::PublisherOptionsWithAllocator<AllocatorT>&) [with NodeT = rclcpp::Node&; AllocatorT = std::allocator<void>]’:
/home/ijnek/tmp_workspaces/geometry2_ws/src/geometry2/tf2_ros/test/test_transform_broadcaster.cpp:57:41: required from here
/home/ijnek/tmp_workspaces/geometry2_ws/src/geometry2/tf2_ros/include/tf2_ros/transform_broadcaster.h:71:7: error: base operand of ‘->’ has non-pointer type ‘rclcpp::Node’
71 | node->get_node_parameters_interface(),
| ^~~~
gmake[2]: *** [CMakeFiles/tf2_ros_test_transform_broadcaster.dir/build.make:76: CMakeFiles/tf2_ros_test_transform_broadcaster.dir/test/test_transform_broadcaster.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:510: CMakeFiles/tf2_ros_test_transform_broadcaster.dir/all] Error 2
gmake[1]: *** Waiting for unfinished jobs....
gmake: *** [Makefile:146: all] Error 2
---
Failed <<< tf2_ros [14.3s, exited with code 2]
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]TransformBroadcaster takes shared pointer or raw node?[/-][+]TransformBroadcaster takes shared pointer instead of raw node[/+]alsora commentedon Sep 21, 2022
Yes, the changes in #552 require that the
NodeTpassed to the constructor ofTransformBroadcasteris some sort of pointer.Note that this requirement was already present in the constructor of
TransformListener: thenodepassed to the constructor was then used in theinitfunction asnode->get_node_base_interface()(thus assuming that it was a pointer) see https://github.com/ros2/geometry2/pull/552/files#diff-db2161f65f99c88d9aef0e89c8d8b2774fcc52e45c9ccc47a9ab76648842f908L102 and https://github.com/ros2/geometry2/pull/552/files#diff-db2161f65f99c88d9aef0e89c8d8b2774fcc52e45c9ccc47a9ab76648842f908L119Before my PR,
TransformBroadcasterwas accepting either nodes or pointers to nodes andTransformListenerwas accepting only pointers to nodes.Now they both only accept pointers to nodes.
I wasn't aware of the existence of that tutorial where a node (not a pointer) was used.
There are different options here:
TransformBroadcasterandTransformListenerto accept both nodes and pointers to nodes.IMO nodes (and ROS entities in general) should be handled via pointers to make it harder to do mistakes, thus my preference would be (2).
ijnek commentedon Sep 21, 2022
I agree with option 2 too.
For the new recommended method, instead of having:
could I suggest having:
That's how its done in a function from rclcpp/executors.hpp.
And yes, we'll have to be careful to consider cases that'll break and add some deprecated methods.
clalancette commentedon Sep 21, 2022
Yes, I agree with this too. @alsora could you make the updates? Thanks.
alsora commentedon Sep 21, 2022
Yes, will open follow-up PRs soon.
@ijnek note that your proposed approach would not work with raw pointers.
clalancette commentedon Sep 21, 2022
Thanks, appreciated.
ijnek commentedon Sep 23, 2022
I was just trying to get across the point that NodeT itself shouldn't be a pointer, but should be the rclcpp node type. That's how it is everywhere else in rclcpp.
In regards to using shared_ptr vs raw pointer vs reference to pass rclcpp::Node, I don't know what the recommended way is.