scenario_simulator_v2 C++ API
configuration.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef TRAFFIC_SIMULATOR__API__CONFIGURATION_HPP_
16 #define TRAFFIC_SIMULATOR__API__CONFIGURATION_HPP_
17 
18 #include <algorithm>
19 #include <boost/filesystem.hpp>
20 #include <boost/filesystem/operations.hpp>
21 #include <boost/range/iterator_range.hpp>
22 #include <iomanip>
24 #include <set>
25 #include <string>
26 
27 namespace traffic_simulator
28 {
30 {
32 
33  using Pathname = boost::filesystem::path;
34 
35  std::set<std::uint8_t> auto_sink_entity_types = {};
36 
37  bool verbose = false;
38 
39  bool standalone_mode = false;
40 
41  std::string simulator_host = "localhost";
42 
44 
46 
47  /* ---- NOTE -----------------------------------------------------------------
48  *
49  * This setting comes from the argument of the same name (= `map_path`) in
50  * the launch file of ArchitectureProposal. In general, Autoware expects
51  * this argument to be given the path to the directory containing the two HD
52  * maps, lanelet_map.osm and pointcloud_map.pcd.
53  *
54  * Depending on your map file, you may need to include additional files in
55  * this directory. For example, Autoware.Auto (at the time this comment was
56  * written) should be given the map origin coordinates in a separate yaml
57  * file.
58  *
59  * ------------------------------------------------------------------------ */
61 
63 
65 
67 
68  explicit Configuration(const Pathname & map_path) //
72  {
73  }
74 
75  auto assertMapPath(const Pathname & map_path) const -> const Pathname &
76  {
77  if (map_path.empty()) {
78  throw common::SimulationError("No map path is given");
79  } else if (not boost::filesystem::is_directory(map_path)) {
81  "The map_path must be a directory (given an ", std::quoted(map_path.string()), ")");
82  } else if (not contains(map_path, ".osm")) {
83  throw common::SimulationError("The map_path must contain at least one *.osm file");
84  } else if (not contains(map_path, ".pcd")) {
85  throw common::SimulationError("The map_path must contain at least one *.pcd file");
86  } else {
87  return map_path;
88  }
89  }
90 
91  template <typename... Ts>
92  auto contains(Ts &&... xs) const -> bool
93  {
94  return not findLexicographicallyFirstFilenameOf(std::forward<decltype(xs)>(xs)...).empty();
95  }
96 
98  const Pathname & pathname, const std::string & extension) const -> Filename
99  {
100  Filename result;
101 
102  for (const auto & each :
103  boost::make_iterator_range(boost::filesystem::directory_iterator(pathname), {})) {
104  const auto filename = each.path().filename().string();
105  if (
106  each.path().extension() == extension and
107  std::lexicographical_compare(
108  std::cbegin(result), std::cend(result), std::cbegin(filename), std::cend(filename))) {
109  result = filename;
110  }
111  }
112 
113  return result;
114  }
115 
116  auto getLanelet2MapFile() const -> const auto &
117  {
118  if (not lanelet2_map_file.empty()) {
119  return lanelet2_map_file;
120  } else {
121  throw common::SimulationError("The map_path must contain at least one *.osm file");
122  }
123  }
124 
125  auto getPointCloudMapFile() const -> const auto &
126  {
127  if (not pointcloud_map_file.empty()) {
128  return pointcloud_map_file;
129  } else {
130  throw common::SimulationError("The map_path must contain at least one *.pcd file");
131  }
132  }
133 
134  auto lanelet2_map_path() const { return map_path / lanelet2_map_file; }
135 
137 };
138 } // namespace traffic_simulator
139 
140 #endif // TRAFFIC_SIMULATOR__API__CONFIGURATION_HPP_
Definition: api.hpp:48
Definition: junit5.hpp:25
std::string string
Definition: junit5.hpp:26
A problem occurred that interfered with the continuation of the simulation.
Definition: exception.hpp:47
Definition: configuration.hpp:30
auto lanelet2_map_path() const
Definition: configuration.hpp:134
auto contains(Ts &&... xs) const -> bool
Definition: configuration.hpp:92
const Pathname map_path
Definition: configuration.hpp:60
Configuration(const Pathname &map_path)
Definition: configuration.hpp:68
auto getLanelet2MapFile() const -> const auto &
Definition: configuration.hpp:116
auto assertMapPath(const Pathname &map_path) const -> const Pathname &
Definition: configuration.hpp:75
std::string Filename
Definition: configuration.hpp:31
auto findLexicographicallyFirstFilenameOf(const Pathname &pathname, const std::string &extension) const -> Filename
Definition: configuration.hpp:97
double v2i_traffic_light_publish_rate
Definition: configuration.hpp:45
auto getPointCloudMapFile() const -> const auto &
Definition: configuration.hpp:125
bool standalone_mode
Definition: configuration.hpp:39
Filename pointcloud_map_file
Definition: configuration.hpp:64
bool verbose
Definition: configuration.hpp:37
std::string simulator_host
Definition: configuration.hpp:41
Pathname scenario_path
Definition: configuration.hpp:66
Filename lanelet2_map_file
Definition: configuration.hpp:62
boost::filesystem::path Pathname
Definition: configuration.hpp:33
std::set< std::uint8_t > auto_sink_entity_types
Definition: configuration.hpp:35
double conventional_traffic_light_publish_rate
Definition: configuration.hpp:43
auto pointcloud_map_path() const
Definition: configuration.hpp:136