(02) Cartographer source code analysis without dead ends - (61) 2D backend optimization→

Explanation of a series of articles about slam summary links: the most complete slam in history starts from scratch , for this column to explain (02) Analysis of Cartographer source code without dead ends - the link is as follows:
(02) Analysis of Cartographer source code without dead ends - (00) Catalog_Latest None Dead corner explanation: https://blog.csdn.net/weixin_43013761/article/details/127350885
 
The center at the bottom of the article provides my contact information, click on my photo to display WX → official certification{\color{blue}{right below the end of the article Center} provides my \color{red} contact information, \color{blue} clicks on my photo to display WX→official certification}At the bottom of the article, the center provides my contact information. Click on my photo to display W XOfficial certification
 

I. Introduction

Through the previous two blogs, I already know how to use the thread pool in Cartographer and add tasks to the thread pool. Before reviewing the code, here are the previous two points of doubt:

Question 1: \color{red}Question 1:Question 1: global_submap_poses is equivalent to when PoseGraph2D::data_.global_submap_poses_2d is optimized.
Question 2: \color{red}Question 2:Question 2: Why wait for the constraint calculation to be completed before calling PoseGraph2D::HandleWorkQueue(), and how the source code is implemented.

Then review the following code in src/cartographer/cartographer/mapping/internal/2d/pose_graph_2d.cc:

NodeId PoseGraph2D::AddNode(......, const std::vector<std::shared_ptr<const Submap2D>>& insertion_submaps){
    
    
	......
  // 向节点列表加入节点,并得到节点的id
  const NodeId node_id = AppendNode(constant_data, trajectory_id,
                                    insertion_submaps, optimized_pose);
  ......
  // 把计算约束的工作放入workitem中等待执行
  AddWorkItem([=]() LOCKS_EXCLUDED(mutex_) {
    
    
    return ComputeConstraintsForNode(node_id, insertion_submaps,
                                     newly_finished_submap);
  });
  return node_id;
}

It seems relatively simple, is to build a work item, the content of the work item is to execute the ComputeConstraintsForNode () function. Then add the work item to PoseGraph2D::work_queue_ by AddWorkItem. It should be noted that there is at most one thread processing the PoseGraph2D::work_queue_ queue. This thread mainly deals with the calculation of PoseGraph2D. If PoseGraph2D::work_queue_ is consumed, the thread will perform other tasks (the thread is not over. ), if subsequent PoseGraph2D::work_queue_ has new data, another thread will be allocated for alignment until the data is processed.

Work items stored in PoseGraph2D::work_queue_ contain many types, as follows:

PoseGraph2D::AddImuData(......)  // 把imu数据加入到优化问题中
PoseGraph2D::AddOdometryData(......) // 把里程计数据加入到优化问题中
PoseGraph2D::AddFixedFramePoseData() // 把gps数据加入到优化问题中
PoseGraph2D::AddLandmarkData() //把landmark数据加入到data_.landmark_nodes中 这个工作项放入到队列中
PoseGraph2D::DeleteTrajectory() //删除轨迹相关的一些工作项
......

The above functions will call the PoseGraph2D::AddWorkItem() function to add work items to the queue.

2. Foreword

Guess you like

Origin blog.csdn.net/weixin_43013761/article/details/130723891