*转载请注明出处 @梦凝小筑
1.2 Cartographer 源码软件结构
Cartographer 的源码中,主要有两大部分:
1,Cartographer 算法核心代码,在Cartographer文件夹中,
2,Cartographer 在 ros 平台的接口,在Cartographer_ros文件夹中
* 还有一个ceres-solver google 的开源 优化库 ,用来求解各种优化问题 ,这里不介绍。
软件结构如图所示:
解析
(1)Cartographer_ros
作用:Cartographer 在 ros 平台的接口 , 启动rosj节点、读取来自传感器数据、处理并将数据上传给核心Cartographer核心算法部分、载入外部参数、初始化Extrapolator等
模块:Options、node、MapBuilderBridge、SensorBridge、TfBridge
Options:
主要代码文件:node_option.cc 、node_option.h 、trajectory_options.cc 、trajectory_options.h
功能:
NodeOptions node_options;//!定义Cartographer最初级选项
TrajectoryOptions trajectory_options;//!定义建图的一些设置参数
//!LoadOptions从外部载入参数,并赋值给 node_options和 trajectory_options
//!输入参数 有launch文件中导入,分别是参数文件的路径和文件名
std::tie(node_options, trajectory_options) =
LoadOptions(FLAGS_configuration_directory, FLAGS_configuration_basename);
node:
主要代码文件:node.cc 、node.h
功能:
Node::LoadState cartographer参数载入的入口
//!调用MapBuilderBridge.LoadState
map_builder_bridge_.LoadState(state_filename, load_frozen_state);
Node::StartTrajectoryWithDefaultTopics 建图前的设置
CHECK(ValidateTrajectoryOptions(options));
//!建图前的设置
AddTrajectory(options, DefaultSensorTopics());
Node::AddTrajectory
int Node::AddTrajectory(const TrajectoryOptions& options,
const cartographer_ros_msgs::SensorTopics& topics) {
const std::set<cartographer::mapping::TrajectoryBuilderInterface::SensorId>
expected_sensor_ids = ComputeExpectedSensorIds(options, topics);//!预期id
//!根据参数初始化MapBuilderBridge
//!MapBuilderBridge map_builder_bridge_ GUARDED_BY(mutex_);
const int trajectory_id =
map_builder_bridge_.AddTrajectory(expected_sensor_ids, options);
AddExtrapolator(trajectory_id, options);//!设置外推器的参数
AddSensorSamplers(trajectory_id, options);
LaunchSubscribers(options, topics, trajectory_id);//!消息订阅
wall_timers_.push_back(node_handle_.createWallTimer( //! ros 计时器
::ros::WallDuration(kTopicMismatchCheckDelaySec),
&Node::MaybeWarnAboutTopicMismatch, this, /*oneshot=*/true));
for (const auto& sensor_id : expected_sensor_ids) {
subscribed_topics_.insert(sensor_id.id);
}
return trajectory_id;
}
Node::ComputeExpectedSensorIds
Node::AddExtrapolator
Node::AddSensorSamplers
Node::LaunchSubscribers (*重要) 定义topic订阅器,订阅各个传感器信息
MapBuilderBridge:
—-持续更新—-