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

how to check if there are waiting messages in a callback queue?

asked 2011-04-28 09:35:06 -0600

Javier Romero gravatar image

updated 2011-04-29 06:55:01 -0600

The test case is the following: i receive images from a camera through a callback, and I want to run a loop of processing until a new image arrive. Is there any function that can tell me if there are new messages in the queue? The pseudocode would look like this (i'm looking for new_imagemsg()):

void imagecb(imagemsg)
{
  while(!new_imagemsg())
  {
    optimize(imagemsg);
  }
  return;
}

I tried the following:

void imagecb(imagemsg)
{
  while(static_cast<ros::CallbackQueue*>(nh->getCallbackQueue())->isEmpty())
  {
    optimize(imagemsg);
  }
  return;
}

But it looks like the function isEmpty() always returns false when called from inside a callback, which makes me think that the callback is removed once the callback function finishes instead of when it enters. Unfortunately it looks like CallbackQueue doesn't have a getSize function ( i would like to check if the size is bigger than one).

Any other ideas? clearing the queue from inside a callback function doesn't seem to work either, apart from being kind of hacky.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2011-07-19 05:23:26 -0600

tfoote gravatar image

The callback queues do not have this functionality. You'll need to clear the queue and build your own which you can track. If you use the boost shared pointer callbacks you can do this with only pointers and thus relatively efficiently.

edit flag offensive delete link more
1

answered 2011-04-28 21:00:09 -0600

I never used them, but CallbackQueues sound like they might help you.

edit flag offensive delete link more

Comments

I tried it, didn't work, so I edited my question.
Javier Romero gravatar image Javier Romero  ( 2011-04-29 06:53:34 -0600 )edit

Question Tools

Stats

Asked: 2011-04-28 09:35:06 -0600

Seen: 1,979 times

Last updated: Jul 19 '11