Problem with message_filters::cache
#include "ros/ros.h" #include "ros/message_traits.h" #include "message_filters/subscriber.h" #include "message_filters/cache.h" #include "std_msgs/String.h"
message_filters::Cache<std_msgs::String> cache;
void some_function (const std_msgs::String::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("/chatter", 1, some_function);
ros::spin();
return 0;
}
when building through catkin_make I get errors:
In file included from /home/great_user/catkin_ws/src/marker/src/newOrganization.cpp:4:0:
/opt/ros/melodic/include/message_filters/cache.h: In instantiation of ‘ros::Time message_filters::Cache<m>::getOldestTime() const [with M = std_msgs::String_<std::allocator<void> >]’:
/home/great_user/catkin_ws/src/marker/src/newOrganization.cpp:13:66: required from here
/opt/ros/melodic/include/message_filters/cache.h:321:44: error: ‘value’ is not a member of
‘ros::message_traits::TimeStamp<std_msgs::string_<std::allocator<void> >, void>’
oldest_time = mt::TimeStamp<m>::value(cache_.front().getMessage());
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /opt/ros/melodic/include/message_filters/cache.h: In instantiation of ‘ros::Time
message_filters::Cache<m>::getLatestTime() const [with M = std_msgs::String_<std::allocator<void> >]’:
/home/great_user/catkin_ws/src/marker/src/newOrganization.cpp:14:66: required from here
/opt/ros/melodic/include/message_filters/cache.h:304:44: error: ‘value’ is not a member of
‘ros::message_traits::TimeStamp<std_msgs::string_<std::allocator<void> >, void>’
latest_time = mt::TimeStamp<m>::value(cache_.back().getMessage());
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /opt/ros/melodic/include/message_filters/cache.h: In instantiation of ‘void
message_filters::Cache<m>::add(const EventType&) [with M = std_msgs::String_<std::allocator<void> >;
message_filters::Cache<m>::EventType = ros::MessageEvent<const std_msgs::string_<std::allocator<void=""> > >]’:
/opt/ros/melodic/include/message_filters/cache.h:121:8: required from ‘void
message_filters::Cache<m>::add(const MConstPtr&) [with M = std_msgs::String_<std::allocator<void> >;
message_filters::Cache<m>::MConstPtr = boost::shared_ptr<const std_msgs::string_<std::allocator<void=""> > >]’
/home/great_user/catkin_ws/src/marker/src/newOrganization.cpp:11:18: required from here
/opt/ros/melodic/include/message_filters/cache.h:146:52: error: ‘value’ is not a member of
‘ros::message_traits::TimeStamp<std_msgs::string_<std::allocator<void> >, void>’
ros::Time evt_stamp = mt::TimeStamp<m>::value(evt.getMessage());
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
/opt/ros/melodic/include/message_filters/cache.h:147:63: error: ‘value’ is not a member of
‘ros::message_traits::TimeStamp<std_msgs::string_<std::allocator<void> >, void>’
while(rev_it != cache_.rend() && mt::TimeStamp<m>::value((rev_it).getMessage()) > evt_stamp)
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
marker/CMakeFiles/organize.dir/build.make:62: recipe for target 'marker/CMakeFiles/organize.dir
/src/newOrganization.cpp.o' failed
make[2]: [marker/CMakeFiles/organize.dir/src/newOrganization.cpp.o] Error 1
CMakeFiles/Makefile2:2222: recipe for target 'marker/CMakeFiles/organize.dir/all' failed
make[1]: [marker/CMakeFiles/organize.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: ** [all] Error 2Invoking "make -j4 -l4" failed
I tried so
int main(int argc, char **argv) {
ros::init(argc, argv, "caching_example");
ros::NodeHandle nh;
cache.setCacheSize(100);
message_filters::Subscriber<marker::mkzBlaFeedbackBla> subs (nh,"/test",10);
message_filters ...