Skip to content

Commit c312952

Browse files
StepTurtleMehmet Dogru
authored and
Mehmet Dogru
committed
Add projector types
Signed-off-by: Barış Zeren <bzeren1819@gmail.com>
1 parent f82ec24 commit c312952

File tree

6 files changed

+112
-47
lines changed

6 files changed

+112
-47
lines changed

launch/tier4_map_launch/launch/map.launch.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
<arg name="use_intra_process" default="false"/>
1717

1818
<!-- select container type -->
19-
<arg name="use_multithread" default="false"/>
19+
<arg name="use_multithread" default="true"/>
2020
<let name="container_type" value="component_container" unless="$(var use_multithread)"/>
2121
<let name="container_type" value="component_container_mt" if="$(var use_multithread)"/>
2222

2323
<group>
2424
<push-ros-namespace namespace="map"/>
2525

26-
<node_container pkg="rclcpp_components" exec="component_container_mt" name="map_container" namespace="" output="screen">
26+
<node_container pkg="rclcpp_components" exec="$(var container_type)" name="map_container" namespace="" output="screen">
2727
<composable_node pkg="map_loader" plugin="PointCloudMapLoaderNode" name="pointcloud_map_loader">
2828
<param from="$(var pointcloud_map_loader_param_path)"/>
2929
<param name="pcd_paths_or_directory" value="[$(var pointcloud_map_path)]"/>
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**:
22
ros__parameters:
3-
dynamic_map_loading_grid_size: 5.0 # [m]
4-
dynamic_map_loading_update_distance: 10.0 # [m]
5-
dynamic_map_loading_map_radius: 15.0 # [m]
3+
dynamic_map_loading_grid_size: 50.0 # [m]
4+
dynamic_map_loading_update_distance: 100.0 # [m]
5+
dynamic_map_loading_map_radius: 150.0 # [m]

map/autoware_dynamic_lanelet_provider/include/autoware/dynamic_lanelet_provider/dynamic_lanelet_provider.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <component_interface_specs/map.hpp>
77
#include <component_interface_utils/rclcpp.hpp>
8+
#include <geography_utils/lanelet2_projector.hpp>
89
#include <lanelet2_extension/projection/mgrs_projector.hpp>
910
#include <rclcpp/rclcpp.hpp>
1011

@@ -13,6 +14,7 @@
1314
#include "autoware_map_msgs/srv/get_differential_lanelet2_map.hpp"
1415
#include <geometry_msgs/msg/point.hpp>
1516
#include <nav_msgs/msg/odometry.hpp>
17+
#include <tier4_map_msgs/msg/map_projector_info.hpp>
1618

1719
namespace autoware
1820
{
@@ -45,6 +47,9 @@ class DynamicLaneletProviderNode : public rclcpp::Node
4547

4648
rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr odometry_sub_;
4749

50+
component_interface_utils::Subscription<map_interface::MapProjectorInfo>::SharedPtr
51+
sub_map_projector_info_;
52+
4853
rclcpp::Subscription<autoware_map_msgs::msg::LaneletMapMetaData>::SharedPtr
4954
lanelet_map_meta_data_sub_;
5055

@@ -63,6 +68,8 @@ class DynamicLaneletProviderNode : public rclcpp::Node
6368
const double dynamic_map_loading_map_radius_;
6469

6570
std::vector<Lanelet2FileMetaData> lanelet_map_meta_data_list_;
71+
72+
std::optional<tier4_map_msgs::msg::MapProjectorInfo> projector_info_;
6673
};
6774
} // namespace dynamic_lanelet_provider
6875
} // namespace autoware

map/autoware_dynamic_lanelet_provider/src/dynamic_lanelet_provider.cpp

+38-19
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ double norm_xy(const T & p1, const U & p2)
4343
DynamicLaneletProviderNode::DynamicLaneletProviderNode(const rclcpp::NodeOptions & options)
4444
: Node("dynamic_lanelet_provider", options),
4545
map_frame_("map"),
46-
dynamic_map_loading_grid_size_(50),
47-
dynamic_map_loading_update_distance_(dynamic_map_loading_grid_size_ * sqrt(2)),
48-
dynamic_map_loading_map_radius_(dynamic_map_loading_grid_size_ * sqrt(5))
46+
dynamic_map_loading_grid_size_(declare_parameter<double>("dynamic_map_loading_grid_size")),
47+
dynamic_map_loading_update_distance_(
48+
declare_parameter<double>("dynamic_map_loading_update_distance")),
49+
dynamic_map_loading_map_radius_(declare_parameter<double>("dynamic_map_loading_map_radius"))
4950
{
50-
client_callback_group_ = this->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
51+
client_callback_group_ =
52+
this->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
5153
timer_callback_group_ = this->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
5254

5355
dynamic_map_pub_ = this->create_publisher<autoware_auto_mapping_msgs::msg::HADMapBin>(
@@ -60,6 +62,13 @@ DynamicLaneletProviderNode::DynamicLaneletProviderNode(const rclcpp::NodeOptions
6062
"/localization/kinematic_state", 100,
6163
std::bind(&DynamicLaneletProviderNode::onOdometry, this, std::placeholders::_1));
6264

65+
const auto adaptor = component_interface_utils::NodeAdaptor(this);
66+
adaptor.init_sub(
67+
sub_map_projector_info_,
68+
[this](const map_interface::MapProjectorInfo::Message::ConstSharedPtr msg) {
69+
projector_info_ = *msg;
70+
});
71+
6372
lanelet_map_meta_data_sub_ =
6473
this->create_subscription<autoware_map_msgs::msg::LaneletMapMetaData>(
6574
"/map/lanelet_map_meta_data", rclcpp::QoS{1}.transient_local(),
@@ -92,6 +101,10 @@ void DynamicLaneletProviderNode::mapUpdateTimerCallback()
92101
return;
93102
}
94103

104+
if (projector_info_ == std::nullopt || lanelet_map_meta_data_list_.empty()) {
105+
RCLCPP_ERROR_ONCE(get_logger(), "Check your lanelet map metadata and projector info.");
106+
}
107+
95108
if (should_update_map()) {
96109
RCLCPP_INFO(get_logger(), "Start updating lanelet map (timer callback)");
97110

@@ -102,25 +115,31 @@ void DynamicLaneletProviderNode::mapUpdateTimerCallback()
102115

103116
void DynamicLaneletProviderNode::updateMap(const geometry_msgs::msg::Point & pose)
104117
{
105-
lanelet::projection::MGRSProjector projector;
106-
107118
std::vector<int> cache_ids;
108-
for (const auto & metadata : lanelet_map_meta_data_list_) {
109-
lanelet::GPSPoint gps_point;
110-
gps_point.lat = metadata.origin_lat;
111-
gps_point.lon = metadata.origin_lon;
112-
gps_point.ele = 0;
113-
114-
lanelet::BasicPoint3d point = projector.forward(gps_point);
115-
116-
double distance = norm_xy(point, pose);
117-
if (distance < dynamic_map_loading_map_radius_) {
118-
cache_ids.push_back(metadata.id);
119+
if (projector_info_.value().projector_type != tier4_map_msgs::msg::MapProjectorInfo::LOCAL) {
120+
std::unique_ptr<lanelet::Projector> projector =
121+
geography_utils::get_lanelet2_projector(projector_info_.value());
122+
123+
for (const auto & metadata : lanelet_map_meta_data_list_) {
124+
lanelet::GPSPoint gps_point;
125+
gps_point.lat = metadata.origin_lat;
126+
gps_point.lon = metadata.origin_lon;
127+
gps_point.ele = 0;
128+
129+
lanelet::BasicPoint3d point = projector->forward(gps_point);
130+
131+
double distance = norm_xy(point, pose);
132+
if (distance < dynamic_map_loading_map_radius_) {
133+
cache_ids.push_back(metadata.id);
134+
}
119135
}
136+
} else {
137+
// TODO: cannot reach LocalProjector here
120138
}
121139

122-
for (const auto & id : cache_ids) {
123-
std::cout << "id: " << id << std::endl;
140+
if (cache_ids.empty()) {
141+
RCLCPP_ERROR(get_logger(), "No lanelet map is found in the radius.");
142+
return;
124143
}
125144

126145
auto request = std::make_shared<autoware_map_msgs::srv::GetDifferentialLanelet2Map::Request>();

map/map_loader/include/map_loader/lanelet2_differential_loader_module.hpp

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include "lanelet2_extension/io/autoware_multi_osm_parser.hpp"
1919
#include "map_loader/utils.hpp"
2020

21+
#include <component_interface_specs/map.hpp>
22+
#include <component_interface_utils/rclcpp.hpp>
23+
#include <geography_utils/lanelet2_projector.hpp>
2124
#include <lanelet2_extension/io/autoware_osm_parser.hpp>
2225
#include <lanelet2_extension/projection/mgrs_projector.hpp>
2326
#include <lanelet2_extension/utility/message_conversion.hpp>
@@ -28,6 +31,7 @@
2831
#include "autoware_map_msgs/srv/get_differential_lanelet2_map.hpp"
2932
#include <autoware_auto_mapping_msgs/msg/had_map_bin.hpp>
3033
#include <autoware_map_msgs/msg/lanelet_map_meta_data.hpp>
34+
#include <tier4_map_msgs/msg/map_projector_info.hpp>
3135

3236
#include <lanelet2_core/LaneletMap.h>
3337
#include <lanelet2_core/geometry/LineString.h>
@@ -57,6 +61,11 @@ class Lanelet2DifferentialLoaderModule
5761
rclcpp::Publisher<autoware_map_msgs::msg::LaneletMapMetaData>::SharedPtr
5862
pub_lanelet_map_meta_data_;
5963

64+
component_interface_utils::Subscription<map_interface::MapProjectorInfo>::SharedPtr
65+
sub_map_projector_info_;
66+
67+
std::optional<tier4_map_msgs::msg::MapProjectorInfo> projector_info_;
68+
6069
bool onServiceGetDifferentialLanelet2Map(
6170
GetDifferentialLanelet2Map::Request::SharedPtr req,
6271
GetDifferentialLanelet2Map::Response::SharedPtr res);

map/map_loader/src/lanelet2_map_loader/lanelet2_differential_loader_module.cpp

+53-23
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "map_loader/lanelet2_differential_loader_module.hpp"
1616

17+
#include "lanelet2_local_projector.hpp"
1718
#include "map_loader/lanelet2_map_loader_node.hpp"
1819

1920
Lanelet2DifferentialLoaderModule::Lanelet2DifferentialLoaderModule(
@@ -33,6 +34,13 @@ Lanelet2DifferentialLoaderModule::Lanelet2DifferentialLoaderModule(
3334
pub_lanelet_map_meta_data_->publish(msg);
3435
}
3536

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+
3644
get_differential_lanelet2_maps_service_ = node->create_service<GetDifferentialLanelet2Map>(
3745
"/map/get_differential_lanelet_map",
3846
std::bind(
@@ -75,39 +83,61 @@ bool Lanelet2DifferentialLoaderModule::differentialLanelet2Load(
7583
return false;
7684
}
7785

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());
83102

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+
}
87114
}
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+
}
90124
}
91-
}
92125

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+
}
101134

102-
// overwrite centerline
103-
lanelet::utils::overwriteLaneletsCenterline(map, 5.0, false);
104-
// convert map to binary message
105-
{
106135
const auto map_bin_msg =
107136
Lanelet2MapLoaderNode::create_map_bin_msg(map, lanelet2_paths[0], rclcpp::Clock().now());
108137

109138
response->differential_map = map_bin_msg;
110139
}
140+
111141
return true;
112142
}
113143

0 commit comments

Comments
 (0)