在amcl的构造函数中有这几行代码
std::shared_ptr<tf2_ros::TransformBroadcaster> tfb_;
std::shared_ptr<tf2_ros::TransformListener> tfl_;
std::shared_ptr<tf2_ros::Buffer> tf_;
tfb_.reset(new tf2_ros::TransformBroadcaster());
tf_.reset(new tf2_ros::Buffer());
tfl_.reset(new tf2_ros::TransformListener(*tf_));
laser_scan_sub_ = new message_filters::Subscriber<sensor_msgs::LaserScan>(nh_, scan_topic_, 100);
laser_scan_filter_ =
new tf2_ros::MessageFilter<sensor_msgs::LaserScan>(*laser_scan_sub_,
*tf_,
odom_frame_id_,
100,
nh_);
laser_scan_filter_->registerCallback(boost::bind(&AmclNode::laserReceived,
this, _1));
首先是定义了三个智能指针,并指向堆空间中的函数入口。在将消息过滤器的地址赋给laser_scan_sub_,再此处,可以把tf2_ros::MessageFilter这个类看作是message_filters::Subscriber类的继承,并且集合了tf变换,因此需要将原始消息过滤器的地址与tf进行绑定。之后再用registerCallback进行注册回调函数laserReceived。