Skip to content
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

Merged

Conversation

ahcorde
Copy link
Collaborator

@ahcorde ahcorde commented Jun 30, 2023

These changes allow to use the republisher as a rclcpp_component and as a normal node.

An example of how to use this:

ros2 run image_transport republish --in_transport compressed in/compressed:=/camera/image/compressed out/compressed:=/camera/republish/compressed out:=/camera/republish/image_raw

ahcorde added 2 commits June 30, 2023 17:04
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Copy link
Contributor

@adityapande-1995 adityapande-1995 left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the "!" a typo ?

Copy link
Collaborator Author

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>
Copy link
Contributor

@adityapande-1995 adityapande-1995 left a 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 ?

@ahcorde ahcorde added the ros1 label Jan 18, 2024
@ahcorde ahcorde added ros2 Issues or Pull Requests targeting ROS2 and removed ros1 labels Feb 15, 2024
@ahcorde ahcorde requested a review from mikeferguson February 15, 2024 12:41
Copy link
Member

@mikeferguson mikeferguson left a 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?

auto pub = image_transport::create_publisher(
node.get(), out_topic,
this->pub = image_transport::create_publisher(
this->shared_from_this().get(), out_topic,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this->shared_from_this().get(), out_topic,
this, out_topic,

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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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),

// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub->advertise(this->shared_from_this().get(), out_topic);
pub->advertise(this, out_topic);

auto sub = image_transport::create_subscription(
node.get(), in_topic,
this->sub = image_transport::create_subscription(
this->shared_from_this().get(), in_topic,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this->shared_from_this().get(), in_topic,
this, in_topic,

Comment on lines 39 to 58
// 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},
});
Copy link
Member

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

rclcpp_components
rclcpp
)
rclcpp_components_register_nodes(republish_node "image_transport::Republisher")
Copy link
Member

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>
@ahcorde
Copy link
Collaborator Author

ahcorde commented Feb 15, 2024

When using --out_transport the app is crashing.

@ahcorde ahcorde requested a review from mikeferguson February 15, 2024 17:05
// 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);
Copy link
Member

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>
@ahcorde
Copy link
Collaborator Author

ahcorde commented Feb 15, 2024

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>
@ahcorde ahcorde requested a review from mikeferguson February 15, 2024 17:41
@ahcorde
Copy link
Collaborator Author

ahcorde commented Feb 15, 2024

Error is fixed too. The loader need to keep alive too

@mikeferguson
Copy link
Member

Honestly - probably 70% of the ROS codebase that uses pluginlib has that error on shutdown

@ahcorde
Copy link
Collaborator Author

ahcorde commented Feb 16, 2024

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
@ahcorde
Copy link
Collaborator Author

ahcorde commented Feb 19, 2024

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@ahcorde ahcorde merged commit 1a559ed into ros-perception:rolling Feb 20, 2024
2 checks passed
@ahcorde ahcorde deleted the ahcorde/rolling/republisher_component branch February 20, 2024 08:59
tonynajjar pushed a commit to angsa-robotics/image_common that referenced this pull request May 15, 2024
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ros2 Issues or Pull Requests targeting ROS2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants