Skip to content

Commit 51a8af8

Browse files
authoredDec 28, 2023
fix(landmark_based_localizer): fix to for moving the definition code of landmarks (#5803)
* Fixed to use lanelet extension landmark Signed-off-by: Shintaro Sakoda <shintaro.sakoda@tier4.jp> * Fixed to build Signed-off-by: Shintaro Sakoda <shintaro.sakoda@tier4.jp> * Fixed link Signed-off-by: Shintaro Sakoda <shintaro.sakoda@tier4.jp> --------- Signed-off-by: Shintaro Sakoda <shintaro.sakoda@tier4.jp>
1 parent 3e6c3a5 commit 51a8af8

File tree

5 files changed

+19
-103
lines changed

5 files changed

+19
-103
lines changed
 

‎localization/landmark_based_localizer/README.md

+1-62
Original file line numberDiff line numberDiff line change
@@ -43,68 +43,7 @@ So, if the 4 vertices are considered as forming a tetrahedron and its volume exc
4343

4444
## Map specifications
4545

46-
For this package to work correctly, the poses of the landmarks must be specified in the Lanelet2 map format that `map_loader` and `landmark_manager` can interpret.
47-
48-
The four vertices of a landmark are defined counterclockwise.
49-
50-
The order of the four vertices is defined as follows. In the coordinate system of a landmark,
51-
52-
- the x-axis is parallel to the vector from the first vertex to the second vertex
53-
- the y-axis is parallel to the vector from the second vertex to the third vertex
54-
55-
![lanelet2 data structure](./doc_image/lanelet2_data_structure.drawio.svg)
56-
57-
### Example of `lanelet2_map.osm`
58-
59-
The values provided below are placeholders.
60-
Ensure to input the correct coordinates corresponding to the actual location where the landmark is placed, such as `lat`, `lon`, `mgrs_code`, `local_x`, `local_y`.
61-
62-
For example, when using the AR tag, it would look like this.
63-
64-
```xml
65-
...
66-
67-
<node id="1" lat="35.8xxxxx" lon="139.6xxxxx">
68-
<tag k="mgrs_code" v="99XXX000000"/>
69-
<tag k="local_x" v="22.2356"/>
70-
<tag k="local_y" v="87.4506"/>
71-
<tag k="ele" v="2.1725"/>
72-
</node>
73-
<node id="2" lat="35.8xxxxx" lon="139.6xxxxx">
74-
<tag k="mgrs_code" v="99XXX000000"/>
75-
<tag k="local_x" v="22.639"/>
76-
<tag k="local_y" v="87.5886"/>
77-
<tag k="ele" v="2.5947"/>
78-
</node>
79-
<node id="3" lat="35.8xxxxx" lon="139.6xxxxx">
80-
<tag k="mgrs_code" v="99XXX000000"/>
81-
<tag k="local_x" v="22.2331"/>
82-
<tag k="local_y" v="87.4713"/>
83-
<tag k="ele" v="3.0208"/>
84-
</node>
85-
<node id="4" lat="35.8xxxxx" lon="139.6xxxxx">
86-
<tag k="mgrs_code" v="99XXX000000"/>
87-
<tag k="local_x" v="21.8298"/>
88-
<tag k="local_y" v="87.3332"/>
89-
<tag k="ele" v="2.5985"/>
90-
</node>
91-
92-
...
93-
94-
<way id="5">
95-
<nd ref="1"/>
96-
<nd ref="2"/>
97-
<nd ref="3"/>
98-
<nd ref="4"/>
99-
<tag k="type" v="pose_marker"/>
100-
<tag k="subtype" v="apriltag_16h5"/>
101-
<tag k="area" v="yes"/>
102-
<tag k="marker_id" v="0"/>
103-
</way>
104-
105-
...
106-
107-
```
46+
See <https://github.com/autowarefoundation/autoware_common/blob/main/tmp/lanelet2_extension/docs/lanelet2_format_extension.md#localization-landmarks>
10847

10948
## About `consider_orientation`
11049

‎localization/landmark_based_localizer/ar_tag_based_localizer/src/ar_tag_based_localizer.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ ArTagBasedLocalizer::ArTagBasedLocalizer(const rclcpp::NodeOptions & options)
142142

143143
void ArTagBasedLocalizer::map_bin_callback(const HADMapBin::ConstSharedPtr & msg)
144144
{
145-
landmark_manager_.parse_landmarks(msg, "apriltag_16h5", this->get_logger());
145+
landmark_manager_.parse_landmarks(msg, "apriltag_16h5");
146146
const MarkerArray marker_msg = landmark_manager_.get_landmarks_as_marker_array_msg();
147147
mapped_tag_pose_pub_->publish(marker_msg);
148148
}
@@ -173,7 +173,7 @@ void ArTagBasedLocalizer::image_callback(const Image::ConstSharedPtr & msg)
173173
const Pose self_pose = interpolate_result.value().interpolated_pose.pose.pose;
174174

175175
// detect
176-
const std::vector<landmark_manager::Landmark> landmarks = detect_landmarks(msg);
176+
const std::vector<Landmark> landmarks = detect_landmarks(msg);
177177
if (landmarks.empty()) {
178178
return;
179179
}
@@ -183,7 +183,7 @@ void ArTagBasedLocalizer::image_callback(const Image::ConstSharedPtr & msg)
183183
PoseArray pose_array_msg;
184184
pose_array_msg.header.stamp = sensor_stamp;
185185
pose_array_msg.header.frame_id = "map";
186-
for (const landmark_manager::Landmark & landmark : landmarks) {
186+
for (const Landmark & landmark : landmarks) {
187187
const Pose detected_marker_on_map =
188188
tier4_autoware_utils::transformPose(landmark.pose, self_pose);
189189
pose_array_msg.poses.push_back(detected_marker_on_map);
@@ -293,7 +293,7 @@ std::vector<landmark_manager::Landmark> ArTagBasedLocalizer::detect_landmarks(
293293
cv_ptr->image.copyTo(in_image);
294294
} catch (cv_bridge::Exception & e) {
295295
RCLCPP_ERROR(this->get_logger(), "cv_bridge exception: %s", e.what());
296-
return std::vector<landmark_manager::Landmark>{};
296+
return std::vector<Landmark>{};
297297
}
298298

299299
// get transform from base_link to camera
@@ -303,15 +303,15 @@ std::vector<landmark_manager::Landmark> ArTagBasedLocalizer::detect_landmarks(
303303
tf_buffer_->lookupTransform("base_link", msg->header.frame_id, sensor_stamp);
304304
} catch (tf2::TransformException & ex) {
305305
RCLCPP_INFO(this->get_logger(), "Could not transform base_link to camera: %s", ex.what());
306-
return std::vector<landmark_manager::Landmark>{};
306+
return std::vector<Landmark>{};
307307
}
308308

309309
// detect
310310
std::vector<aruco::Marker> markers;
311311
detector_.detect(in_image, markers, cam_param_, marker_size_, false);
312312

313313
// parse
314-
std::vector<landmark_manager::Landmark> landmarks;
314+
std::vector<Landmark> landmarks;
315315

316316
for (aruco::Marker & marker : markers) {
317317
// convert marker pose to tf
@@ -327,7 +327,7 @@ std::vector<landmark_manager::Landmark> ArTagBasedLocalizer::detect_landmarks(
327327
const double distance = std::hypot(pose.position.x, pose.position.y, pose.position.z);
328328
if (distance <= distance_threshold_) {
329329
tf2::doTransform(pose, pose, transform_sensor_to_base_link);
330-
landmarks.push_back(landmark_manager::Landmark{std::to_string(marker.id), pose});
330+
landmarks.push_back(Landmark{std::to_string(marker.id), pose});
331331
}
332332

333333
// for debug, drawing the detected markers

‎localization/landmark_based_localizer/ar_tag_based_localizer/src/ar_tag_based_localizer.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class ArTagBasedLocalizer : public rclcpp::Node
8080
using TransformStamped = geometry_msgs::msg::TransformStamped;
8181
using MarkerArray = visualization_msgs::msg::MarkerArray;
8282
using DiagnosticArray = diagnostic_msgs::msg::DiagnosticArray;
83+
using Landmark = landmark_manager::Landmark;
8384

8485
public:
8586
explicit ArTagBasedLocalizer(const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
@@ -89,7 +90,7 @@ class ArTagBasedLocalizer : public rclcpp::Node
8990
void image_callback(const Image::ConstSharedPtr & msg);
9091
void cam_info_callback(const CameraInfo::ConstSharedPtr & msg);
9192
void ekf_pose_callback(const PoseWithCovarianceStamped::ConstSharedPtr & msg);
92-
std::vector<landmark_manager::Landmark> detect_landmarks(const Image::ConstSharedPtr & msg);
93+
std::vector<Landmark> detect_landmarks(const Image::ConstSharedPtr & msg);
9394

9495
// Parameters
9596
float marker_size_{};

‎localization/landmark_based_localizer/landmark_manager/include/landmark_manager/landmark_manager.hpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#ifndef LANDMARK_MANAGER__LANDMARK_MANAGER_HPP_
1616
#define LANDMARK_MANAGER__LANDMARK_MANAGER_HPP_
1717

18+
#include "lanelet2_extension/localization/landmark.hpp"
19+
1820
#include <rclcpp/rclcpp.hpp>
1921

2022
#include "autoware_auto_mapping_msgs/msg/had_map_bin.hpp"
@@ -40,13 +42,13 @@ class LandmarkManager
4042
public:
4143
void parse_landmarks(
4244
const autoware_auto_mapping_msgs::msg::HADMapBin::ConstSharedPtr & msg,
43-
const std::string & target_subtype, const rclcpp::Logger & logger);
45+
const std::string & target_subtype);
4446

4547
[[nodiscard]] visualization_msgs::msg::MarkerArray get_landmarks_as_marker_array_msg() const;
4648

4749
[[nodiscard]] geometry_msgs::msg::Pose calculate_new_self_pose(
48-
const std::vector<landmark_manager::Landmark> & detected_landmarks,
49-
const geometry_msgs::msg::Pose & self_pose, const bool consider_orientation) const;
50+
const std::vector<Landmark> & detected_landmarks, const geometry_msgs::msg::Pose & self_pose,
51+
const bool consider_orientation) const;
5052

5153
private:
5254
// To allow multiple landmarks with the same id to be registered on a vector_map,

‎localization/landmark_based_localizer/landmark_manager/src/landmark_manager.cpp

+4-30
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,17 @@ namespace landmark_manager
2929

3030
void LandmarkManager::parse_landmarks(
3131
const autoware_auto_mapping_msgs::msg::HADMapBin::ConstSharedPtr & msg,
32-
const std::string & target_subtype, const rclcpp::Logger & logger)
32+
const std::string & target_subtype)
3333
{
34-
RCLCPP_INFO_STREAM(logger, "msg->format_version: " << msg->format_version);
35-
RCLCPP_INFO_STREAM(logger, "msg->map_format: " << msg->map_format);
36-
RCLCPP_INFO_STREAM(logger, "msg->map_version: " << msg->map_version);
37-
RCLCPP_INFO_STREAM(logger, "msg->data.size(): " << msg->data.size());
38-
lanelet::LaneletMapPtr lanelet_map_ptr{std::make_shared<lanelet::LaneletMap>()};
39-
lanelet::utils::conversion::fromBinMsg(*msg, lanelet_map_ptr);
40-
41-
for (const auto & poly : lanelet_map_ptr->polygonLayer) {
42-
const std::string type{poly.attributeOr(lanelet::AttributeName::Type, "none")};
43-
if (type != "pose_marker") {
44-
continue;
45-
}
46-
const std::string subtype{poly.attributeOr(lanelet::AttributeName::Subtype, "none")};
47-
if (subtype != target_subtype) {
48-
continue;
49-
}
50-
34+
std::vector<lanelet::Polygon3d> landmarks =
35+
lanelet::localization::parseLandmarkPolygons(msg, target_subtype);
36+
for (const lanelet::Polygon3d & poly : landmarks) {
5137
// Get landmark_id
5238
const std::string landmark_id = poly.attributeOr("marker_id", "none");
5339

5440
// Get 4 vertices
5541
const auto & vertices = poly.basicPolygon();
5642
if (vertices.size() != 4) {
57-
RCLCPP_WARN_STREAM(logger, "vertices.size() (" << vertices.size() << ") != 4");
5843
continue;
5944
}
6045

@@ -65,12 +50,8 @@ void LandmarkManager::parse_landmarks(
6550
const auto & v2 = vertices[2];
6651
const auto & v3 = vertices[3];
6752
const double volume = (v1 - v0).cross(v2 - v0).dot(v3 - v0) / 6.0;
68-
RCLCPP_INFO_STREAM(logger, "volume = " << volume);
6953
const double volume_threshold = 1e-5;
7054
if (volume > volume_threshold) {
71-
RCLCPP_WARN_STREAM(
72-
logger,
73-
"volume (" << volume << ") > threshold (" << volume_threshold << "), This is not plane.");
7455
continue;
7556
}
7657

@@ -99,13 +80,6 @@ void LandmarkManager::parse_landmarks(
9980

10081
// Add
10182
landmarks_map_[landmark_id].push_back(pose);
102-
RCLCPP_INFO_STREAM(logger, "id: " << landmark_id);
103-
RCLCPP_INFO_STREAM(
104-
logger,
105-
"(x, y, z) = " << pose.position.x << ", " << pose.position.y << ", " << pose.position.z);
106-
RCLCPP_INFO_STREAM(
107-
logger, "q = " << pose.orientation.x << ", " << pose.orientation.y << ", "
108-
<< pose.orientation.z << ", " << pose.orientation.w);
10983
}
11084
}
11185

0 commit comments

Comments
 (0)
Please sign in to comment.