Cartographer_ros(1)

Cartographer_ros的node_main.cc主要负责参数读取和程序启动。使用gflags解析命令行参数,如collect_metrics、configuration_directory等。glog用于日志记录,如使用CHECK宏进行条件检查。程序通过LoadOptions从Lua配置文件获取节点和轨迹选项,并创建MapBuilder进行SLAM算法。Node类初始化时,将ROS话题传入SLAM算法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Cartographer_ros(1)

入口node_main.cc

node_main.cc主要实现参数文件读取和程序启动功能。

gflags

首先,使用谷歌的gflags命令行参数解析工具,实现将命令行输入参数读取到程序内部的功能。

DEFINE_bool(collect_metrics, false,
            "Activates the collection of runtime metrics. If activated, the "
            "metrics can be accessed via a ROS service.");
DEFINE_string(configuration_directory, "",
              "First directory in which configuration files are searched, "
              "second is always the Cartographer installation to allow "
              "including files from there.");
DEFINE_string(configuration_basename, "",
              "Basename, i.e. not containing any directory prefix, of the "
              "configuration file.");
DEFINE_string(load_state_filename, "",
              "If non-empty, filename of a .pbstream file to load, containing "
              "a saved SLAM state.");
fgrep -l -f ./test ccc

-l是不带参数的标记,-f是带了./test参数的标记

定义参数通过DEFINE_type宏实现, 该宏的三个参数含义分别为命令行参数名, 参数默认值, 以及参数的帮助信息。

例如定义collect_metrics

DEFINE_bool(collect_metrics,  false,
            "Activates the collection of runtime metrics. If activated, the "
            "metrics can be accessed via a ROS service.");

使用以FLAGS_name的方式调用

  Node node(node_options, std::move(map_builder), &tf_buffer,
            FLAGS_collect_metrics);

glog

glog是谷歌开发的一个应用级别的日志系统库。glog里提供的CHECK系列的宏, 检测某个表达式是否为真。

Cartographer中大量使用CHECK函数。

main函数

glog库的初始化

 google::InitGoogleLogging(argv[0]);

使用gflags进行参数的初始化. 其中第三个参数为remove_flag

如果为true, gflags会移除parse过的参数, 否则gflags就会保留这些参数, 但可能会对参数顺序进行调整.

google::ParseCommandLineFlags(&argc, &argv, true);

run函数

 // 开启监听tf的独立线程
  tf2_ros::TransformListener tf(tf_buffer);

  NodeOptions node_options;
  TrajectoryOptions trajectory_options;

  // c++11: std::tie()函数可以将变量连接到一个给定的tuple上,生成一个元素类型全是引用的tuple

  // 根据Lua配置文件中的内容, 为node_options, trajectory_options 赋值
  std::tie(node_options, trajectory_options) =
      LoadOptions(FLAGS_configuration_directory, FLAGS_configuration_basename);

  // MapBuilder类是完整的SLAM算法类
  // 包含前端(TrajectoryBuilders,scan to submap) 与 后端(用于查找回环的PoseGraph) 
  auto map_builder =
      cartographer::mapping::CreateMapBuilder(node_options.map_builder_options);

map_builder 是完整的SLAM算法类,包含前端(trajectorybuilders, scan to submap matching)与后端(posegraph)

  // Node类的初始化, 将ROS的topic传入SLAM, 也就是MapBuilder
  Node node(node_options, std::move(map_builder), &tf_buffer,
            FLAGS_collect_metrics);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值