ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Don't get all rostopic echo data

asked 2017-04-28 21:37:20 -0500

Bob H gravatar image

updated 2017-04-29 04:55:08 -0500

gvdhoorn gravatar image

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

edit retag flag offensive close merge delete

Comments

did you run rostopic echo before the node?

Archhaskeller gravatar image Archhaskeller  ( 2017-04-28 23:39:19 -0500 )edit

Yes, I had rostopic running before running the node

Bob H gravatar image Bob H  ( 2017-04-29 10:15:11 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-04-29 04:58:48 -0500

gvdhoorn gravatar image

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().

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-04-28 21:37:20 -0500

Seen: 1,182 times

Last updated: Apr 29 '17