-
Notifications
You must be signed in to change notification settings - Fork 786
[ros2] Add check if rclcpp::init() has been called #859
[ros2] Add check if rclcpp::init() has been called #859
Conversation
chapulina
left a comment
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.
Thanks for catching the problem and making a PR!
The new test failed on the build farm, it looks like the message is published too late:
19:54:56 12: �[0m/tmp/ws/src/gazebo_ros_pkgs/gazebo_ros/test/test_plugins.cpp:63: Failure
19:54:56 12: Expected: (msg) != (nullptr), actual: 16-byte object <00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00> vs 8-byte object <00-00 00-00 00-00 00-00>
19:54:56 12: test
19:54:57 12: [WARN] [hello_ros_world]: Publishing
| rclcpp::init(argc, argv); | ||
| if (!rclcpp::is_initialized()) { | ||
| rclcpp::init(argc, argv); | ||
| } |
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.
Good call! It may also be worth it adding a check to gazebo_ros_init, and in both cases, printing a warning if it's been initialized, so the user knows their arguments won't be loaded.
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.
OK. I'll add a check to gazebo_ros_init, too.
I think using both gazebo_ros_init and gazebo_ros_factory is a common use case for ROS users. In that case it might be annoying when a warning is always printed. Is that OK?
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.
Ok, let's go without the warning, thanks!
6d3652e to
18be0fe
Compare
|
Thank you for your reviewing.
Thanks for your advice in advance. |
chapulina
left a comment
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.
Thanks for iterating, this looks good to me.
| rclcpp::init(argc, argv); | ||
| impl_->ros_node_ = gazebo_ros::Node::Get(); | ||
| } else { | ||
| impl_->ros_node_ = gazebo_ros::Node::Get(); |
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.
nitpick: this line can be moved out of the if/else
Hi,
I would like to use both
gazebo_ros_initandgazebo_ros_factoryplugins at the same time. But when I tried that, it failed.This PR adds check if
rclcpp::init()has been called before calling it.