0
$\begingroup$

Rosanswers logo

I have a node which publishes data 3 times. But when I look at the results of the rostopic echo, I only get the last two cycles. I have tried this with different counts, but rostopic echo always misses the first cycle.

std_msgs::Int16MultiArray head;  
ros::init(argc,argv, "xxxxxx");  
ros::NodeHandle nh;  
pubheader=nh.advertise<std_msgs>::Int16MultiArray>("Audio_head",1);  
ros::Rate loop_rate(1);  
int i,j;  
for(j=0;j<3;j++)  
{  
  head.data.clear();  
  for(i=0;i < headersize;i++)  
   {  
    head.data.push_back(header.ROSheader[i]);  
  }  
  pubheader.publish(head);  
  ros::spinOnce();  
  loop_rate.sleep();  
}  

Any reason that only the last two instances are echoed?

Thanks


Originally posted by Bob H on ROS Answers with karma: 1 on 2017-04-28

Post score: 0


Original comments

Comment by Archhaskeller on 2017-04-28:
did you run rostopic echo before the node?

Comment by Bob H on 2017-04-29:
Yes, I had rostopic running before running the node

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

A bit of a guess, but setting up subscriptions takes time, even if you only have everything running on a single machine.

As @Archhaskeller hints at, rostopic might simply be 'too late' to receive all publications.

If receiving all messages is important, consider using an interaction pattern that is not so completely decoupled as pub-sub (ie: services or actions), or see if a latched topic helps.

Another option might be to wait with publishing until there is (are) at least one (or more) subscriber(s). You can do that with checking ros::Publisher::getNumSubscribers().


Originally posted by gvdhoorn with karma: 86574 on 2017-04-29

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.