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

The sequence between 2 rostopic messages subscriber

asked 2018-11-30 10:31:49 -0500

zhonghao gravatar image

updated 2018-12-02 03:03:14 -0500

Say I have 2 rostopic messages subscribers A and B listening to 2 different topics "a" and "b", however, I would to only processing the msg in A when the subscriber B got all messages from topic "b"(i.e. until there is no new message from b), is it possible to do it?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-12-01 00:08:57 -0500

Hamid Didari gravatar image

updated 2018-12-01 06:41:25 -0500

if i understand correctly you can use something like this:

void callback_b(...)
{
 time = ros::Time::now().toSec();
 index=0;
...
}


void callback_a(...)
{
 if(ros::Time::now().toSec() - time > 3)//3 seconds that we don't have a  message from b
  {
   //do something
  }
 buff[index] = *msg;
 index++;
}
edit flag offensive delete link more

Comments

hi I think it is much closer to what I want to do .But in this case, I guess the messages in callback_a before the condition"ros::Time::now().toSec() - time > 3" will be lost?

zhonghao gravatar image zhonghao  ( 2018-12-01 05:03:59 -0500 )edit

you can create buffer to save msg in 3 seconds some thing like the answer(i edited the answer)

Hamid Didari gravatar image Hamid Didari  ( 2018-12-01 06:40:04 -0500 )edit

Unless you control all publishers on topic B, how can you guarantee that you've "received the last message" on the topic?

gvdhoorn gravatar image gvdhoorn  ( 2018-12-01 07:19:18 -0500 )edit

some thing like time out , if no new msg arrive after 3 sec i assume there is no new msg . yes there is no guarantee that we 've received the last message but if we know the hz of msg in topic b we can use some thing like timeout

Hamid Didari gravatar image Hamid Didari  ( 2018-12-01 23:14:34 -0500 )edit
0

answered 2018-11-30 12:50:30 -0500

gvdhoorn gravatar image

I would to only processing the msg in A when the subscriber B got all messages from topic "b"(i.e. until there is no new message from b), is it possible to do it?

No. Not with just rostopic alone.

I'm also wondering what you mean by "processing the msg": rostopic does not really process messages. It can only print them to the console, or publish new ones.

And something to consider: when are "all messages on a topic" received? How would you know?

edit flag offensive delete link more

Comments

yes, I know rostoopic doesn't really process messages. we can process the msgs from callback funciton of the rostopic. However I need the all msgs from B topic ,i.e.(until no new msg received from B topic) such that I can do sth in rostopic A's callback function

zhonghao gravatar image zhonghao  ( 2018-11-30 12:55:35 -0500 )edit

I think you misunderstood me: rostopic is a ROS comman line tool. It does not call callbacks for you.

You may be referring to a "ROS topic", which is not the same as rostopic.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-01 07:20:01 -0500 )edit

Question Tools

Stats

Asked: 2018-11-30 10:31:49 -0500

Seen: 354 times

Last updated: Dec 02 '18