HBRS-SDP / ss22-ros2-perception

GNU General Public License v3.0
0 stars 3 forks source link

cannot pass lifecycle_node pointer as function parameter [non-blocking issue] #22

Closed vamsikalagaturu closed 2 years ago

vamsikalagaturu commented 2 years ago

In the multimodal_object_recognition.cpp constructor:

https://github.com/HBRS-SDP/ss22-ros2-perception/blob/43bf5f8fa26eba3cfaf84deee420159f34f086fe/mir_object_recognition/ros/src/multimodal_object_recognition.cpp#L665

while initializing the cluster_visualizer_rgb_, we cannot pass this as a paramter to the cluster_visualizerrgb.

https://github.com/HBRS-SDP/ss22-ros2-perception/blob/43bf5f8fa26eba3cfaf84deee420159f34f086fe/mir_object_recognition/ros/src/mir_perception_utils/clustered_point_cloud_visualizer.cpp#L17

it throws the below error:

/home/vk/sdp_ws/src/mir_object_recognition/ros/src/multimodal_object_recognition.cpp:673:38: error: no matching function for call to ‘mir_perception_utils::visualization::ClusteredPointCloudVisualizer::ClusteredPointCloudVisualizer(MultiModalObjectRecognitionROS*, const char [28], bool)’
  673 |     rgb_cluster_remove_outliers_(true)

This can be reproduced by checking out to the commit 43bf5f8 of cloud_image_recog branch and adding this as a parameter in the below line:

https://github.com/HBRS-SDP/ss22-ros2-perception/blob/43bf5f8fa26eba3cfaf84deee420159f34f086fe/mir_object_recognition/ros/src/multimodal_object_recognition.cpp#L665

cluster_visualizerrgb(this, "output/tabletop_cluster_rgb", true),

This is not a blocking issue, currently, we are creating temporary nodes and publishing the data:

https://github.com/HBRS-SDP/ss22-ros2-perception/blob/43bf5f8fa26eba3cfaf84deee420159f34f086fe/mir_object_recognition/ros/src/mir_perception_utils/clustered_point_cloud_visualizer.cpp#L33

I am just exploring to pass the main node instance and use it to publish data, rather than temporary nodes.

sthoduka commented 2 years ago

https://answers.ros.org/question/330920/ros-2-composable-node-pass-nodehandler/ so you can use shared_from_this() and std::shared_ptr (with no const and pass by value, not reference) std::shared_ptr<rclcpp_lifecycle::LifecycleNode> node

sthoduka commented 2 years ago

@vamsikalagaturu I forgot I had commented on this. The comment still applies: When creating the object, replace cluster_visualizer_rgb_("output/tabletop_cluster_rgb", true) with: cluster_visualizer_rgb_(shared_from_this(), "output/tabletop_cluster_rgb", true) The constructor signature should be:

ClusteredPointCloudVisualizer::ClusteredPointCloudVisualizer(
    std::shared_ptr<rclcpp_lifecycle::LifecycleNode> node,
    const std::string &topic_name, bool check_subscribers)
sthoduka commented 2 years ago

One other option is to create the visualizers only in the on_configure function. It makes sense for keeping with the lifecycle rules of creating publishers only on configuration. This probably means you will have to make the visualizer objects themselves as shared_ptrs.

vamsikalagaturu commented 2 years ago

Declaring them in the on_configure and using shared_from_this()has resolved the duplicate name conflicts.