Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "cartographer/mapping/internal/collated_trajectory_builder.h"
00018
00019 #include "cartographer/common/time.h"
00020 #include "glog/logging.h"
00021
00022 namespace cartographer {
00023 namespace mapping {
00024
00025 namespace {
00026
00027 constexpr double kSensorDataRatesLoggingPeriodSeconds = 15.;
00028
00029 }
00030
00031 CollatedTrajectoryBuilder::CollatedTrajectoryBuilder(
00032 const proto::TrajectoryBuilderOptions& trajectory_options,
00033 sensor::CollatorInterface* const sensor_collator, const int trajectory_id,
00034 const std::set<SensorId>& expected_sensor_ids,
00035 std::unique_ptr<TrajectoryBuilderInterface> wrapped_trajectory_builder)
00036 : sensor_collator_(sensor_collator),
00037 collate_landmarks_(trajectory_options.collate_landmarks()),
00038 collate_fixed_frame_(trajectory_options.collate_fixed_frame()),
00039 trajectory_id_(trajectory_id),
00040 wrapped_trajectory_builder_(std::move(wrapped_trajectory_builder)),
00041 last_logging_time_(std::chrono::steady_clock::now()) {
00042 absl::flat_hash_set<std::string> expected_sensor_id_strings;
00043 for (const auto& sensor_id : expected_sensor_ids) {
00044 if (sensor_id.type == SensorId::SensorType::LANDMARK &&
00045 !collate_landmarks_) {
00046 continue;
00047 }
00048 if (sensor_id.type == SensorId::SensorType::FIXED_FRAME_POSE &&
00049 !collate_fixed_frame_) {
00050 continue;
00051 }
00052 expected_sensor_id_strings.insert(sensor_id.id);
00053 }
00054 sensor_collator_->AddTrajectory(
00055 trajectory_id, expected_sensor_id_strings,
00056 [this](const std::string& sensor_id, std::unique_ptr<sensor::Data> data) {
00057 HandleCollatedSensorData(sensor_id, std::move(data));
00058 });
00059 }
00060
00061 void CollatedTrajectoryBuilder::AddData(std::unique_ptr<sensor::Data> data) {
00062 sensor_collator_->AddSensorData(trajectory_id_, std::move(data));
00063 }
00064
00065 void CollatedTrajectoryBuilder::HandleCollatedSensorData(
00066 const std::string& sensor_id, std::unique_ptr<sensor::Data> data) {
00067 auto it = rate_timers_.find(sensor_id);
00068 if (it == rate_timers_.end()) {
00069 it = rate_timers_
00070 .emplace(
00071 std::piecewise_construct, std::forward_as_tuple(sensor_id),
00072 std::forward_as_tuple(
00073 common::FromSeconds(kSensorDataRatesLoggingPeriodSeconds)))
00074 .first;
00075 }
00076 it->second.Pulse(data->GetTime());
00077
00078 if (std::chrono::steady_clock::now() - last_logging_time_ >
00079 common::FromSeconds(kSensorDataRatesLoggingPeriodSeconds)) {
00080 for (const auto& pair : rate_timers_) {
00081 LOG(INFO) << pair.first << " rate: " << pair.second.DebugString();
00082 }
00083 last_logging_time_ = std::chrono::steady_clock::now();
00084 }
00085
00086 data->AddToTrajectoryBuilder(wrapped_trajectory_builder_.get());
00087 }
00088
00089 }
00090 }