![cd9bb2e45387b9a2520a85efcb3cb5ea.png](https://img-blog.csdnimg.cn/img_convert/cd9bb2e45387b9a2520a85efcb3cb5ea.png)
cartographer一般可以分为四个部分:1.前端匹配。2.后端优化。3.建图。4.回环检测。所以针对源码,也从前端匹配开始讲起吧。
1.前端匹配
1.1.main(http://node_main.cc)
直接从main函数开始!这里只需要关注cartographer_ros::Run()这个函数。其余函数都是用于装载参数、初始化ros节点和初始化日志信息,与算法本身关系并不大。
1.2.cartographer_ros::Run(http://node_main.cc)
先初始化了tf订阅器、参数器,然后最重要的是构造了Node这个类的对象,并将tf订阅器与参数器作为参数传进Node的构造函数中。
1.3.node构造函数(http://node.cc)
这个构造函数先是初始化五个话题发布器(具体内容看注释):
//用于发布存有submap的列表
submap_list_publisher_ =
node_handle_.advertise<::cartographer_ros_msgs::SubmapList>(
kSubmapListTopic, kLatestOnlyPublisherQueueSize);
//用于发布轨迹,一条轨迹通常包含各个位置的传感器信息
trajectory_node_list_publisher_ =
node_handle_.advertise<::visualization_msgs::MarkerArray>(
kTrajectoryNodeListTopic, kLatestOnlyPublisherQueueSize);
//用于发布存有地标landmark的位姿的列表
landmark_poses_list_publisher_ =
node_handle_.advertise<::visualization_msgs::MarkerArray>(
kLandmarkPosesListTopic, kLatestOnlyPublisherQueueSize);
//用于发布存有约束关系的列表
constraint_list_publisher_ =
node_handle_.advertise<::visua