The sequence between 2 rostopic messages subscriber
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?
Asked by zhonghao on 2018-11-30 11:31:49 UTC
Answers
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?
Asked by gvdhoorn on 2018-11-30 13:50:30 UTC
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
Asked by zhonghao on 2018-11-30 13:55:35 UTC
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
.
Asked by gvdhoorn on 2018-12-01 08:20:01 UTC
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++;
}
Asked by Hamid Didari on 2018-12-01 01:08:57 UTC
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?
Asked by zhonghao on 2018-12-01 06:03:59 UTC
you can create buffer to save msg in 3 seconds some thing like the answer(i edited the answer)
Asked by Hamid Didari on 2018-12-01 07:40:04 UTC
Unless you control all publishers on topic B, how can you guarantee that you've "received the last message" on the topic?
Asked by gvdhoorn on 2018-12-01 08:19:18 UTC
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
Asked by Hamid Didari on 2018-12-02 00:14:34 UTC
Comments