Cartographer-[4]-从node_main.cc开始

Catalogue
  1. 1. 1. 从node_main.cc开始
  2. 2. 2. demo_backpack_2d.launch
  3. 3. 3. backpack_2d.launch
  4. 4. 4. 继续node_main.cc
    1. 4.1. 4.1. int main()
    2. 4.2. 4.2. cartographer_ros::Run()
  5. 5. 5. Google自己定义的Node节点(类)

1. 从node_main.cc开始

虽说从node_main.cc开始,但是,实际上还是从demo开始吧

2. demo_backpack_2d.launch

官方的demo启动如下:

2D:

1
2
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag

可以发现,主要是启动了demo_backpack_2d.launch文件,该文件内容如下:

1
2
3
4
5
6
7
8
9
10
<launch>
<param name="/use_sim_time" value="true" />

<include file="$(find cartographer_ros)/launch/backpack_2d.launch" />

<node name="rviz" pkg="rviz" type="rviz" required="true"
args="-d $(find cartographer_ros)/configuration_files/demo_2d.rviz" />
<node name="playbag" pkg="rosbag" type="play"
args="--clock $(arg bag_filename)" />
</launch>

该launch文件实现了

  • 调用backpack_2d.launch文件
  • 启动rviz
  • 使用playbag进行数据包回放

3. backpack_2d.launch

接下来,继续跟踪backpack_2d.launch文件,该文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<launch>
<param name="robot_description"
textfile="$(find cartographer_ros)/urdf/backpack_2d.urdf" />

<node name="robot_state_publisher" pkg="robot_state_publisher"
type="robot_state_publisher" />

<node name="cartographer_node" pkg="cartographer_ros"
type="cartographer_node" args="
-configuration_directory $(find cartographer_ros)/configuration_files
-configuration_basename backpack_2d.lua"
output="screen">
<remap from="echoes" to="horizontal_laser_2d" />
</node>

<node name="cartographer_occupancy_grid_node" pkg="cartographer_ros"
type="cartographer_occupancy_grid_node" args="-resolution 0.05" />
</launch>

backpack_2d.launch文件实现了

  • 启动robot_state_publisher节点,发布TF变换
  • 启动了cartographer_node节点,传入lua文件进行参数加载configuration_files/backpack_2d.lua
  • 启动了cartographer_occupancy_grid_node节点,传入分辨率参数-resolution 0.05

4. 继续node_main.cc

上面的launch文件最终启动了Cartographer_ros节点,而这个主节点在node_main.cc启动。

4.1. int main()

  1. 初始化google的日志输出
  2. 初始化节点"cartographer_node"
  3. 调用cartographer_ros::Run()

4.2. cartographer_ros::Run()

  1. 初始化tf2的缓冲区tf_buffer
  2. 创建tf变换监听器
  3. 获取命令行传入的配置文件
  4. [重点来了]创建MapBuilder对象,返回对象指针,赋值map_builder
  5. new一个Google自己定义的Node节点,传入配置文件、map_builder指针、tf缓冲区进行构造
  6. 启动上面new出来的Node节点
  7. ...建图...
  8. 结束轨迹
  9. 调用最后一次全局BA优化
  10. 根据标志位判断是否进行序列化输出

5. Google自己定义的Node节点(类)

main()函数来看,最终都交给了Node节点来处理