• ROS


    1.Time Synchronizer 时间同步器

    2.Policy-Based Synchronizer基于策略的同步器

    2.1ExactTime策略

    message_filters :: sync_policies :: ExactTime策略要求消息具有完全相同的时间戳以便匹配。 只有在具有相同确切时间戳的所有指定通道上收到消息时,才会调用回调。 从所有消息的头域读取时间戳(这是该策略所必需的)。
    C++头文件:message_filters/sync_policies/exact_time.h

      ros::NodeHandle nh;
      message_filters::Subscriber<Image> image_sub(nh, "image", 1);
      message_filters::Subscriber<CameraInfo> info_sub(nh, "camera_info", 1);
    
      typedef sync_policies::ExactTime<Image, CameraInfo> MySyncPolicy;
      // ExactTime takes a queue size as its constructor argument, hence MySyncPolicy(10)
      Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), image_sub, info_sub);
      sync.registerCallback(boost::bind(&callback, _1, _2));

    2.2ApproximateTime 策略

    message_filters :: sync_policies :: ApproximateTime策略使用自适应算法来匹配基于其时间戳的消息。
    如果不是所有的消息都有一个标题字段,从中可以确定时间戳,请参见下面的解决方法。
    C++头文件:message_filters/sync_policies/approximate_time.h

        ros::NodeHandle nh;
    
        message_filters::Subscriber<sensor_msgs::Image> left_sub(nh, "/camera/left/image_raw", 1);
        message_filters::Subscriber<sensor_msgs::Image> right_sub(nh, "/camera/right/image_raw", 1);
        typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, sensor_msgs::Image> sync_pol;
    // ApproximateTime takes a queue size as its constructor argument, hencesync_po(10)
    message_filters::Synchronizer<sync_pol> sync(sync_pol(10), left_sub,right_sub);
    //(&igb)->ImageGrabber::GrabStereo(left_sub,right_sub)
    sync.registerCallback(boost::bind(&ImageGrabber::GrabStereo,&igb,_1,_2));

    如果某些消息的类型不包含头字段,则ApproximateTimeSynchronizer默认拒绝添加此类消息。 但是,它的Python版本可以用allow_headerless = True来构造,它使用当前的ROS时间代替任何缺少的header.stamp字段:

    from std_msgs.msg import Int32, Float32
    
    def callback(mode, penalty):
      # The callback processing the pairs of numbers that arrived at approximately the same time
    
    mode_sub = message_filters.Subscriber('mode', Int32)
    penalty_sub = message_filters.Subscriber('penalty', Float32)
    
    ts = message_filters.ApproximateTimeSynchronizer([mode_sub, penalty_sub], 10, 0.1, allow_headerless=True)
    ts.registerCallback(callback)
  • 相关阅读:
    未能加载文件或程序集“file:///C:Program Files (x86)SAP BusinessObjectsCrystal Reports for .NET Framework 4.0
    iwms后台出现从客户端(ctl00$cphMain$logo="<img src="pic/logo.g...")中检测到有潜在危险的 Request.Form 值。错误解决方法
    Socket层实现系列 — accept()的实现(二)
    Socket层实现系列 — accept()的实现(一)
    Socket层实现系列 — getsockname()和getpeername()的实现
    洛谷1279 字串距离
    poj 2411
    poj 2411
    noip提高组 2010 关押罪犯 (洛谷1525)
    二分图匹配 (匈牙利算法) 洛谷3386
  • 原文地址:https://www.cnblogs.com/hitzzq/p/14663199.html
Copyright © 2020-2023  润新知