Ask Your Question

access message filters cache data in python

asked 2014-08-23 13:24:29 -0600

raminzohouri gravatar image

updated 2014-08-23 13:30:52 -0600

Hi all

I am suing message filters cache in my little python code but I couldn't figure out to access the cache data. It seems the python version has not function cache.getInterval(start, end).

in tutorial there is only c++ example seems to have the function but the python version doesn't.

Could anyone please tell me how can I possibly access the cache data.

Here is the is my code

class EegListener(object):

 def __init__(self):

     self.eeg_subscriber = message_filters.Subscriber("/eeg_signal_packet", EegPacket)
             # the topick contains Header type and float64[] type
     self.eeg_cache = message_filters.Cache(self.eeg_subscriber, 1280)

 def callback(self,eeg_msg):                 
             print eeg_msg.header 
 def listener(self):
             #  self.eeg_cache.getInterval(rospy.get_rostime(),rospy.get_rostime()) does not exists !?
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-08-23 15:08:00 -0600

ahendrix gravatar image

updated 2014-08-23 15:08:18 -0600

Yes, this appears to be broken.

The current version of the Cache synchronizer has a TODO instead of actually maintaining a cache: message_filters/

You should probably file this as a bug against ros_comm:

edit flag offensive delete link more


Hey Austin

Thank you very much for your reply. I will report the issue for sure. At the mean time I have implemented the C++ version of the message filters cache. it looks find except that I have some packet lost in between. I am publishing a message with header and there I have 128Hz frequency but when I am reading cache with :

  1. start_time = ros::Time::now();
  2. cache.getInterval(start_time - ros::Duration(1), start_time).size()

The vector has size of 107-115. When I only subscribe and print it also seems fine. Are there any packet lost of I just need to increase the duration to get full cycle that i publish ?

raminzohouri gravatar image raminzohouri  ( 2014-08-24 02:27:14 -0600 )edit

ROS is designed to drop packets when a topic is saturated, so it's quite possible that it's losing a few. The only way to really know is to analyze the message sequence numbers to see if any messages are missing.

ahendrix gravatar image ahendrix  ( 2014-08-24 03:42:53 -0600 )edit

I did so and it keep losing around 20 packets that are important for me.. actually I am trying to make emokit signals in available in ros... I can publish the message but the points is each message contains one packet and the sampling frequency for the device is 128Hz. Publisher does not lose any packet, also the subscriber.

But i need to queue 10 second of these packets and lose a service ros service to access the desired interval. Do you have any suggestion about how to do this ?

Boost::circularBuffer is the thing i am trying to use for queuing messages at moment .

raminzohouri gravatar image raminzohouri  ( 2014-08-24 04:08:09 -0600 )edit

You may want to try increasing the publisher and subscriber queue sizes to see if that helps prevent dropping messages.

ahendrix gravatar image ahendrix  ( 2014-08-24 04:53:08 -0600 )edit

Thanks for the reply I did so and now I am publishing the packets getting them from cache .... the code is looks like this now and I am using a service to read from the new topic... I hope this code is optimal ?


eeg_packet_buffer; ros::Publisher
eeg_packet_buffer_pub ;

void some_function (const
&msg) {

eeg_cache_vector =
       for(uint i = 0; i < eeg_cache_vector.size(); ++i){*eeg_cache_vector[i]);

int main(int argc, char **argv) {  
ros::init(argc, argv,
ros::NodeHandle nh;  
ros::Subscriber sub =
256 , some_function);  
eeg_packet_buffer_pub = 
ros::spin();   return 0; }`
raminzohouri gravatar image raminzohouri  ( 2014-08-24 08:05:17 -0600 )edit

@raminzohouri: I think it would be better if you update your original question. The comment area is just that: for short comments. Seeing as your original question was answered by @ahendrix though, you might want to create a new one (for your problem with msg loss).

gvdhoorn gravatar image gvdhoorn  ( 2014-08-24 09:42:08 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2014-08-23 13:21:10 -0600

Seen: 851 times

Last updated: Aug 23 '14