message_filter同步频率不同的传感器,不进回调
-
想用message_filter同步两个传感器的消息,程序订阅同一节点时间戳肯定相同,没问题进回调了。但订阅频率不同的传感器,就有问题了,该怎么改?
class MultiSubscriber : public rclcpp::Node
{
public:
message_filters::Subscriber<sensor_msgs::msg::LaserScan> image_sub_; message_filters::Subscriber<sensor_msgs::msg::LaserScan> disparity_sub_;MultiSubscriber(const std::string& name) : Node(name) { image_sub_.subscribe(this, "scan", rmw_qos_profile_sensor_data); disparity_sub_.subscribe(this, "scan", rmw_qos_profile_sensor_data); typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::msg::LaserScan, sensor_msgs::msg::LaserScan> approximate_policy; static message_filters::Synchronizer<approximate_policy>syncApproximate(approximate_policy(100), disparity_sub_, image_sub_); syncApproximate.registerCallback(&MultiSubscriber::disparityCb,this); } private: void disparityCb(const sensor_msgs::msg::LaserScan::SharedPtr disparity_msg, const sensor_msgs::msg::LaserScan::SharedPtr color_msg) { cout << "Recieved" << endl; }
};
int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
auto timestamp = std::make_shared<MultiSubscriber>("timestamp");
rclcpp::spin(timestamp);
rclcpp::shutdown();
return 0;
} -
@2960084565 建议检查时间参数,还有就是同步策略问题approximate_policy(100) 是否合适
-
@小鱼 时间参数?检查msg->header.stamp消息时间戳?
同步策略approximate近似同步感觉很适合,比严格同步条件要宽松很多,缓存队列也只是自认为10比较少才调得100 -
@2960084565 在 message_filter同步频率不同的传感器,不进回调 中说:
检查msg->header.stamp消息时间戳?
是的,策略再放松,可能是你这两个话题的stamp差距太大