@@ -40,7 +40,7 @@ struct MapHeightFitter::Impl
40
40
void on_pcd_map (const sensor_msgs::msg::PointCloud2::ConstSharedPtr msg);
41
41
void on_vector_map (const autoware_auto_mapping_msgs::msg::HADMapBin::ConstSharedPtr msg);
42
42
bool get_partial_point_cloud_map (const Point & point);
43
- double get_ground_height (const tf2::Vector3 & point) const ;
43
+ double get_ground_height (const tf2::Vector3 & point);
44
44
std::optional<Point > fit (const Point & position, const std::string & frame);
45
45
46
46
tf2::BufferCore tf2_buffer_;
@@ -166,26 +166,46 @@ void MapHeightFitter::Impl::on_vector_map(
166
166
{
167
167
vector_map_ = std::make_shared<lanelet::LaneletMap>();
168
168
lanelet::utils::conversion::fromBinMsg (*msg, vector_map_);
169
+ const auto logger = node_->get_logger ();
170
+ map_frame_ = msg->header .frame_id ;
169
171
}
170
172
171
- double MapHeightFitter::Impl::get_ground_height (const tf2::Vector3 & point) const
173
+ double MapHeightFitter::Impl::get_ground_height (const tf2::Vector3 & point)
172
174
{
175
+ const auto logger = node_->get_logger ();
176
+
173
177
const double x = point.getX ();
174
178
const double y = point.getY ();
175
179
176
- // find distance d to closest point
177
- double min_dist2 = INFINITY;
178
- for (const auto & p : map_cloud_->points ) {
179
- const double dx = x - p.x ;
180
- const double dy = y - p.y ;
181
- const double sd = (dx * dx) + (dy * dy);
182
- min_dist2 = std::min (min_dist2, sd);
183
- }
184
-
185
- // find lowest height within radius (d+1.0)
186
- const double radius2 = std::pow (std::sqrt (min_dist2) + 1.0 , 2.0 );
187
180
double height = INFINITY;
188
181
if (fit_target_ == " pointcloud_map" ) {
182
+ if (cli_pcd_map_) {
183
+ geometry_msgs::msg::Point position;
184
+ position.x = point.getX ();
185
+ position.y = point.getY ();
186
+ position.z = point.getZ ();
187
+ if (!get_partial_point_cloud_map (position)) {
188
+ return point.getZ ();
189
+ }
190
+ }
191
+
192
+ if (!map_cloud_) {
193
+ RCLCPP_WARN_STREAM (logger, " point cloud map is not ready" );
194
+ return point.getZ ();
195
+ }
196
+
197
+ // find distance d to closest point
198
+ double min_dist2 = INFINITY;
199
+ for (const auto & p : map_cloud_->points ) {
200
+ const double dx = x - p.x ;
201
+ const double dy = y - p.y ;
202
+ const double sd = (dx * dx) + (dy * dy);
203
+ min_dist2 = std::min (min_dist2, sd);
204
+ }
205
+
206
+ // find lowest height within radius (d+1.0)
207
+ const double radius2 = std::pow (std::sqrt (min_dist2) + 1.0 , 2.0 );
208
+
189
209
for (const auto & p : map_cloud_->points ) {
190
210
const double dx = x - p.x ;
191
211
const double dy = y - p.y ;
@@ -202,7 +222,12 @@ double MapHeightFitter::Impl::get_ground_height(const tf2::Vector3 & point) cons
202
222
pose.position .y = y;
203
223
pose.position .z = 0.0 ;
204
224
lanelet::ConstLanelet closest_lanelet;
205
- lanelet::utils::query::getClosestLanelet (all_lanelets, pose, &closest_lanelet);
225
+ const bool result =
226
+ lanelet::utils::query::getClosestLanelet (all_lanelets, pose, &closest_lanelet);
227
+ if (!result) {
228
+ RCLCPP_WARN_STREAM (logger, " failed to get closest lanelet" );
229
+ return point.getZ ();
230
+ }
206
231
height = closest_lanelet.centerline ().back ().z ();
207
232
}
208
233
@@ -216,17 +241,6 @@ std::optional<Point> MapHeightFitter::Impl::fit(const Point & position, const st
216
241
217
242
RCLCPP_DEBUG (logger, " original point: %.3f %.3f %.3f" , point.getX (), point.getY (), point.getZ ());
218
243
219
- if (cli_pcd_map_) {
220
- if (!get_partial_point_cloud_map (position)) {
221
- return std::nullopt;
222
- }
223
- }
224
-
225
- if (!map_cloud_) {
226
- RCLCPP_WARN_STREAM (logger, " point cloud map is not ready" );
227
- return std::nullopt;
228
- }
229
-
230
244
try {
231
245
const auto stamped = tf2_buffer_.lookupTransform (map_frame_, frame, tf2::TimePointZero);
232
246
tf2::Transform transform{tf2::Quaternion{}, tf2::Vector3{}};
0 commit comments