21
21
#include " lanelet2_extension/utility/utilities.hpp"
22
22
#include " map_loader/lanelet2_map_loader_node.hpp"
23
23
#include " map_projection_loader/load_info_from_lanelet2_map.hpp"
24
+ #include " map_projection_loader/map_projection_loader.hpp"
24
25
#include " motion_utils/resample/resample.hpp"
25
26
#include " motion_utils/trajectory/conversion.hpp"
26
27
#include " tier4_autoware_utils/geometry/geometry.hpp"
36
37
#include " std_msgs/msg/bool.hpp"
37
38
#include " std_msgs/msg/float32.hpp"
38
39
#include " std_msgs/msg/int32.hpp"
39
- #include < tier4_map_msgs/msg/map_projector_info.hpp>
40
40
41
41
#include < boost/geometry/algorithms/correct.hpp>
42
42
#include < boost/geometry/algorithms/distance.hpp>
@@ -204,8 +204,10 @@ StaticCenterlineGeneratorNode::StaticCenterlineGeneratorNode(
204
204
const auto selected_centerline = std::vector<TrajectoryPoint>(
205
205
c.centerline .begin () + traj_range_indices_.first ,
206
206
c.centerline .begin () + traj_range_indices_.second + 1 );
207
+ const auto selected_route_lane_ids = get_route_lane_ids_from_points (selected_centerline);
207
208
save_map (
208
- lanelet2_output_file_path, CenterlineWithRoute{selected_centerline, c.route_lane_ids });
209
+ lanelet2_output_file_path,
210
+ CenterlineWithRoute{selected_centerline, selected_route_lane_ids});
209
211
}
210
212
});
211
213
sub_traj_resample_interval_ = create_subscription<std_msgs::msg::Float32 >(
@@ -280,6 +282,8 @@ void StaticCenterlineGeneratorNode::run()
280
282
load_map (lanelet2_input_file_path);
281
283
const auto centerline_with_route = generate_centerline_with_route ();
282
284
traj_range_indices_ = std::make_pair (0 , centerline_with_route.centerline .size () - 1 );
285
+
286
+ evaluate (centerline_with_route.route_lane_ids , centerline_with_route.centerline );
283
287
save_map (lanelet2_output_file_path, centerline_with_route);
284
288
285
289
centerline_with_route_ = centerline_with_route;
@@ -304,19 +308,7 @@ CenterlineWithRoute StaticCenterlineGeneratorNode::generate_centerline_with_rout
304
308
return CenterlineWithRoute{optimized_centerline, route_lane_ids};
305
309
} else if (centerline_source_ == CenterlineSource::BagEgoTrajectoryBase) {
306
310
const auto bag_centerline = generate_centerline_with_bag (*this );
307
- const auto start_lanelets =
308
- route_handler_ptr_->getRoadLaneletsAtPose (bag_centerline.front ().pose );
309
- const auto end_lanelets =
310
- route_handler_ptr_->getRoadLaneletsAtPose (bag_centerline.back ().pose );
311
- if (start_lanelets.empty () || end_lanelets.empty ()) {
312
- RCLCPP_ERROR (get_logger (), " Nearest lanelets to the bag's centerline are not found." );
313
- return CenterlineWithRoute{};
314
- }
315
-
316
- const lanelet::Id start_lanelet_id = start_lanelets.front ().id ();
317
- const lanelet::Id end_lanelet_id = end_lanelets.front ().id ();
318
- const auto route_lane_ids = plan_route (start_lanelet_id, end_lanelet_id);
319
-
311
+ const auto route_lane_ids = get_route_lane_ids_from_points (bag_centerline);
320
312
return CenterlineWithRoute{bag_centerline, route_lane_ids};
321
313
}
322
314
throw std::logic_error (
@@ -337,6 +329,24 @@ CenterlineWithRoute StaticCenterlineGeneratorNode::generate_centerline_with_rout
337
329
return centerline_with_route;
338
330
}
339
331
332
+ std::vector<lanelet::Id> StaticCenterlineGeneratorNode::get_route_lane_ids_from_points (
333
+ const std::vector<TrajectoryPoint> & points)
334
+ {
335
+ const auto start_lanelets = route_handler_ptr_->getRoadLaneletsAtPose (points.front ().pose );
336
+ const auto end_lanelets = route_handler_ptr_->getRoadLaneletsAtPose (points.back ().pose );
337
+ if (start_lanelets.empty () || end_lanelets.empty ()) {
338
+ RCLCPP_ERROR (get_logger (), " Nearest lanelets to the bag's points are not found." );
339
+ return std::vector<lanelet::Id>{};
340
+ }
341
+
342
+ const lanelet::Id start_lanelet_id = start_lanelets.front ().id ();
343
+ const lanelet::Id end_lanelet_id = end_lanelets.front ().id ();
344
+ if (start_lanelet_id == end_lanelet_id) {
345
+ return std::vector<lanelet::Id>{start_lanelet_id};
346
+ }
347
+ return plan_route (start_lanelet_id, end_lanelet_id);
348
+ }
349
+
340
350
void StaticCenterlineGeneratorNode::load_map (const std::string & lanelet2_input_file_path)
341
351
{
342
352
// copy the input LL2 map to the temporary file for debugging
@@ -349,21 +359,18 @@ void StaticCenterlineGeneratorNode::load_map(const std::string & lanelet2_input_
349
359
// load map by the map_loader package
350
360
map_bin_ptr_ = [&]() -> HADMapBin::ConstSharedPtr {
351
361
// load map
352
- const auto map_projector_info = load_info_from_lanelet2_map (lanelet2_input_file_path);
362
+ map_projector_info_ =
363
+ std::make_unique<MapProjectorInfo>(load_info_from_lanelet2_map (lanelet2_input_file_path));
353
364
const auto map_ptr =
354
- Lanelet2MapLoaderNode::load_map (lanelet2_input_file_path, map_projector_info );
365
+ Lanelet2MapLoaderNode::load_map (lanelet2_input_file_path, *map_projector_info_ );
355
366
if (!map_ptr) {
356
367
return nullptr ;
357
368
}
358
369
359
- // NOTE: generate map projector for lanelet::write().
360
- // Without this, lat/lon of the generated LL2 map will be wrong.
361
- map_projector_ = geography_utils::get_lanelet2_projector (map_projector_info);
362
-
363
- // NOTE: The original map is stored here since the various ids in the lanelet map will change
364
- // after lanelet::utils::overwriteLaneletCenterline, and saving map will fail.
370
+ // NOTE: The original map is stored here since the centerline will be added to all the
371
+ // lanelet when lanelet::utils::overwriteLaneletCenterline is called.
365
372
original_map_ptr_ =
366
- Lanelet2MapLoaderNode::load_map (lanelet2_input_file_path, map_projector_info );
373
+ Lanelet2MapLoaderNode::load_map (lanelet2_input_file_path, *map_projector_info_ );
367
374
368
375
// overwrite more dense centerline
369
376
lanelet::utils::overwriteLaneletsCenterline (map_ptr, 5.0 , false );
@@ -639,11 +646,13 @@ void StaticCenterlineGeneratorNode::save_map(
639
646
const auto route_lanelets = utils::get_lanelets_from_ids (*route_handler_ptr_, c.route_lane_ids );
640
647
641
648
// update centerline in map
642
- utils::update_centerline (*route_handler_ptr_ , route_lanelets, c.centerline );
649
+ utils::update_centerline (original_map_ptr_ , route_lanelets, c.centerline );
643
650
RCLCPP_INFO (get_logger (), " Updated centerline in map." );
644
651
645
652
// save map with modified center line
646
- lanelet::write (lanelet2_output_file_path, *original_map_ptr_, *map_projector_);
653
+ std::filesystem::create_directory (" /tmp/static_centerline_generator" ); // TODO(murooka)
654
+ const auto map_projector = geography_utils::get_lanelet2_projector (*map_projector_info_);
655
+ lanelet::write (lanelet2_output_file_path, *original_map_ptr_, *map_projector);
647
656
RCLCPP_INFO (get_logger (), " Saved map." );
648
657
649
658
// copy the output LL2 map to the temporary file for debugging
0 commit comments