Skip to content

Commit 0cc5cae

Browse files
Fixed to run
Signed-off-by: Shintaro Sakoda <shintaro.sakoda@tier4.jp>
1 parent 56400c0 commit 0cc5cae

File tree

4 files changed

+42
-25
lines changed

4 files changed

+42
-25
lines changed

localization/pose_initializer/launch/pose_initializer.launch.xml

+1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
<param name="fit_target" value="pointcloud_map"/>
2828
<remap from="~/pointcloud_map" to="/map/pointcloud_map"/>
2929
<remap from="~/partial_map_load" to="/map/get_partial_pointcloud_map"/>
30+
<remap from="~/vector_map" to="/map/vector_map"/>
3031
</node>
3132
</launch>

map/map_height_fitter/launch/map_height_fitter.launch.xml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<param name="fit_target" value="pointcloud_map"/>
77
<remap from="~/pointcloud_map" to="/map/pointcloud_map"/>
88
<remap from="~/partial_map_load" to="/map/get_partial_pointcloud_map"/>
9+
<remap from="~/vector_map" to="/map/vector_map"/>
910
</node>
1011
</group>
1112
</launch>

map/map_height_fitter/src/map_height_fitter.cpp

+39-25
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct MapHeightFitter::Impl
4040
void on_pcd_map(const sensor_msgs::msg::PointCloud2::ConstSharedPtr msg);
4141
void on_vector_map(const autoware_auto_mapping_msgs::msg::HADMapBin::ConstSharedPtr msg);
4242
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);
4444
std::optional<Point> fit(const Point & position, const std::string & frame);
4545

4646
tf2::BufferCore tf2_buffer_;
@@ -166,26 +166,46 @@ void MapHeightFitter::Impl::on_vector_map(
166166
{
167167
vector_map_ = std::make_shared<lanelet::LaneletMap>();
168168
lanelet::utils::conversion::fromBinMsg(*msg, vector_map_);
169+
const auto logger = node_->get_logger();
170+
map_frame_ = msg->header.frame_id;
169171
}
170172

171-
double MapHeightFitter::Impl::get_ground_height(const tf2::Vector3 & point) const
173+
double MapHeightFitter::Impl::get_ground_height(const tf2::Vector3 & point)
172174
{
175+
const auto logger = node_->get_logger();
176+
173177
const double x = point.getX();
174178
const double y = point.getY();
175179

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);
187180
double height = INFINITY;
188181
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+
189209
for (const auto & p : map_cloud_->points) {
190210
const double dx = x - p.x;
191211
const double dy = y - p.y;
@@ -202,7 +222,12 @@ double MapHeightFitter::Impl::get_ground_height(const tf2::Vector3 & point) cons
202222
pose.position.y = y;
203223
pose.position.z = 0.0;
204224
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+
}
206231
height = closest_lanelet.centerline().back().z();
207232
}
208233

@@ -216,17 +241,6 @@ std::optional<Point> MapHeightFitter::Impl::fit(const Point & position, const st
216241

217242
RCLCPP_DEBUG(logger, "original point: %.3f %.3f %.3f", point.getX(), point.getY(), point.getZ());
218243

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-
230244
try {
231245
const auto stamped = tf2_buffer_.lookupTransform(map_frame_, frame, tf2::TimePointZero);
232246
tf2::Transform transform{tf2::Quaternion{}, tf2::Vector3{}};

system/default_ad_api_helpers/ad_api_adaptors/launch/rviz_adaptors.launch.xml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<remap from="~/initialpose" to="/initialpose"/>
99
<remap from="~/pointcloud_map" to="/map/pointcloud_map"/>
1010
<remap from="~/partial_map_load" to="/map/get_partial_pointcloud_map"/>
11+
<remap from="~/vector_map" to="/map/vector_map"/>
1112
</node>
1213
<node pkg="ad_api_adaptors" exec="routing_adaptor" name="routing_adaptor">
1314
<remap from="~/input/fixed_goal" to="/planning/mission_planning/goal"/>

0 commit comments

Comments
 (0)