【问题标题】:ROS message_filters::TimeSequencerROS message_filters::TimeSequencer
【发布时间】:2015-12-16 21:05:02
【问题描述】:

我正在尝试延迟处理通过 ros 主题收到的一些输入,并且当我阅读 message_filters 包信息时,TimeSequencer 似乎就是这样做的。

它们甚至包括一些我复制的示例代码,但无法让它编译。我在这里粘贴了产生错误的小测试程序:

#include "ros/ros.h"
#include <message_filters/subscriber.h>
#include <message_filters/time_sequencer.h>
#include <std_msgs/String.h>

void callback(const std_msgs::String& info)
{
  //do some processing
} 

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

  message_filters::Subscriber<std_msgs::String> sub(n, "my_topic", 1);
  message_filters::TimeSequencer<std_msgs::String> seq(sub, ros::Duration(0.1), ros::Duration(0.01), 10);
  seq.registerCallback(callback);

  ros::spin();

  return 0;
}

错误发生在seq.registerCallback(callback);

In file included from /opt/ros/hydro/include/message_filters/subscriber.h:44:0,
                 from /home/j/workspace/src/test.cpp:17:
/opt/ros/hydro/include/message_filters/simple_filter.h: In member function message_filters::Connection message_filters::SimpleFilter<M>::registerCallback(void (*)(P)) [with P = const std_msgs::String_<std::allocator<void> >&, M = std_msgs::String_<std::allocator<void> >]:
/home/j/workspace/src/test.cpp:39:32:   instantiated from here
/opt/ros/hydro/include/message_filters/simple_filter.h:96:100: error: no matching function for call to message_filters::Signal1<std_msgs::String_<std::allocator<void> > >::addCallback(void (*&)(const std_msgs::String_<std::allocator<void> >&))
/opt/ros/hydro/include/message_filters/simple_filter.h:96:100: note: candidate is:
/opt/ros/hydro/include/message_filters/signal1.h:91:22: note: template<class P> message_filters::Signal1<M>::CallbackHelper1Ptr message_filters::Signal1::addCallback(const boost::function<void(P)>&) [with P = P, M = std_msgs::String_<std::allocator<void> >, message_filters::Signal1<M>::CallbackHelper1Ptr = boost::shared_ptr<message_filters::CallbackHelper1<std_msgs::String_<std::allocator<void> > > >]

我已经用 TimeSequencer 搜索了很多示例,但实际上找不到太多。非常感谢任何帮助。

【问题讨论】:

    标签: c++ ros


    【解决方案1】:

    与 ros::NodeHandle::subscribe() 不同,message_filters 类需要回调采用 boost::shared_ptr。

    在此处查看文档: http://wiki.ros.org/message_filters#Time_Sequencer

    void callback(const boost::shared_ptr<std_msgs::String>& info);
    

    或者你可以使用 ConstPtr typedef:

    void callback(const std_msgs::StringConstPtr& info);
    

    【讨论】:

    • @Watts,我面临着类似的问题。我使用了这段代码 sn-p 并将解决方案放入其中,但它仍然给我同样的错误。
    • @Watts 它对我也不起作用,我在这里描述了我的代码:stackoverflow.com/questions/62345576/…
    • @TonyParker 你找到解决方案了吗?
    【解决方案2】:
    #include <ros/ros.h>
    #include <geometry_msgs/PoseStamped.h>
    #include "image_transport/image_transport.h"
    #include "cv_bridge/cv_bridge.h"
    #include "message_filters/subscriber.h"
    #include "message_filters/synchronizer.h"
    #include "message_filters/time_synchronizer.h"
    #include "message_filters/sync_policies/exact_time.h"
    #include <message_filters/sync_policies/approximate_time.h>
    using namespace sensor_msgs;
    using namespace message_filters;
    
    class SubscribeAndPublish
    {
    public:
    void callback(const sensor_msgs::ImageConstPtr& msg,const sensor_msgs::ImageConstPtr& msg2)
    {}
    public:
    SubscribeAndPublish():sync2(image_sub,image_sub2,500){
        //https://gist.github.com/tdenewiler/e2172f628e49ab633ef2786207793336
        image_sub.subscribe(n, "/camera/color/image_raw", 1);
        image_sub2.subscribe(n, "/camera/aligned_depth_to_color/image_raw", 1);
        sync2.registerCallback(boost::bind(&SubscribeAndPublish::callback,this, _1, _2));
        odom_pub = n.advertise<nav_msgs::Odometry>("RGBDodom", 50);
    }
    private:
    ros::NodeHandle n;
    ros::Publisher odom_pub;
    message_filters::Subscriber<Image> image_sub;
    message_filters::Subscriber<Image> image_sub2;
    TimeSynchronizer<Image, Image> sync2;
    };
    

    试试上面的代码

    【讨论】:

    猜你喜欢
    • 2022-09-27
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-09
    相关资源
    最近更新 更多