My subscribe method (C++) is not invoked

asked 2021-09-01 18:47:25 -0500

ssn gravatar image

updated 2021-09-02 01:22:46 -0500

janindu gravatar image

I am using ROS melodic in Docker environment. It consists of various systems and I am describing only part of the system.

Launch file 'A' is calling 'camera.launch' file and is providing different arguments as follows.

<!-- camera1 -->
    <include file="$(find asv_perception_obstacleid)/launch/camera.launch" ns="camera1">
        <arg name="use_segmentation" value="$(arg use_segmentation)" />
        <arg name="classification_topic" value="/classification/1/output" />
        <arg name="homography_topic" value="/camera1/homography/rgb_radar" />
    </include>

    <include file="$(find asv_perception_obstacleid)/launch/camera.launch" ns="ir_camera1"> 
            <arg name="use_segmentation" value="$(arg use_segmentation)" />
            <arg name="ir_segmentation_topic" value="/segmentation_ir/0/output" />
            <arg name="homography_topic" value="/ir_camera1/homography/rgb_radar" />
            <arg name="ir_homography_topic" value="/ir_camera1/homography/ir_radar" />
    </include>

Camera.launch file -

<launch>

  <arg name="package_name" value="asv_perception_obstacleid"/>
  <arg name="use_segmentation" />
  <arg name="segmentation_topic" default="default1"/>
  <arg name="ir_segmentation_topic" default="default2" />
  <arg name="classification_topic" default="default3"/>
  <arg name="homography_topic" default="default4"/>
  <arg name="ir_homography_topic" default="default5"/>


  <arg name="nodelet_name" value="$(arg package_name)_nodelet" />
  <node pkg="nodelet" type="nodelet" name="$(arg nodelet_name)" args="manager" respawn="true" />

   <node pkg="nodelet" type="nodelet" name="projection" respawn="true" output="screen"
    args="load $(arg package_name)/ObstacleProjectionNodelet $(arg nodelet_name)" >

    <remap from="~segmentation" to="$(arg segmentation_topic)" />
    <remap from="~ir_segmentation" to="$(arg ir_segmentation_topic)" />
    <remap from="~classification" to="$(arg classification_topic)" />
    <remap from="~rgb_radar" to="$(arg homography_topic)" />
    <remap from="~ir_radar" to="$(arg ir_homography_topic)" />

    <!-- convert to boolean strings that roscpp likes -->
    <param name="use_segmentation" value="true" if="$(arg use_segmentation)" />
    <param name="use_segmentation" value="false" unless="$(arg use_segmentation)" />
    </node>
<launch>

The 'ObstacleProjectionNodelet' is implemented in C++ and is derived from nodelet_topic_tools::NodeletLazy. I have put the ROS_DEBUG statements in C++ code so that I can see them in rqt_console. For 'camera1', I see that its subscribe method is invoked. However, for 'ir_camera1', the subscribe method is not invoked. The nodes are created for both. I have a statement in onInit() method which I see for both cameras. My questions: 1) Notice my use of 'default' in the launch file. Some arguments are not applicable for 'camera1' and some are not applicable for 'ir_camera1'. Is there anything wrong with giving imaginary string as default values? I tried empty string, 'None' but they did not work. 2) Who calls 'subscribe' method is ROS world? How can I debug why subscribe method of the class is not invoked? 3) Is this something to do with derivation from NodeletLazy? Sorry, I am trying to reuse someone's code and I am trying to understand it while simultaneously adding some parts to it. Is it possibl to remove optimization of NodeletLazy (only publish if there are subscribers). Could it be the problem? If so, what are the alternatives?

The important part of C++ code is as follows -

namespace {
    using namespace obstacle_id;
    static const std::string 
        TOPIC_NAME_INPUT_SEGMENTATION = "segmentation"
        , TOPIC_NAME_INPUT_IR_SEGMENTATION = "ir_segmentation"
        , TOPIC_NAME_INPUT_CLASSIFICATION = "classification"
        , TOPIC_NAME_INPUT_HOMOGRAPHY_RGB_TO_RADAR = "rgb_radar"
        , TOPIC_NAME_INPUT_HOMOGRAPHY_IR_TO_RADAR = "ir_radar"
        , TOPIC_NAME_OUTPUT_OBSTACLES = "obstacles"
        , TOPIC_NAME_OUTPUT_CLOUD = "cloud"
    ;
} // ns
//////////////////////////////////////////////////////////////////////////////////////////////
void ObstacleProjectionNodelet::onInit ()
{
    // Call the super onInit ()
    base_type ...
(more)
edit retag flag offensive close merge delete

Comments

Also, is there any way to "see" the resolved value of arguments which are passed from launch file to the nodes (in Python as well as in C++)?

ssn gravatar image ssn  ( 2021-09-01 20:07:09 -0500 )edit

Is this something to do with derivation from NodeletLazy?

that should be easy to check: if you create a normal nodelet, do things still not work as you expect them?


Edit: also: including 6 questions in one post is not going to work. Your question title is "My subscribe method (C++) is not invoked". But you have many more questions in the actual question body. Visibility for those is almost zero, and it's going to be difficult for anyone to answer all of your questions.

I'd suggest to focus on a single one here.

Please also clarify how this is related to your #q385551.

gvdhoorn gravatar image gvdhoorn  ( 2021-09-02 01:31:39 -0500 )edit