Ask Your Question

Problem with message_filters::cache

asked 2018-11-08 05:24:40 -0500

D0l0RES gravatar image

updated 2018-11-11 23:36:28 -0500

#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)

    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;

  ros::Subscriber sub = nh.subscribe("/chatter", 1, some_function);

  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(
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /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
[marker/CMakeFiles/organize.dir/src/newOrganization.cpp.o] Error 1
CMakeFiles/Makefile2:2222: recipe for target 'marker/CMakeFiles/organize.dir/all' failed
[marker/CMakeFiles/organize.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *
* [all] Error 2

Invoking "make -j4 -l4" failed

I tried so

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

message_filters::Subscriber<marker::mkzBlaFeedbackBla> subs (nh,"/test",10);
message_filters ...
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-11-08 05:41:28 -0500

gvdhoorn gravatar image

updated 2018-11-12 02:32:43 -0500

message_filters classes can only be used with messages that have Headers (in principle). std_msgs/String doesn't have a header.

See #q60568 and #q197811 for two previous questions about this.

Edit: to work-around this, Cache supports Headerless messages: see the last section of the documentation of message_filters/Cache. Unfortunately:

This is currently only available in Python.


the error remains

the text of the message, then compiled into the header

float32 batteryCharge
float32 batteryVoltage
float32 chargeCurrentOfTheBattery
bool routingTaskReady
bool routingTaskDownload
bool readiness
uint8 errorCode

I don't know what you mean by "compiled into the header", but the issue would appear to be that your message doesn't contain a field called header of type std_msgs/Header.

The header field would contain the stamp, which is the timestamp that message_filters needs.

edit flag offensive delete link more


thanks I understand

D0l0RES gravatar image D0l0RES  ( 2018-11-08 06:06:54 -0500 )edit

I have a message that has its header file, I added it and still the error persists

D0l0RES gravatar image D0l0RES  ( 2018-11-08 06:25:21 -0500 )edit

If you've changed your code/setup/build then I would suggest to update your question text to show exactly what you're doing now. Otherwise we cannot help you.

Do not overwrite your current question. Just edit it and append the new information.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-08 09:05:00 -0500 )edit

@gvdhoorn, added a new version of the code

D0l0RES gravatar image D0l0RES  ( 2018-11-11 23:31:56 -0500 )edit

@gvdhoorn, I created my custom message (msg).it's called mkzBlaFeedbackBla and he msg file contains the packet marker. Then I added my Cmake name to my message and got a header. and then I use it in my code to receive and receive messages.

D0l0RES gravatar image D0l0RES  ( 2018-11-12 03:18:48 -0500 )edit

That sounds all fine, but the problem is with the .msg file. It does not contain a field with the name header and with the type std_msgs/Header. The problem is not with a C++ header file.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-12 10:32:57 -0500 )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

1 follower


Asked: 2018-11-08 05:24:40 -0500

Seen: 839 times

Last updated: Nov 12 '18