14
14
15
15
#include " map_loader/lanelet2_differential_loader_module.hpp"
16
16
17
+ #include " lanelet2_local_projector.hpp"
17
18
#include " map_loader/lanelet2_map_loader_node.hpp"
18
19
19
20
Lanelet2DifferentialLoaderModule::Lanelet2DifferentialLoaderModule (
@@ -33,6 +34,13 @@ Lanelet2DifferentialLoaderModule::Lanelet2DifferentialLoaderModule(
33
34
pub_lanelet_map_meta_data_->publish (msg);
34
35
}
35
36
37
+ const auto adaptor = component_interface_utils::NodeAdaptor (node);
38
+ adaptor.init_sub (
39
+ sub_map_projector_info_,
40
+ [this ](const map_interface::MapProjectorInfo::Message::ConstSharedPtr msg) {
41
+ projector_info_ = *msg;
42
+ });
43
+
36
44
get_differential_lanelet2_maps_service_ = node->create_service <GetDifferentialLanelet2Map>(
37
45
" /map/get_differential_lanelet_map" ,
38
46
std::bind (
@@ -75,39 +83,61 @@ bool Lanelet2DifferentialLoaderModule::differentialLanelet2Load(
75
83
return false ;
76
84
}
77
85
78
- // create parser and load map
79
- lanelet::ErrorMessages errors{};
80
- lanelet::projection::MGRSProjector projector{};
81
- lanelet::io_handlers::MultiOsmParser parser (projector);
82
- lanelet::LaneletMapPtr map = parser.parse (lanelet2_paths, errors);
86
+ if (projector_info_.value ().projector_type != tier4_map_msgs::msg::MapProjectorInfo::LOCAL) {
87
+ std::unique_ptr<lanelet::Projector> projector =
88
+ geography_utils::get_lanelet2_projector (projector_info_.value ());
89
+
90
+ lanelet::ErrorMessages errors{};
91
+ lanelet::io_handlers::MultiOsmParser parser (*projector);
92
+ lanelet::LaneletMapPtr map = parser.parse (lanelet2_paths, errors);
93
+
94
+ if (!errors.empty ()) {
95
+ for (const auto & error : errors) {
96
+ RCLCPP_ERROR_STREAM (rclcpp::get_logger (" map_loader" ), error);
97
+ }
98
+ }
99
+
100
+ const auto map_bin_msg =
101
+ Lanelet2MapLoaderNode::create_map_bin_msg (map, lanelet2_paths[0 ], rclcpp::Clock ().now ());
83
102
84
- for (lanelet::Point3d point : map->pointLayer ) {
85
- if (point.hasAttribute (" local_x" )) {
86
- point.x () = point.attribute (" local_x" ).asDouble ().value ();
103
+ response->differential_map = map_bin_msg;
104
+ } else {
105
+ const lanelet::projection::LocalProjector projector;
106
+ lanelet::ErrorMessages errors{};
107
+ lanelet::io_handlers::MultiOsmParser parser (projector);
108
+ lanelet::LaneletMapPtr map = parser.parse (lanelet2_paths, errors);
109
+
110
+ if (!errors.empty ()) {
111
+ for (const auto & error : errors) {
112
+ RCLCPP_ERROR_STREAM (rclcpp::get_logger (" map_loader" ), error);
113
+ }
87
114
}
88
- if (point.hasAttribute (" local_y" )) {
89
- point.y () = point.attribute (" local_y" ).asDouble ().value ();
115
+
116
+ // overwrite local_x, local_y
117
+ for (lanelet::Point3d point : map->pointLayer ) {
118
+ if (point.hasAttribute (" local_x" )) {
119
+ point.x () = point.attribute (" local_x" ).asDouble ().value ();
120
+ }
121
+ if (point.hasAttribute (" local_y" )) {
122
+ point.y () = point.attribute (" local_y" ).asDouble ().value ();
123
+ }
90
124
}
91
- }
92
125
93
- // realign lanelet borders using updated points
94
- for (lanelet::Lanelet lanelet : map->laneletLayer ) {
95
- auto left = lanelet.leftBound ();
96
- auto right = lanelet.rightBound ();
97
- std::tie (left, right) = lanelet::geometry::align (left, right);
98
- lanelet.setLeftBound (left);
99
- lanelet.setRightBound (right);
100
- }
126
+ // realign lanelet borders using updated points
127
+ for (lanelet::Lanelet lanelet : map->laneletLayer ) {
128
+ auto left = lanelet.leftBound ();
129
+ auto right = lanelet.rightBound ();
130
+ std::tie (left, right) = lanelet::geometry::align (left, right);
131
+ lanelet.setLeftBound (left);
132
+ lanelet.setRightBound (right);
133
+ }
101
134
102
- // overwrite centerline
103
- lanelet::utils::overwriteLaneletsCenterline (map, 5.0 , false );
104
- // convert map to binary message
105
- {
106
135
const auto map_bin_msg =
107
136
Lanelet2MapLoaderNode::create_map_bin_msg (map, lanelet2_paths[0 ], rclcpp::Clock ().now ());
108
137
109
138
response->differential_map = map_bin_msg;
110
139
}
140
+
111
141
return true ;
112
142
}
113
143
0 commit comments