Skip to content

Commit 173aae4

Browse files
authored
fix(autoware_static_centerline_generator): update the centerline correctly with map projector (#6825)
* fix(static_centerline_generator): fixed the bug of offset lat/lon values Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> * fix typo Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> --------- Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com>
1 parent e7a8268 commit 173aae4

File tree

5 files changed

+58
-38
lines changed

5 files changed

+58
-38
lines changed

planning/autoware_static_centerline_generator/launch/static_centerline_generator.launch.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<!-- mandatory arguments when run_background is true -->
1212
<arg name="lanelet2_input_file_path" default=""/>
13-
<arg name="lanelet2_output_file_path" default="/tmp/lanelet2_map.osm"/>
13+
<arg name="lanelet2_output_file_path" default="/tmp/static_centerline_generator/lanelet2_map.osm"/>
1414
<arg name="start_lanelet_id" default=""/>
1515
<arg name="end_lanelet_id" default=""/>
1616

planning/autoware_static_centerline_generator/src/static_centerline_generator_node.cpp

+35-26
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "lanelet2_extension/utility/utilities.hpp"
2222
#include "map_loader/lanelet2_map_loader_node.hpp"
2323
#include "map_projection_loader/load_info_from_lanelet2_map.hpp"
24+
#include "map_projection_loader/map_projection_loader.hpp"
2425
#include "motion_utils/resample/resample.hpp"
2526
#include "motion_utils/trajectory/conversion.hpp"
2627
#include "tier4_autoware_utils/geometry/geometry.hpp"
@@ -36,7 +37,6 @@
3637
#include "std_msgs/msg/bool.hpp"
3738
#include "std_msgs/msg/float32.hpp"
3839
#include "std_msgs/msg/int32.hpp"
39-
#include <tier4_map_msgs/msg/map_projector_info.hpp>
4040

4141
#include <boost/geometry/algorithms/correct.hpp>
4242
#include <boost/geometry/algorithms/distance.hpp>
@@ -204,8 +204,10 @@ StaticCenterlineGeneratorNode::StaticCenterlineGeneratorNode(
204204
const auto selected_centerline = std::vector<TrajectoryPoint>(
205205
c.centerline.begin() + traj_range_indices_.first,
206206
c.centerline.begin() + traj_range_indices_.second + 1);
207+
const auto selected_route_lane_ids = get_route_lane_ids_from_points(selected_centerline);
207208
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});
209211
}
210212
});
211213
sub_traj_resample_interval_ = create_subscription<std_msgs::msg::Float32>(
@@ -280,6 +282,8 @@ void StaticCenterlineGeneratorNode::run()
280282
load_map(lanelet2_input_file_path);
281283
const auto centerline_with_route = generate_centerline_with_route();
282284
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);
283287
save_map(lanelet2_output_file_path, centerline_with_route);
284288

285289
centerline_with_route_ = centerline_with_route;
@@ -304,19 +308,7 @@ CenterlineWithRoute StaticCenterlineGeneratorNode::generate_centerline_with_rout
304308
return CenterlineWithRoute{optimized_centerline, route_lane_ids};
305309
} else if (centerline_source_ == CenterlineSource::BagEgoTrajectoryBase) {
306310
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);
320312
return CenterlineWithRoute{bag_centerline, route_lane_ids};
321313
}
322314
throw std::logic_error(
@@ -337,6 +329,24 @@ CenterlineWithRoute StaticCenterlineGeneratorNode::generate_centerline_with_rout
337329
return centerline_with_route;
338330
}
339331

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+
340350
void StaticCenterlineGeneratorNode::load_map(const std::string & lanelet2_input_file_path)
341351
{
342352
// copy the input LL2 map to the temporary file for debugging
@@ -349,21 +359,18 @@ void StaticCenterlineGeneratorNode::load_map(const std::string & lanelet2_input_
349359
// load map by the map_loader package
350360
map_bin_ptr_ = [&]() -> HADMapBin::ConstSharedPtr {
351361
// 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));
353364
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_);
355366
if (!map_ptr) {
356367
return nullptr;
357368
}
358369

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.
365372
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_);
367374

368375
// overwrite more dense centerline
369376
lanelet::utils::overwriteLaneletsCenterline(map_ptr, 5.0, false);
@@ -639,11 +646,13 @@ void StaticCenterlineGeneratorNode::save_map(
639646
const auto route_lanelets = utils::get_lanelets_from_ids(*route_handler_ptr_, c.route_lane_ids);
640647

641648
// 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);
643650
RCLCPP_INFO(get_logger(), "Updated centerline in map.");
644651

645652
// 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);
647656
RCLCPP_INFO(get_logger(), "Saved map.");
648657

649658
// copy the output LL2 map to the temporary file for debugging

planning/autoware_static_centerline_generator/src/static_centerline_generator_node.hpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
#include "type_alias.hpp"
2424
#include "vehicle_info_util/vehicle_info_util.hpp"
2525

26-
#include <geography_utils/lanelet2_projector.hpp>
27-
2826
#include "std_msgs/msg/bool.hpp"
2927
#include "std_msgs/msg/float32.hpp"
3028
#include "std_msgs/msg/int32.hpp"
29+
#include "tier4_map_msgs/msg/map_projector_info.hpp"
3130

3231
#include <memory>
3332
#include <string>
@@ -39,6 +38,7 @@ namespace autoware::static_centerline_generator
3938
using autoware_static_centerline_generator::srv::LoadMap;
4039
using autoware_static_centerline_generator::srv::PlanPath;
4140
using autoware_static_centerline_generator::srv::PlanRoute;
41+
using tier4_map_msgs::msg::MapProjectorInfo;
4242

4343
struct CenterlineWithRoute
4444
{
@@ -66,6 +66,8 @@ class StaticCenterlineGeneratorNode : public rclcpp::Node
6666

6767
// plan centerline
6868
CenterlineWithRoute generate_centerline_with_route();
69+
std::vector<lanelet::Id> get_route_lane_ids_from_points(
70+
const std::vector<TrajectoryPoint> & points);
6971
void on_plan_path(
7072
const PlanPath::Request::SharedPtr request, const PlanPath::Response::SharedPtr response);
7173

@@ -80,7 +82,7 @@ class StaticCenterlineGeneratorNode : public rclcpp::Node
8082
lanelet::LaneletMapPtr original_map_ptr_{nullptr};
8183
HADMapBin::ConstSharedPtr map_bin_ptr_{nullptr};
8284
std::shared_ptr<RouteHandler> route_handler_ptr_{nullptr};
83-
std::unique_ptr<lanelet::Projector> map_projector_{nullptr};
85+
std::unique_ptr<MapProjectorInfo> map_projector_info_{nullptr};
8486

8587
std::pair<int, int> traj_range_indices_{0, 0};
8688
std::optional<CenterlineWithRoute> centerline_with_route_{std::nullopt};

planning/autoware_static_centerline_generator/src/utils.cpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,19 @@ nav_msgs::msg::Odometry::ConstSharedPtr convert_to_odometry(const geometry_msgs:
3535
return odometry_ptr;
3636
}
3737

38-
lanelet::Point3d createPoint3d(const double x, const double y, const double z = 19.0)
38+
lanelet::Point3d createPoint3d(const double x, const double y, const double z)
3939
{
4040
lanelet::Point3d point(lanelet::utils::getId());
41+
42+
// position
43+
point.x() = x;
44+
point.y() = y;
45+
point.z() = z;
46+
47+
// attributes
4148
point.setAttribute("local_x", x);
4249
point.setAttribute("local_y", y);
43-
point.setAttribute("ele", z);
50+
// NOTE: It seems that the attribute "ele" is assigned automatically.
4451

4552
return point;
4653
}
@@ -76,11 +83,13 @@ geometry_msgs::msg::Pose get_center_pose(
7683
geometry_msgs::msg::Point middle_pos;
7784
middle_pos.x = center_line[middle_point_idx].x();
7885
middle_pos.y = center_line[middle_point_idx].y();
86+
middle_pos.z = center_line[middle_point_idx].z();
7987

8088
// get next middle position of the lanelet
8189
geometry_msgs::msg::Point next_middle_pos;
8290
next_middle_pos.x = center_line[middle_point_idx + 1].x();
8391
next_middle_pos.y = center_line[middle_point_idx + 1].y();
92+
next_middle_pos.z = center_line[middle_point_idx + 1].z();
8493

8594
// calculate middle pose
8695
geometry_msgs::msg::Pose middle_pose;
@@ -119,13 +128,13 @@ PathWithLaneId get_path_with_lane_id(
119128
}
120129

121130
void update_centerline(
122-
RouteHandler & route_handler, const lanelet::ConstLanelets & lanelets,
131+
lanelet::LaneletMapPtr lanelet_map_ptr, const lanelet::ConstLanelets & lanelets,
123132
const std::vector<TrajectoryPoint> & new_centerline)
124133
{
125134
// get lanelet as reference to update centerline
126135
lanelet::Lanelets lanelets_ref;
127136
for (const auto & lanelet : lanelets) {
128-
for (auto & lanelet_ref : route_handler.getLaneletMapPtr()->laneletLayer) {
137+
for (auto & lanelet_ref : lanelet_map_ptr->laneletLayer) {
129138
if (lanelet_ref.id() == lanelet.id()) {
130139
lanelets_ref.push_back(lanelet_ref);
131140
}
@@ -148,13 +157,13 @@ void update_centerline(
148157

149158
// set center point
150159
centerline.push_back(center_point);
151-
route_handler.getLaneletMapPtr()->add(center_point);
160+
lanelet_map_ptr->add(center_point);
152161
break;
153162
}
154163

155164
if (!centerline.empty()) {
156165
// set centerline
157-
route_handler.getLaneletMapPtr()->add(centerline);
166+
lanelet_map_ptr->add(centerline);
158167
lanelet_ref.setCenterline(centerline);
159168

160169
// prepare new centerline
@@ -166,7 +175,7 @@ void update_centerline(
166175
auto & lanelet_ref = lanelets_ref.at(lanelet_idx);
167176

168177
// set centerline
169-
route_handler.getLaneletMapPtr()->add(centerline);
178+
lanelet_map_ptr->add(centerline);
170179
lanelet_ref.setCenterline(centerline);
171180
}
172181
}

planning/autoware_static_centerline_generator/src/utils.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ PathWithLaneId get_path_with_lane_id(
4242
const double nearest_ego_yaw_threshold);
4343

4444
void update_centerline(
45-
RouteHandler & route_handler, const lanelet::ConstLanelets & lanelets,
45+
lanelet::LaneletMapPtr lanelet_map_ptr, const lanelet::ConstLanelets & lanelets,
4646
const std::vector<TrajectoryPoint> & new_centerline);
4747

4848
MarkerArray create_footprint_marker(

0 commit comments

Comments
 (0)