node_grpc_main.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2017 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 #include "cartographer_ros/node.h"
21 #include "gflags/gflags.h"
23 
24 DEFINE_string(configuration_directory, "",
25  "First directory in which configuration files are searched, "
26  "second is always the Cartographer installation to allow "
27  "including files from there.");
28 DEFINE_string(configuration_basename, "",
29  "Basename, i.e. not containing any directory prefix, of the "
30  "configuration file.");
31 DEFINE_string(server_address, "localhost:50051",
32  "gRPC server address to "
33  "stream the sensor data to.");
35  start_trajectory_with_default_topics, true,
36  "Enable to immediately start the first trajectory with default topics.");
38  save_map_filename, "",
39  "If non-empty, serialize state and write it to disk before shutting down.");
40 DEFINE_string(load_state_filename, "",
41  "If non-empty, filename of a .pbstream file "
42  "to load, containing a saved SLAM state.");
43 
44 namespace cartographer_ros {
45 namespace {
46 
47 void Run() {
48  constexpr double kTfBufferCacheTimeInSeconds = 10.;
49  tf2_ros::Buffer tf_buffer{::ros::Duration(kTfBufferCacheTimeInSeconds)};
50  tf2_ros::TransformListener tf(tf_buffer);
51  NodeOptions node_options;
52  TrajectoryOptions trajectory_options;
53  std::tie(node_options, trajectory_options) =
54  LoadOptions(FLAGS_configuration_directory, FLAGS_configuration_basename);
55 
56  auto map_builder =
57  cartographer::common::make_unique<::cartographer::cloud::MapBuilderStub>(
58  FLAGS_server_address);
59  Node node(node_options, std::move(map_builder), &tf_buffer);
60 
61  if (!FLAGS_load_state_filename.empty()) {
62  node.LoadState(FLAGS_load_state_filename, true /* load_frozen_state */);
63  }
64 
65  if (FLAGS_start_trajectory_with_default_topics) {
66  node.StartTrajectoryWithDefaultTopics(trajectory_options);
67  }
68 
69  ::ros::spin();
70 
71  node.FinishAllTrajectories();
72  node.RunFinalOptimization();
73 
74  if (!FLAGS_save_map_filename.empty()) {
75  node.SerializeState(FLAGS_save_map_filename);
76  }
77 }
78 
79 } // namespace
80 } // namespace cartographer_ros
81 
82 int main(int argc, char** argv) {
83  google::InitGoogleLogging(argv[0]);
84  google::ParseCommandLineFlags(&argc, &argv, true);
85 
86  CHECK(!FLAGS_configuration_directory.empty())
87  << "-configuration_directory is missing.";
88  CHECK(!FLAGS_configuration_basename.empty())
89  << "-configuration_basename is missing.";
90 
91  ::ros::init(argc, argv, "cartographer_grpc_node");
92  ::ros::start();
93 
95  cartographer_ros::Run();
96  ::ros::shutdown();
97 }
DEFINE_string(configuration_directory, "", "First directory in which configuration files are searched, " "second is always the Cartographer installation to allow " "including files from there.")
std::tuple< NodeOptions, TrajectoryOptions > LoadOptions(const std::string &configuration_directory, const std::string &configuration_basename)
Definition: node_options.cc:46
DEFINE_bool(start_trajectory_with_default_topics, true, "Enable to immediately start the first trajectory with default topics.")
int main(int argc, char **argv)
void Run(const std::string &configuration_directory, const std::string &configuration_basename)
tf2_ros::Buffer * tf_buffer


cartographer_ros
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:06:05