cartographer analysis - first chapter

来源:互联网 发布:ubuntu ifconfig 编辑:程序博客网 时间:2024/05/02 04:36

为了分析这个代码的运行原理,首先切到最初的版本,这样的简化代码有利于理解cartographer的运行基本方式。
这里写图片描述
如上是cartographer的调用入口。
Node 是一个类,run 函数调用了Node的三个接口:构造函数,以及SpinForever, Initialize.
class node
可以看到仅开放了main函数调用的方法。
Initialize()方法:
1. subscribe to IMU
2. subscribe to laser: 3 types

const bool has_laser_scan_2d = node_handle_.hasParam("laser_scan_2d_topic");const bool has_multi_echo_laser_scan_2d = node_handle_.hasParam("multi_echo_laser_scan_2d_topic");const bool has_laser_scan_3d = node_handle_.hasParam("laser_scan_3d_topics");

以下集中分析2d 这种case

 if (has_laser_scan_2d)   {  const string topic = GetParamOrDie<string>("laser_scan_2d_topic");  laser_2d_subscriber_ = node_handle_.subscribe(topic, kSubscriberQueueSize, &Node::LaserScanMessageCallback, this);  expected_sensor_identifiers.insert(topic);  }

这里注册了回调函数LaserScanMessageCallback

接下里,定义了用于sparse graph optimization的对象:sparse_pose_graph_

auto sparse_pose_graph_2d = ::cartographer::common::make_unique< ::cartographer::mapping_2d::SparsePoseGraph>(     ::cartographer::mapping::CreateSparsePoseGraphOptions(lua_parameter_dictionary.GetDictionary("sparse_pose_graph").get()), &thread_pool_, &constant_node_data_);trajectory_builder_ = ::cartographer::common::make_unique<  ::cartographer::mapping_2d::GlobalTrajectoryBuilder>          (::cartographer::mapping_2d::CreateLocalTrajectoryBuilderOptions(lua_parameter_dictionary.GetDictionary("trajectory_builder").get()),sparse_pose_graph_2d.get());sparse_pose_graph_ = std::move(sparse_pose_graph_2d);

可以看到对于class 的数据成员,遵循了后缀下划线的风格惯例。代码中大量采用了C++11的语法,std::move 将左值转换成右值。
Initialize()最后,会调用:
这里写图片描述
那么HandleSensorData函数又做了什么?
这里写图片描述
所以会根据不同的sensor 类型,调用对应的Add方法。
如下包含了2个Add和两个回调函数的实现上:
这里写图片描述
通过回调函数,imulaser数据都会被传入到sensor_dataAddSensorData方法中。
可以发现Add操作分别调用了trajectory_builder_->AddImuData 和trajectory_builder_->AddHorizontalLaserFan

0 0
原创粉丝点击