ros2消息时间同步与回调_sync.registercallback,回调函数不回调

关键词ros2、zed、时间同步、ApproximateTime

问题1.怎么写的都不调用回调函数,
排查方向,回调函数的参数列表和输入是否一致,话题对应的数据类型和subscribe定义的是否一致,这两个是最重要的
其次还有容错时间、话题是否有效等等粗心大意的问题都是排查方向,最后我的问题是应该在头文件里的类里就定义

message_filters::Subscriber<sensor_msgs::msg::Image> left_sub_m;
message_filters::Subscriber<sensor_msgs::msg::Image> depth_sub_m;

一开始把订阅者在实现中定义而不是在头文件声明中定义
  message_filters::Subscriber<sensor_msgs::msg::Image> left_sub_m;
  message_filters::Subscriber<sensor_msgs::msg::Image> depth_sub_m;
  
    left_sub_m.subscribe(this, "/zed/zed_node/left/image_rect_color");
    depth_sub_m.subscribe(this, "/zed/zed_node/depth/depth_registered");


    //使用 message_filters 中的 ApproximateTime 策略进行左右图像和深度图像的近似时间同步,该策略将根据消息的时间戳匹配近似时间的左右图像和深度图像
	typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::msg::Image, sensor_msgs::msg::Image> approximate_policy;
	//使用 Synchronizer 类创建一个同步器,并传入 ApproximateTime 策略和左右图像的订阅器允许消息在时间上有一定的误差(这里设置为100毫秒)
    static message_filters::Synchronizer<approximate_policy> syncApproximate(approximate_policy(100), left_sub_m, depth_sub_m);
    //通过syncApproximate.setMaxIntervalDuration方法设置同步器的最大时间间隔,这里设置为3// syncApproximate.setMaxIntervalDuration(rclcpp::Duration(3,0)); 
    //使用 registerCallback 方法注册一个回调函数,该回调函数会在近似时间同步成功后被调用。在回调函数中调用 GrabDepth 方法处理左右图像和深度图像数据
    syncApproximate.registerCallback(std::bind(&ObjectDetectionNode::GrabDepth_callback, this,std::placeholders::_1, std::placeholders::_2));

我的解决方法仅供参考
https://wiki.ros.org/message_filters
https://www.cnblogs.com/RobustFresher/p/13182645.html

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值