0
$\begingroup$

Rosanswers logo

#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::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::value(*cache_.front().getMessage());
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /opt/ros/melodic/include/message_filters/cache.h: In instantiation of ‘ros::Time
message_filters::Cache::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::value(*cache_.back().getMessage());
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /opt/ros/melodic/include/message_filters/cache.h: In instantiation of ‘void
message_filters::Cache::add(const EventType&) [with M = std_msgs::String_std::allocator<void >;
message_filters::Cache::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::add(const MConstPtr&) [with M = std_msgs::String_std::allocator<void >;
message_filters::Cache::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::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::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 2
Invoking "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::Cache<marker::mkzBlaFeedbackBla> cache(subs, 100);

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

ros::spin();
return 0
} 

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


Originally posted by D0l0RES on ROS Answers with karma: 23 on 2018-11-08

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Edit:

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.


Originally posted by gvdhoorn with karma: 86574 on 2018-11-08

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by D0l0RES on 2018-11-08:
thanks I understand

Comment by D0l0RES on 2018-11-08:
I have a message that has its header file, I added it and still the error persists

Comment by gvdhoorn on 2018-11-08:
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.

Comment by D0l0RES on 2018-11-12:
@gvdhoorn, added a new version of the code

Comment by D0l0RES on 2018-11-12:
@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.

Comment by gvdhoorn on 2018-11-12:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.