-
Notifications
You must be signed in to change notification settings - Fork 223
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
Added rclcpp component to Republish #275
Added rclcpp component to Republish #275
Conversation
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
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.
Looks good ! Could you add a test or an example ? Maybe here : https://github.com/ros-perception/image_common/tree/noetic-devel/image_transport/tutorial/src ?
class Republisher : public rclcpp::Node | ||
{ | ||
public: | ||
//! Constructor |
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.
Is the "!" a typo ?
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.
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
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.
Looks good ! Is there a way to add a test here ?
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.
I don't understand why you go through manually processing the parameters?
image_transport/src/republish.cpp
Outdated
auto pub = image_transport::create_publisher( | ||
node.get(), out_topic, | ||
this->pub = image_transport::create_publisher( | ||
this->shared_from_this().get(), out_topic, |
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->shared_from_this().get(), out_topic, | |
this, out_topic, |
image_transport/src/republish.cpp
Outdated
auto sub = image_transport::create_subscription( | ||
node.get(), in_topic, std::bind(pub_mem_fn, &pub, std::placeholders::_1), | ||
this->sub = image_transport::create_subscription( | ||
this->shared_from_this().get(), in_topic, std::bind(pub_mem_fn, &pub, std::placeholders::_1), |
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->shared_from_this().get(), in_topic, std::bind(pub_mem_fn, &pub, std::placeholders::_1), | |
this, in_topic, std::bind(pub_mem_fn, &pub, std::placeholders::_1), |
image_transport/src/republish.cpp
Outdated
// Load transport plugin | ||
typedef image_transport::PublisherPlugin Plugin; | ||
pluginlib::ClassLoader<Plugin> loader("image_transport", "image_transport::PublisherPlugin"); | ||
std::string lookup_name = Plugin::getLookupName(out_transport); | ||
|
||
auto instance = loader.createUniqueInstance(lookup_name); | ||
std::shared_ptr<Plugin> pub = std::move(instance); | ||
pub->advertise(node.get(), out_topic); | ||
pub->advertise(this->shared_from_this().get(), out_topic); |
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.
pub->advertise(this->shared_from_this().get(), out_topic); | |
pub->advertise(this, out_topic); |
image_transport/src/republish.cpp
Outdated
auto sub = image_transport::create_subscription( | ||
node.get(), in_topic, | ||
this->sub = image_transport::create_subscription( | ||
this->shared_from_this().get(), in_topic, |
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->shared_from_this().get(), in_topic, | |
this, in_topic, |
// remove program name | ||
args.erase(args.begin()); | ||
|
||
std::string in_transport{"raw"}; | ||
std::string out_transport{""}; | ||
|
||
if (image_transport::has_option(args, "--in_transport")) { | ||
in_transport = image_transport::get_option(args, "--in_transport"); | ||
} | ||
if (image_transport::has_option(args, "--out_transport")) { | ||
out_transport = image_transport::get_option(args, "--out_transport"); | ||
} | ||
|
||
rclcpp::NodeOptions options; | ||
// override default parameters with the desired transform | ||
options.parameter_overrides( | ||
{ | ||
{"in_transport", in_transport}, | ||
{"out_transport", out_transport}, | ||
}); |
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.
What is the point of all this? It seems to be the only specialized thing you are doing over the default behavior of generating an executable using rclcpp_components_register_node
image_transport/CMakeLists.txt
Outdated
rclcpp_components | ||
rclcpp | ||
) | ||
rclcpp_components_register_nodes(republish_node "image_transport::Republisher") |
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.
You could actually remove the entire add_executable below, delete republish_program.cpp and the utilities files and generate a node that loads the plugin and runs it with:
rclcpp_components_register_node(republish_node
PLUGIN "image_transport::Republisher"
EXECUTABLE republish
)
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
When using |
image_transport/src/republish.cpp
Outdated
// Load transport plugin | ||
typedef image_transport::PublisherPlugin Plugin; | ||
pluginlib::ClassLoader<Plugin> loader("image_transport", "image_transport::PublisherPlugin"); | ||
std::string lookup_name = Plugin::getLookupName(out_transport); | ||
|
||
auto instance = loader.createUniqueInstance(lookup_name); | ||
std::shared_ptr<Plugin> pub = std::move(instance); | ||
pub->advertise(node.get(), out_topic); | ||
pub->advertise(this, out_topic); |
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.
should this be this->pub? rather than declaring a new one in the line above? Might that be your crash?
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Yep, but I have now this awesome message Warning: class_loader.ClassLoader: SEVERE WARNING!!! Attempting to unload library while objects created by this loader exist in the heap! You should delete your objects before attempting to unload the library or destroying the ClassLoader. The library will NOT be unloaded.
at line 127 in /home/ahcorde/ros2_rolling/src/ros/class_loader/src/class_loader.cpp |
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Error is fixed too. The loader need to keep alive too |
Honestly - probably 70% of the ROS codebase that uses pluginlib has that error on shutdown |
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
These changes allow to use the republisher as a
rclcpp_component
and as a normal node.An example of how to use this: