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

Revision history [back]

click to hide/show revision 1
initial version

Thanks a lot for your help. Now it works :)

What's important for everyone who has the same problem:

Don't forget to add these lines to your CMakeLists.txt

rosbuild_add_boost_directories()
rosbuild_link_boost(YOUR_PACKAGE_NAME thread signals system)

You also need to add the following to your manifest.xml

<depend package="message_filters"/>
click to hide/show revision 2
added a working example

Thanks a lot for your help. Now it works :)

What's important for everyone who has the same problem:

Don't forget to add these lines to your CMakeLists.txt

rosbuild_add_boost_directories()
rosbuild_link_boost(YOUR_PACKAGE_NAME thread signals system)

You also need to add the following to your manifest.xml

<depend package="message_filters"/>

I also rearranged my code a little bit because i wasn't able to access the cache otherwise. The following now works:

#include <ros/ros.h>
#include <message_filters/subscriber.h>
#include <message_filters/cache.h>
#include <geometry_msgs/PoseStamped.h>

message_filters::Cache<geometry_msgs::PoseStamped> cache;

void some_function (const geometry_msgs::PoseStamped::ConstPtr &msg)
{
    cache.add(msg);

    std::cout << "Oldest time cached is " << cache.getOldestTime() << std::endl;
    std::cout << "Last time received is " << cache.getLatestTime() << std::endl << std::endl;
}

int main(int argc, char **argv) {
  ros::init(argc, argv, "caching_example");
  ros::NodeHandle nh;

  cache.setCacheSize(100);
  ros::Subscriber sub = nh.subscribe("/some_topic", 1, some_function);

  ros::spin();
  return 0;
}