Ask Your Question

Revision history [back]

Thanks for your answers.

I was successful in using latch and getNumSubscribers() to achieve a single message publisher, as explained above.

I would like to point out that using 'rostopic echo' command to verify a single message publisher has not been successful for me. When I run 'rostopic echo', I notice that an additional subscriber is listed under 'rostopic info'. Thus I assumed it would behave like a regular subscriber.

I observe that when I use a separate program to subscribe to the topic, I receive the message successfully. However, 'rostopic echo' does not display the single message that I am trying to publish.

Here is some demo code with the relevant portions:

int main(int argc, char** argv) { ros::init(argc, argv, "VirtualObjectPublisher"); ros::NodeHandle VirtualObjectNode("~"); ros::Publisher VirtualObjectROSPublisher; ros::Rate poll_rate(100); bool latchOn = 1;

/* Some processing */

VirtualObjectROSPublisher = VirtualObjectNode.advertise<eu_nifti_env_msg_ros::ElementOfInterestMessage>("/eoi", 20, latchOn);

 while(VirtualObjectROSPublisher.getNumSubscribers()==0)
{
   ROS_ERROR("Waiting for subscibers");
   sleep(10);
}
ROS_ERROR("Got subscriber");
VirtualObjectROSPublisher.publish(publishEOImsg);
ros::spinOnce();

 while(ros::ok())
{
   sleep(3);    
}

return 0;

}

// I added the ROS_ERROR for debugging. The same with the sleep statements. I also added the final ros::ok(), loop since I didn't want the node to be destroyed prematurely, to better understand the problem.

My test procedure:

i. Terminal 1 : Start the above code ii. After 3 seconds, Terminal 2 : 'rostopic echo /eoi'. iii. Terminal 1 : Terminal 2 does not echo the topic.

However, as I explained earlier, if I have a program with a Subscriber, it reads the message successfully.

Regards,

Shanker Keshavdas

Thanks for your answers.

I was successful in using latch and getNumSubscribers() to achieve a single message publisher, as explained above.

I would like to point out that using 'rostopic echo' command to verify a single message publisher has not been successful for me. When I run 'rostopic echo', I notice that an additional subscriber is listed under 'rostopic info'. Thus I assumed it would behave like a regular subscriber.

I observe that when I use a separate program to subscribe to the topic, I receive the message successfully. However, 'rostopic echo' does not display the single message that I am trying to publish.

Here is some demo code with the relevant portions:

// Code starts here

int main(int argc, char** argv) { argv)

{

ros::init(argc, argv, "VirtualObjectPublisher");
  ros::NodeHandle VirtualObjectNode("~");
  ros::Publisher VirtualObjectROSPublisher;
  ros::Rate poll_rate(100);
  bool latchOn = 1;

1;

/* Some processing */

VirtualObjectROSPublisher = VirtualObjectNode.advertise<eu_nifti_env_msg_ros::ElementOfInterestMessage>("/eoi", 20, latchOn);

 while(VirtualObjectROSPublisher.getNumSubscribers()==0)
{
   ROS_ERROR("Waiting for subscibers");
   sleep(10);
}
ROS_ERROR("Got subscriber");
VirtualObjectROSPublisher.publish(publishEOImsg);
ros::spinOnce();

 while(ros::ok())
{
   sleep(3);    
}

return 0;

}

// I added the ROS_ERROR for debugging. The same with the sleep statements. I also added the final ros::ok(), loop since I didn't want the node to be destroyed prematurely, to better understand the problem.

My test procedure:

i. Terminal 1 : Start the above code code

ii. After 3 seconds, Terminal 2 : 'rostopic echo /eoi'. /eoi'.

iii. Terminal 1 :

Terminal 2 does not echo the topic.

However, as I explained earlier, if I have a program with a Subscriber, it reads the message successfully.

Regards,

Shanker Keshavdas