Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(map_height_fitter): fitting by vector_map #6340

Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4eb1bba
Added fit_target
SakodaShintaro Feb 6, 2024
8ec248e
Merge remote-tracking branch 'origin' into feat/z_fitting_by_vectormap
SakodaShintaro Feb 6, 2024
56400c0
Fixed group
SakodaShintaro Feb 6, 2024
0cc5cae
Fixed to run
SakodaShintaro Feb 6, 2024
db575e3
Merge remote-tracking branch 'origin' into feat/z_fitting_by_vectormap
SakodaShintaro Feb 6, 2024
c7eb386
style(pre-commit): autofix
pre-commit-ci[bot] Feb 7, 2024
ee19f39
Fixed to work by pointcloud_map
SakodaShintaro Feb 7, 2024
0b6cb3c
Fixed comments
SakodaShintaro Feb 7, 2024
f6cdffd
Added a comment
SakodaShintaro Feb 7, 2024
a6b251a
Fixed a comment
SakodaShintaro Feb 7, 2024
d14e60b
Fixed to use arg
SakodaShintaro Feb 7, 2024
2cb8c75
Added info log
SakodaShintaro Feb 7, 2024
782a99e
FIxed default value
SakodaShintaro Feb 7, 2024
6c78842
Merge branch 'main' into feat/z_fitting_by_vectormap
SakodaShintaro Feb 7, 2024
f221790
Merge branch 'main' into feat/z_fitting_by_vectormap
SakodaShintaro Feb 7, 2024
a6e6158
FIxed default values
SakodaShintaro Feb 7, 2024
a8fc4bd
Updated schema.json
SakodaShintaro Feb 7, 2024
e4f1d93
Fixed description of fit_target
SakodaShintaro Feb 7, 2024
d89c660
Merge branch 'main' into feat/z_fitting_by_vectormap
SakodaShintaro Feb 8, 2024
d52569c
Fixed arg name
SakodaShintaro Feb 8, 2024
23e01b5
Restore const
SakodaShintaro Feb 8, 2024
21b4f3f
Fixed map_height_fitter.param.yaml
SakodaShintaro Feb 8, 2024
69ceb62
Fixed map_height_fitter.schema.json
SakodaShintaro Feb 8, 2024
7fd0b40
style(pre-commit): autofix
pre-commit-ci[bot] Feb 8, 2024
25a6a4e
Merge branch 'main' into feat/z_fitting_by_vectormap
isamu-takagi Feb 9, 2024
9a47cde
Removed an unused variable
SakodaShintaro Feb 13, 2024
461fd40
Merge branch 'main' into feat/z_fitting_by_vectormap
SakodaShintaro Feb 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<arg name="stop_check_enabled"/>

<arg name="sub_gnss_pose_cov" default="sub_gnss_pose_cov"/>
<arg name="gnss_initial_pose_auto_fix_target" default="pointcloud_map"/>

<node pkg="pose_initializer" exec="pose_initializer_node" name="pose_initializer_node">
<param from="$(var config_file)" allow_substs="true"/>
Expand All @@ -17,8 +18,10 @@
<remap from="pose_reset" to="/initialpose3d"/>
<remap from="ekf_trigger_node" to="/localization/pose_twist_fusion_filter/trigger_node"/>
<remap from="ndt_trigger_node" to="/localization/pose_estimator/trigger_node"/>
<param name="map_loader_name" value="/map/pointcloud_map_loader"/>
<param name="map_height_fitter.map_loader_name" value="/map/pointcloud_map_loader"/>
<param name="map_height_fitter.target" value="$(var gnss_initial_pose_auto_fix_target)"/>
<remap from="~/pointcloud_map" to="/map/pointcloud_map"/>
<remap from="~/partial_map_load" to="/map/get_partial_pointcloud_map"/>
<remap from="~/vector_map" to="/map/vector_map"/>
</node>
</launch>
4 changes: 4 additions & 0 deletions map/map_height_fitter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ ament_auto_add_library(map_height_fitter SHARED
)
target_link_libraries(map_height_fitter ${PCL_LIBRARIES})

# When adding `<depend>lanelet2_extension</depend>` to package.xml, many warnings are generated.
# These are treated as errors in compile, so pedantic warnings are disabled for this package.
target_compile_options(map_height_fitter PRIVATE -Wno-pedantic)

ament_auto_add_executable(node
src/node.cpp
)
Expand Down
4 changes: 3 additions & 1 deletion map/map_height_fitter/config/map_height_fitter.param.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/**:
ros__parameters:
map_loader_name: "/map/pointcloud_map_loader"
map_height_fitter:
map_loader_name: "/map/pointcloud_map_loader"
target: "pointcloud_map"
1 change: 1 addition & 0 deletions map/map_height_fitter/launch/map_height_fitter.launch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<param from="$(var param_path)"/>
<remap from="~/pointcloud_map" to="/map/pointcloud_map"/>
<remap from="~/partial_map_load" to="/map/get_partial_pointcloud_map"/>
<remap from="~/vector_map" to="/map/vector_map"/>
</node>
</group>
</launch>
2 changes: 2 additions & 0 deletions map/map_height_fitter/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>autoware_auto_mapping_msgs</depend>
<depend>autoware_map_msgs</depend>
<depend>geometry_msgs</depend>
<depend>lanelet2_extension</depend>
<depend>libpcl-common</depend>
<depend>pcl_conversions</depend>
<depend>rclcpp</depend>
Expand Down
14 changes: 12 additions & 2 deletions map/map_height_fitter/schema/map_height_fitter.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@
"type": "string",
"description": "Node name of the map loader from which this map_height_fitter will retrieve its parameters",
"default": "/map/pointcloud_map_loader"
},
"target": {
"type": "string",
"description": "Target map to fit (choose from 'pointcloud_map', 'vector_map')",
"default": "pointcloud_map"
}
},
"required": ["map_loader_name"],
"required": ["map_loader_name", "target"],
"additionalProperties": false
}
},
Expand All @@ -21,7 +26,12 @@
"type": "object",
"properties": {
"ros__parameters": {
"$ref": "#/definitions/map_height_fitter"
"type": "object",
"properties": {
"map_height_fitter": {
"$ref": "#/definitions/map_height_fitter"
}
}
}
},
"required": ["ros__parameters"],
Expand Down
222 changes: 150 additions & 72 deletions map/map_height_fitter/src/map_height_fitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@

#include "map_height_fitter/map_height_fitter.hpp"

#include <lanelet2_extension/utility/message_conversion.hpp>
#include <lanelet2_extension/utility/query.hpp>

#include <autoware_auto_mapping_msgs/msg/had_map_bin.hpp>
#include <autoware_map_msgs/srv/get_partial_point_cloud_map.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>

#include <lanelet2_core/Forward.h>
#include <lanelet2_core/LaneletMap.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl_conversions/pcl_conversions.h>
Expand All @@ -31,52 +37,74 @@
static constexpr char enable_partial_load[] = "enable_partial_load";

explicit Impl(rclcpp::Node * node);
void on_map(const sensor_msgs::msg::PointCloud2::ConstSharedPtr msg);
void on_pcd_map(const sensor_msgs::msg::PointCloud2::ConstSharedPtr msg);
void on_vector_map(const autoware_auto_mapping_msgs::msg::HADMapBin::ConstSharedPtr msg);
bool get_partial_point_cloud_map(const Point & point);
double get_ground_height(const tf2::Vector3 & point) const;
double get_ground_height(const Point & point) const;
std::optional<Point> fit(const Point & position, const std::string & frame);

tf2::BufferCore tf2_buffer_;
tf2_ros::TransformListener tf2_listener_;
std::string map_frame_;
pcl::PointCloud<pcl::PointXYZ>::Ptr map_cloud_;
rclcpp::Node * node_;

std::string fit_target_;

// for fitting by pointcloud_map_loader
rclcpp::CallbackGroup::SharedPtr group_;
rclcpp::Client<autoware_map_msgs::srv::GetPartialPointCloudMap>::SharedPtr cli_map_;
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr sub_map_;
rclcpp::AsyncParametersClient::SharedPtr params_map_loader_;
pcl::PointCloud<pcl::PointXYZ>::Ptr map_cloud_;
rclcpp::Client<autoware_map_msgs::srv::GetPartialPointCloudMap>::SharedPtr cli_pcd_map_;
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr sub_pcd_map_;
rclcpp::AsyncParametersClient::SharedPtr params_pcd_map_loader_;

// for fitting by vector_map_loader
lanelet::LaneletMapPtr vector_map_;
rclcpp::Subscription<autoware_auto_mapping_msgs::msg::HADMapBin>::SharedPtr sub_vector_map_;
};

MapHeightFitter::Impl::Impl(rclcpp::Node * node) : tf2_listener_(tf2_buffer_), node_(node)
{
const auto callback = [this](const std::shared_future<std::vector<rclcpp::Parameter>> & future) {
bool partial_load = false;
for (const auto & param : future.get()) {
if (param.get_name() == enable_partial_load) {
partial_load = param.as_bool();
}
}

if (partial_load) {
group_ = node_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
cli_map_ = node_->create_client<autoware_map_msgs::srv::GetPartialPointCloudMap>(
"~/partial_map_load", rmw_qos_profile_default, group_);
} else {
const auto durable_qos = rclcpp::QoS(1).transient_local();
sub_map_ = node_->create_subscription<sensor_msgs::msg::PointCloud2>(
"~/pointcloud_map", durable_qos,
std::bind(&MapHeightFitter::Impl::on_map, this, std::placeholders::_1));
}
};

const auto map_loader_name = node->declare_parameter<std::string>("map_loader_name");
params_map_loader_ = rclcpp::AsyncParametersClient::make_shared(node, map_loader_name);
params_map_loader_->wait_for_service();
params_map_loader_->get_parameters({enable_partial_load}, callback);
fit_target_ = node->declare_parameter<std::string>("map_height_fitter.target");
if (fit_target_ == "pointcloud_map") {

Check warning on line 68 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L67-L68

Added lines #L67 - L68 were not covered by tests
const auto callback =
[this](const std::shared_future<std::vector<rclcpp::Parameter>> & future) {

Check warning on line 70 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L70

Added line #L70 was not covered by tests
bool partial_load = false;
for (const auto & param : future.get()) {
if (param.get_name() == enable_partial_load) {
partial_load = param.as_bool();

Check warning on line 74 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L72-L74

Added lines #L72 - L74 were not covered by tests
}
}

if (partial_load) {
group_ = node_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
cli_pcd_map_ = node_->create_client<autoware_map_msgs::srv::GetPartialPointCloudMap>(

Check warning on line 80 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L78-L80

Added lines #L78 - L80 were not covered by tests
"~/partial_map_load", rmw_qos_profile_default, group_);
} else {
const auto durable_qos = rclcpp::QoS(1).transient_local();
sub_pcd_map_ = node_->create_subscription<sensor_msgs::msg::PointCloud2>(

Check warning on line 84 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L83-L84

Added lines #L83 - L84 were not covered by tests
"~/pointcloud_map", durable_qos,
std::bind(&MapHeightFitter::Impl::on_pcd_map, this, std::placeholders::_1));

Check warning on line 86 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L86

Added line #L86 was not covered by tests
}
};

Check warning on line 88 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L88

Added line #L88 was not covered by tests

const auto map_loader_name =
node->declare_parameter<std::string>("map_height_fitter.map_loader_name");
params_pcd_map_loader_ = rclcpp::AsyncParametersClient::make_shared(node, map_loader_name);

Check warning on line 92 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L91-L92

Added lines #L91 - L92 were not covered by tests
params_pcd_map_loader_->wait_for_service();
params_pcd_map_loader_->get_parameters({enable_partial_load}, callback);

Check warning on line 94 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L94

Added line #L94 was not covered by tests

} else if (fit_target_ == "vector_map") {
const auto durable_qos = rclcpp::QoS(1).transient_local();
sub_vector_map_ = node_->create_subscription<autoware_auto_mapping_msgs::msg::HADMapBin>(

Check warning on line 98 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L96-L98

Added lines #L96 - L98 were not covered by tests
"~/vector_map", durable_qos,
std::bind(&MapHeightFitter::Impl::on_vector_map, this, std::placeholders::_1));

Check warning on line 100 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L100

Added line #L100 was not covered by tests

} else {
throw std::runtime_error("invalid fit_target");

Check warning on line 103 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L103

Added line #L103 was not covered by tests
}
}

void MapHeightFitter::Impl::on_map(const sensor_msgs::msg::PointCloud2::ConstSharedPtr msg)
void MapHeightFitter::Impl::on_pcd_map(const sensor_msgs::msg::PointCloud2::ConstSharedPtr msg)

Check warning on line 107 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L107

Added line #L107 was not covered by tests
{
map_frame_ = msg->header.frame_id;
map_cloud_ = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
Expand All @@ -87,11 +115,11 @@
{
const auto logger = node_->get_logger();

if (!cli_map_) {
if (!cli_pcd_map_) {

Check warning on line 118 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L118

Added line #L118 was not covered by tests
RCLCPP_WARN_STREAM(logger, "Partial map loading in pointcloud_map_loader is not enabled");
return false;
}
if (!cli_map_->service_is_ready()) {
if (!cli_pcd_map_->service_is_ready()) {

Check warning on line 122 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L122

Added line #L122 was not covered by tests
RCLCPP_WARN_STREAM(logger, "Partial map loading in pointcloud_map_loader is not ready");
return false;
}
Expand All @@ -102,7 +130,7 @@
req->area.radius = 50;

RCLCPP_DEBUG(logger, "Send request to map_loader");
auto future = cli_map_->async_send_request(req);
auto future = cli_pcd_map_->async_send_request(req);

Check warning on line 133 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L133

Added line #L133 was not covered by tests
auto status = future.wait_for(std::chrono::seconds(1));
while (status != std::future_status::ready) {
RCLCPP_DEBUG(logger, "waiting response");
Expand Down Expand Up @@ -134,72 +162,122 @@
return true;
}

double MapHeightFitter::Impl::get_ground_height(const tf2::Vector3 & point) const
void MapHeightFitter::Impl::on_vector_map(

Check warning on line 165 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L165

Added line #L165 was not covered by tests
const autoware_auto_mapping_msgs::msg::HADMapBin::ConstSharedPtr msg)
{
const double x = point.getX();
const double y = point.getY();

// find distance d to closest point
double min_dist2 = INFINITY;
for (const auto & p : map_cloud_->points) {
const double dx = x - p.x;
const double dy = y - p.y;
const double sd = (dx * dx) + (dy * dy);
min_dist2 = std::min(min_dist2, sd);
}
vector_map_ = std::make_shared<lanelet::LaneletMap>();
lanelet::utils::conversion::fromBinMsg(*msg, vector_map_);
const auto logger = node_->get_logger();
map_frame_ = msg->header.frame_id;
}

Check warning on line 172 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L168-L172

Added lines #L168 - L172 were not covered by tests

double MapHeightFitter::Impl::get_ground_height(const Point & point) const

Check warning on line 174 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L174

Added line #L174 was not covered by tests
{
const auto logger = node_->get_logger();

Check warning on line 176 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L176

Added line #L176 was not covered by tests

const double x = point.x;
const double y = point.y;

Check warning on line 179 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L178-L179

Added lines #L178 - L179 were not covered by tests

// find lowest height within radius (d+1.0)
const double radius2 = std::pow(std::sqrt(min_dist2) + 1.0, 2.0);
double height = INFINITY;
for (const auto & p : map_cloud_->points) {
const double dx = x - p.x;
const double dy = y - p.y;
const double sd = (dx * dx) + (dy * dy);
if (sd < radius2) {
height = std::min(height, static_cast<double>(p.z));
if (fit_target_ == "pointcloud_map") {

Check warning on line 182 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L182

Added line #L182 was not covered by tests
// find distance d to closest point
double min_dist2 = INFINITY;
for (const auto & p : map_cloud_->points) {
const double dx = x - p.x;
const double dy = y - p.y;
const double sd = (dx * dx) + (dy * dy);
min_dist2 = std::min(min_dist2, sd);

Check warning on line 189 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L184-L189

Added lines #L184 - L189 were not covered by tests
}

// find lowest height within radius (d+1.0)
const double radius2 = std::pow(std::sqrt(min_dist2) + 1.0, 2.0);

Check warning on line 193 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L193

Added line #L193 was not covered by tests

for (const auto & p : map_cloud_->points) {
const double dx = x - p.x;
const double dy = y - p.y;
const double sd = (dx * dx) + (dy * dy);
if (sd < radius2) {
height = std::min(height, static_cast<double>(p.z));

Check warning on line 200 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L195-L200

Added lines #L195 - L200 were not covered by tests
}
}
} else if (fit_target_ == "vector_map") {
lanelet::ConstLanelets all_lanelets = lanelet::utils::query::laneletLayer(vector_map_);

Check warning on line 204 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L203-L204

Added lines #L203 - L204 were not covered by tests

geometry_msgs::msg::Pose pose;
pose.position.x = x;
pose.position.y = y;
pose.position.z = 0.0;
lanelet::ConstLanelet closest_lanelet;

Check warning on line 210 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L207-L210

Added lines #L207 - L210 were not covered by tests
const bool result =
lanelet::utils::query::getClosestLanelet(all_lanelets, pose, &closest_lanelet);
if (!result) {
RCLCPP_WARN_STREAM(logger, "failed to get closest lanelet");
return point.z;

Check warning on line 215 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L212-L215

Added lines #L212 - L215 were not covered by tests
}
height = closest_lanelet.centerline().back().z();

Check warning on line 217 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L217

Added line #L217 was not covered by tests
}

return std::isfinite(height) ? height : point.getZ();
return std::isfinite(height) ? height : point.z;

Check warning on line 220 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L220

Added line #L220 was not covered by tests
}

std::optional<Point> MapHeightFitter::Impl::fit(const Point & position, const std::string & frame)
{
const auto logger = node_->get_logger();
tf2::Vector3 point(position.x, position.y, position.z);
RCLCPP_INFO_STREAM(logger, "fit_target: " << fit_target_ << ", frame: " << frame);

Check warning on line 226 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L226

Added line #L226 was not covered by tests

RCLCPP_DEBUG(logger, "original point: %.3f %.3f %.3f", point.getX(), point.getY(), point.getZ());
Point point;
point.x = position.x;
point.y = position.y;
point.z = position.z;

Check warning on line 231 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L229-L231

Added lines #L229 - L231 were not covered by tests

if (cli_map_) {
if (!get_partial_point_cloud_map(position)) {
RCLCPP_DEBUG(logger, "original point: %.3f %.3f %.3f", point.x, point.y, point.z);

Check warning on line 233 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L233

Added line #L233 was not covered by tests

// prepare data
if (fit_target_ == "pointcloud_map") {
if (cli_pcd_map_) { // if cli_pcd_map_ is available, prepare pointcloud map by partial loading
if (!get_partial_point_cloud_map(position)) {
RCLCPP_WARN_STREAM(logger, "failed to get partial point cloud map");
return std::nullopt;

Check warning on line 240 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L236-L240

Added lines #L236 - L240 were not covered by tests
}
} // otherwise, pointcloud map should be already prepared by on_pcd_map
if (!map_cloud_) {
RCLCPP_WARN_STREAM(logger, "point cloud map is not ready");
return std::nullopt;

Check warning on line 245 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L243-L245

Added lines #L243 - L245 were not covered by tests
}
} else if (fit_target_ == "vector_map") {

Check warning on line 247 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L247

Added line #L247 was not covered by tests
// vector_map_ should be already prepared by on_vector_map
if (!vector_map_) {
RCLCPP_WARN_STREAM(logger, "vector map is not ready");

Check warning on line 250 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L249-L250

Added lines #L249 - L250 were not covered by tests
return std::nullopt;
}
} else {
throw std::runtime_error("invalid fit_target");

Check warning on line 254 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L254

Added line #L254 was not covered by tests
}

if (!map_cloud_) {
RCLCPP_WARN_STREAM(logger, "point cloud map is not ready");
// transform frame to map_frame_
try {
const auto stamped = tf2_buffer_.lookupTransform(frame, map_frame_, tf2::TimePointZero);
tf2::doTransform(point, point, stamped);
} catch (tf2::TransformException & exception) {
RCLCPP_WARN_STREAM(logger, "failed to lookup transform: " << exception.what());

Check warning on line 262 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L259-L262

Added lines #L259 - L262 were not covered by tests
return std::nullopt;
}

// fit height on map_frame_
point.z = get_ground_height(point);

Check warning on line 267 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L267

Added line #L267 was not covered by tests

// transform map_frame_ to frame
try {
const auto stamped = tf2_buffer_.lookupTransform(map_frame_, frame, tf2::TimePointZero);
tf2::Transform transform{tf2::Quaternion{}, tf2::Vector3{}};
tf2::fromMsg(stamped.transform, transform);
point = transform * point;
point.setZ(get_ground_height(point));
point = transform.inverse() * point;
tf2::doTransform(point, point, stamped);

Check warning on line 272 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L272

Added line #L272 was not covered by tests
} catch (tf2::TransformException & exception) {
RCLCPP_WARN_STREAM(logger, "failed to lookup transform: " << exception.what());
return std::nullopt;
}

RCLCPP_DEBUG(logger, "modified point: %.3f %.3f %.3f", point.getX(), point.getY(), point.getZ());
RCLCPP_DEBUG(logger, "modified point: %.3f %.3f %.3f", point.x, point.y, point.z);

Check warning on line 278 in map/map_height_fitter/src/map_height_fitter.cpp

View check run for this annotation

Codecov / codecov/patch

map/map_height_fitter/src/map_height_fitter.cpp#L278

Added line #L278 was not covered by tests

Point result;
result.x = point.getX();
result.y = point.getY();
result.z = point.getZ();
return result;
return point;
}

MapHeightFitter::MapHeightFitter(rclcpp::Node * node)
Expand Down
Loading
Loading