Ask Your Question

Revision history [back]

tl;dr: you create a special message_filters.Subscriber, which you pass to message_filters.Cache. This will cause the Cache to be updated with every incoming message. In addition, you register your own callback (ie: self.ReturnRateData) that also gets called for every new incoming message.

But that callback is a regular ROS subscribers callback, so it receives the message that was received by the special Subscriber you created earlier.

In your callback signature, you call that argument Cache, and treat it as if it is the message_filters.Cache instance (by calling getElemBeforeTime(..) on it.

That won't work, as it's actually a PoseStamped message.

You'll have to keep a reference to cache around and access that.


Longer: you have this:

self.sub = message_filters.Subscriber('/vrpn_client_node/TestTed/pose',PoseStamped)
cache = message_filters.Cache(self.sub, 2,allow_headerless=False)
cache.registerCallback(self.ReturnRateData)

[..]

def ReturnRateData(self, Cache):
  self.rate_previous = Cache.getElemBeforeTime(Cache.getOldestTime())
  self.rate_current = Cache.getElemAfterTime(Cache.getLatestTime())
  [..]

The Cache argument that ReturnRateData(..) receives is not a message_filters.Cache, but a PoseStamped.

This is described on the wiki page of message_filters (here):

sub = message_filters.Subscriber('my_topic', sensor_msgs.msg.Image)
cache = message_filters.Cache(sub, 100)

In this example, the Cache stores the last 100 messages received on my_topic, and myCallback is called on the addition of every new message. The user can then make calls like cache.getInterval(start, end) to extract part of the cache.

And from the Message Filters API documentation (here):

message_filters.Subscriber.registerCallback(cb, *args)

Register a callback function cb to be called when this filter has output. The filter calls the function cb with a filter-dependent list of arguments, followed by the call-supplied arguments args.

tl;dr: you create a special message_filters.Subscriber, which you pass to message_filters.Cache. This will cause the Cache to be updated with every incoming message. In addition, you register your own callback (ie: self.ReturnRateData) that also gets called for every new incoming message.

But that callback is a regular ROS subscribers callback, so it receives the message that was received by the special Subscriber you created earlier.

In your callback signature, you call that argument Cache, and treat it as if it is the message_filters.Cache instance (by calling getElemBeforeTime(..) on it.it).

That won't work, as it's actually a PoseStampedgeometry_msgs.PoseStamped message.

You'll have to keep a reference to cache around and access that.


Longer: you have this:

self.sub = message_filters.Subscriber('/vrpn_client_node/TestTed/pose',PoseStamped)
cache = message_filters.Cache(self.sub, 2,allow_headerless=False)
cache.registerCallback(self.ReturnRateData)

[..]

def ReturnRateData(self, Cache):
  self.rate_previous = Cache.getElemBeforeTime(Cache.getOldestTime())
  self.rate_current = Cache.getElemAfterTime(Cache.getLatestTime())
  [..]

The Cache argument that ReturnRateData(..) receives is not a message_filters.Cache, but a PoseStamped.

This is described on the wiki page of message_filters (here):

sub = message_filters.Subscriber('my_topic', sensor_msgs.msg.Image)
cache = message_filters.Cache(sub, 100)

In this example, the Cache stores the last 100 messages received on my_topic, and myCallback is called on the addition of every new message. The user can then make calls like cache.getInterval(start, end) to extract part of the cache.

And from the Message Filters API documentation (here):

message_filters.Subscriber.registerCallback(cb, *args)

Register a callback function cb to be called when this filter has output. The filter calls the function cb with a filter-dependent list of arguments, followed by the call-supplied arguments args.

tl;dr: you create a special message_filters.Subscriber, which you pass to message_filters.Cache. This will cause the Cache to be updated with every incoming message. In addition, you register your own callback (ie: self.ReturnRateData) that also gets called for every new incoming message.

But that callback is a regular ROS subscribers callback, so it receives the message that was received by the special Subscriber you created earlier.

In your callback signature, you call that argument Cache, and treat it as if it is the message_filters.Cache instance (by calling getElemBeforeTime(..) on it).

That won't work, as it's actually a geometry_msgs.PoseStamped message.message (that was just received).

You'll have to keep a reference to cache around and access that. in your ReturnRateData(..) (perhaps store your Cache instance as a member variable of your OptitrackReceive class).


Longer: you have this:

def __init__(self):
  [..]
  self.sub = message_filters.Subscriber('/vrpn_client_node/TestTed/pose',PoseStamped)
 cache = message_filters.Cache(self.sub, 2,allow_headerless=False)
 cache.registerCallback(self.ReturnRateData)

[..]

def ReturnRateData(self, Cache):
  self.rate_previous = Cache.getElemBeforeTime(Cache.getOldestTime())
  self.rate_current = Cache.getElemAfterTime(Cache.getLatestTime())
  [..]

The Cache argument that ReturnRateData(..) receives is not a message_filters.Cache, but a PoseStamped.

This is described on the wiki page of message_filters (here):

sub = message_filters.Subscriber('my_topic', sensor_msgs.msg.Image)
cache = message_filters.Cache(sub, 100)

In this example, the Cache stores the last 100 messages received on my_topic, and myCallback is called on the addition of every new message. The user can then make calls like cache.getInterval(start, end) to extract part of the cache.

And from the Message Filters API documentation (here):

message_filters.Subscriber.registerCallback(cb, *args)

Register a callback function cb to be called when this filter has output. The filter calls the function cb with a filter-dependent list of arguments, followed by the call-supplied arguments args.