作者:考试大试题网 | 来源:互联网 | 2023-08-12 16:21
1.Cartographer文件树cartographer算法包括cartographer和cartographer_ros两部分,其中cartographer为算
1.Cartographer文件树
cartographer算法包括cartographer
和cartographer_ros
两部分,其中cartographer
为算法的核心实现,cartographer_ros
为算法和ROS的对接的桥梁,方便用户使用。
.
├── cartographer
│ ├── bazel
│ │ └── third_party
│ ├── cartographer
│ │ ├── cloud
│ │ ├── common
│ │ ├── ground_truth
│ │ ├── io
│ │ ├── mapping
│ │ ├── metrics
│ │ ├── sensor
│ │ └── transform
│ ├── cmake
│ │ └── modules
│ ├── configuration_files
│ ├── docs
│ │ ├── assets
│ │ └── source
│ └── scripts
└── cartographer_ros├── cartographer_ros│ ├── cartographer_ros│ ├── configuration_files│ ├── launch│ ├── scripts│ └── urdf├── cartographer_ros_msgs│ ├── msg│ └── srv├── cartographer_rviz│ ├── cartographer_rviz│ └── ogre_media├── docs│ └── source└── scripts
2.Cartographer初始化
- 从
src/cartographer_ros/cartographer_ros/launch/backpack_2d.launch
进入,可以看到cartographer_node
节点的启动
<launch><param name&#61;"robot_description"textfile&#61;"$(find cartographer_ros)/urdf/backpack_2d.urdf" /><node name&#61;"robot_state_publisher" pkg&#61;"robot_state_publisher"type&#61;"robot_state_publisher" /><node name&#61;"cartographer_node" pkg&#61;"cartographer_ros"type&#61;"cartographer_node" args&#61;"-configuration_directory $(find cartographer_ros)/configuration_files-configuration_basename backpack_2d.lua"output&#61;"screen"><remap from&#61;"echoes" to&#61;"horizontal_laser_2d" />node><node name&#61;"cartographer_occupancy_grid_node" pkg&#61;"cartographer_ros"type&#61;"cartographer_occupancy_grid_node" args&#61;"-resolution 0.05" />
launch>
- 可以发现
cartographer_node
是在src/cartographer_ros/cartographer_ros/cartographer_ros/node_main.cc
中创建的&#xff0c;这里主要关注函数cartographer_ros::Run()
。
int main(int argc, char** argv) {google::InitGoogleLogging(argv[0]);google::ParseCommandLineFlags(&argc, &argv, true);CHECK(!FLAGS_configuration_directory.empty())<< "-configuration_directory is missing.";CHECK(!FLAGS_configuration_basename.empty())<< "-configuration_basename is missing.";::ros::init(argc, argv, "cartographer_node");::ros::start();cartographer_ros::ScopedRosLogSink ros_log_sink;cartographer_ros::Run();::ros::shutdown();
}
- 在
cartographer_ros::Run()
函数中创建了map_builder
和node
&#xff0c;node
控制着整个系统&#xff0c;而map_builder
如名字一样&#xff0c;用于地图的构建&#xff0c;另外map_builder
这个变量移动到MapBuilderBridge
中的std::unique_ptr map_builder_
void Run() {constexpr double kTfBufferCacheTimeInSeconds &#61; 10.;tf2_ros::Buffer tf_buffer{::ros::Duration(kTfBufferCacheTimeInSeconds)};tf2_ros::TransformListener tf(tf_buffer);NodeOptions node_options;TrajectoryOptions trajectory_options;std::tie(node_options, trajectory_options) &#61;LoadOptions(FLAGS_configuration_directory, FLAGS_configuration_basename);auto map_builder &#61;cartographer::mapping::CreateMapBuilder(node_options.map_builder_options);Node node(node_options, std::move(map_builder), &tf_buffer,FLAGS_collect_metrics);......
}
- 从
node
的构造开始&#xff0c;初始的流程如图所示