码迷,mamicode.com
首页 > 其他好文 > 详细

Cartographer源码阅读(4)

时间:2018-01-10 22:52:19      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:ring   cal   now()   expect   make   hand   pos   void   data   

  MapBuilder的成员变量sensor::Collator sensor_collator_;

  再次阅读MapBuilder::AddTrajectoryBuilder方法。首先构造了mapping::GlobalTrajectoryBuilder单例,接着作为参数构造了CollatedTrajectoryBuilder单例。

trajectory_builders_.push_back(
common::make_unique<CollatedTrajectoryBuilder>(
&sensor_collator_, trajectory_id, expected_sensor_ids,
common::make_unique<mapping::GlobalTrajectoryBuilder<mapping_2d::LocalTrajectoryBuilder,mapping_2d::proto::LocalTrajectoryBuilderOptions,mapping_2d::PoseGraph>>
(trajectory_options.trajectory_builder_2d_options(),trajectory_id, pose_graph_2d_.get(),local_slam_result_callback)
)
);

  这里sensor_collator_作为参数传入,参与CollatedTrajectoryBuilder构造。

查看构造函数

CollatedTrajectoryBuilder::CollatedTrajectoryBuilder(sensor::Collator* const sensor_collator, const int trajectory_id, const std::unordered_set<std::string>& expected_sensor_ids,   std::unique_ptr<TrajectoryBuilderInterface> wrapped_trajectory_builder)
    : sensor_collator_(sensor_collator)
    , trajectory_id_(trajectory_id)
    , wrapped_trajectory_builder_(std::move(wrapped_trajectory_builder))
    , last_logging_time_(std::chrono::steady_clock::now()) 
{
     sensor_collator_->AddTrajectory(trajectory_id, expected_sensor_ids,
      [this](const std::string& sensor_id, std::unique_ptr<sensor::Data> data)
      {
        HandleCollatedSensorData(sensor_id, std::move(data));
      }
      );
}

  这里是回调函数。

 [this](const std::string& sensor_id, std::unique_ptr<sensor::Data> data)
 {
        HandleCollatedSensorData(sensor_id, std::move(data));
  }

  查看sensor::Collator的AddTrajectory方法:

void Collator::AddTrajectory( const int trajectory_id, const std::unordered_set<std::string>& expected_sensor_ids, const Callback& callback) 
{
   for (const auto& sensor_id : expected_sensor_ids)
  {
      const auto queue_key = QueueKey{trajectory_id, sensor_id};
      queue_.AddQueue(queue_key, [callback, sensor_id](std::unique_ptr<Data> data)
                    {
                      callback(sensor_id, std::move(data));
                    });
       queue_keys_[trajectory_id].push_back(queue_key);
  }
}

  for (const auto& sensor_id : expected_sensor_ids)用到了C++11的auto新特性。

Cartographer源码阅读(4)

标签:ring   cal   now()   expect   make   hand   pos   void   data   

原文地址:https://www.cnblogs.com/yhlx125/p/8260990.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!