Skip to content

Commit 74249fa

Browse files
Fixed sample pcd
Signed-off-by: Shintaro Sakoda <shintaro.sakoda@tier4.jp>
1 parent 62fda75 commit 74249fa

File tree

3 files changed

+52
-24
lines changed

3 files changed

+52
-24
lines changed

localization/ndt_scan_matcher/test/stub_pcd_loader.hpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,25 @@ class StubPcdLoader : public rclcpp::Node
4646
{
4747
(void)req;
4848
autoware_map_msgs::msg::PointCloudMapCellWithID pcd_map_cell_with_id;
49-
constexpr float interval = 0.2f;
50-
pcd_map_cell_with_id.metadata.min_x = -10;
51-
pcd_map_cell_with_id.metadata.min_y = -10;
52-
pcd_map_cell_with_id.metadata.max_x = 30;
53-
pcd_map_cell_with_id.metadata.max_y = 30;
5449
pcd_map_cell_with_id.cell_id = "0";
55-
pcl::PointCloud<pcl::PointXYZ> cloud = make_sample_pcd(-10, 30, interval);
50+
pcl::PointCloud<pcl::PointXYZ> cloud = make_sample_half_cubic_pcd();
51+
const float offset_x = 100.0f;
52+
const float offset_y = 100.0f;
53+
for (auto & point : cloud.points) {
54+
point.x += offset_x;
55+
point.y += offset_y;
56+
}
57+
pcd_map_cell_with_id.metadata.min_x = std::numeric_limits<float>::max();
58+
pcd_map_cell_with_id.metadata.min_y = std::numeric_limits<float>::max();
59+
pcd_map_cell_with_id.metadata.max_x = std::numeric_limits<float>::lowest();
60+
pcd_map_cell_with_id.metadata.max_y = std::numeric_limits<float>::lowest();
61+
for (const auto & point : cloud.points) {
62+
pcd_map_cell_with_id.metadata.min_x = std::min(pcd_map_cell_with_id.metadata.min_x, point.x);
63+
pcd_map_cell_with_id.metadata.min_y = std::min(pcd_map_cell_with_id.metadata.min_y, point.y);
64+
pcd_map_cell_with_id.metadata.max_x = std::max(pcd_map_cell_with_id.metadata.max_x, point.x);
65+
pcd_map_cell_with_id.metadata.max_y = std::max(pcd_map_cell_with_id.metadata.max_y, point.y);
66+
}
67+
RCLCPP_INFO_STREAM(get_logger(), "cloud size: " << cloud.size());
5668
pcl::toROSMsg(cloud, pcd_map_cell_with_id.pointcloud);
5769
res->new_pointcloud_with_ids.push_back(pcd_map_cell_with_id);
5870
res->header.frame_id = "map";

localization/ndt_scan_matcher/test/test.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ TEST_F(TestNDTScanMatcher,
9191
//---------//
9292

9393
// prepare input source PointCloud
94-
pcl::PointCloud<pcl::PointXYZ> cloud = make_sample_pcd(-10.0, 10.0, 1.0);
94+
pcl::PointCloud<pcl::PointXYZ> cloud = make_sample_half_cubic_pcd();
95+
pcl::VoxelGrid<pcl::PointXYZ> vg;
96+
vg.setInputCloud(cloud.makeShared());
97+
vg.setLeafSize(0.5, 0.5, 0.5);
98+
vg.filter(cloud);
99+
RCLCPP_INFO_STREAM(node_->get_logger(), "sensor cloud size: " << cloud.size());
95100
sensor_msgs::msg::PointCloud2 input_cloud;
96101
pcl::toROSMsg(cloud, input_cloud);
97102
input_cloud.header.frame_id = "sensor_frame";
@@ -100,8 +105,8 @@ TEST_F(TestNDTScanMatcher,
100105

101106
// prepare input initial pose
102107
geometry_msgs::msg::PoseWithCovarianceStamped initial_pose_msg;
103-
initial_pose_msg.pose.pose.position.x = 10.0;
104-
initial_pose_msg.pose.pose.position.y = 10.0;
108+
initial_pose_msg.pose.pose.position.x = 100.0;
109+
initial_pose_msg.pose.pose.position.y = 100.0;
105110
initial_pose_msg.pose.pose.position.z = 0.0;
106111
initial_pose_msg.pose.pose.orientation.x = 0.0;
107112
initial_pose_msg.pose.pose.orientation.y = 0.0;
@@ -138,9 +143,9 @@ TEST_F(TestNDTScanMatcher,
138143
RCLCPP_INFO_STREAM(
139144
node_->get_logger(), std::fixed << "result_pose: " << result_pose.position.x << ", "
140145
<< result_pose.position.y << ", " << result_pose.position.z);
141-
EXPECT_NEAR(result_pose.position.x, 10.0, 3.0);
142-
EXPECT_NEAR(result_pose.position.y, 10.0, 3.0);
143-
EXPECT_NEAR(result_pose.position.z, 0.0, 3.0);
146+
EXPECT_NEAR(result_pose.position.x, 100.0, 1.0);
147+
EXPECT_NEAR(result_pose.position.y, 100.0, 1.0);
148+
EXPECT_NEAR(result_pose.position.z, 0.0, 1.0);
144149

145150
rclcpp::shutdown();
146151
t1.join();

localization/ndt_scan_matcher/test/test_util.hpp

+23-12
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,35 @@
1818
#include <pcl/point_cloud.h>
1919
#include <pcl/point_types.h>
2020

21-
inline pcl::PointCloud<pcl::PointXYZ> make_sample_pcd(
22-
const float min_xy, const float max_xy, const float interval)
21+
inline pcl::PointCloud<pcl::PointXYZ> make_sample_half_cubic_pcd()
2322
{
24-
const float range_width = max_xy - min_xy;
25-
const float center = (max_xy + min_xy) / 2.0f;
26-
const int num_points_per_line = static_cast<int>(range_width / interval) + 1;
23+
constexpr float length = 10;
24+
constexpr float interval = 0.1;
25+
constexpr int num_points_per_line = static_cast<int>(length / interval) + 1;
26+
constexpr int num_points_per_plane = num_points_per_line * num_points_per_line;
2727
pcl::PointCloud<pcl::PointXYZ> cloud;
28-
cloud.width = num_points_per_line * num_points_per_line;
28+
cloud.width = 3 * num_points_per_plane;
2929
cloud.height = 1;
3030
cloud.points.resize(cloud.width * cloud.height);
3131
for (int i = 0; i < num_points_per_line; ++i) {
3232
for (int j = 0; j < num_points_per_line; ++j) {
33-
const float x = min_xy + interval * static_cast<float>(j);
34-
const float y = min_xy + interval * static_cast<float>(i);
35-
const float z = std::hypot(x - center, y - center) / (range_width / 16);
36-
cloud.points[i * num_points_per_line + j].x = x; // NOLINT
37-
cloud.points[i * num_points_per_line + j].y = y; // NOLINT
38-
cloud.points[i * num_points_per_line + j].z = z; // NOLINT
33+
const float u = interval * static_cast<float>(j);
34+
const float v = interval * static_cast<float>(i);
35+
36+
// xy
37+
cloud.points[num_points_per_plane * 0 + i * num_points_per_line + j].x = u; // NOLINT
38+
cloud.points[num_points_per_plane * 0 + i * num_points_per_line + j].y = v; // NOLINT
39+
cloud.points[num_points_per_plane * 0 + i * num_points_per_line + j].z = 0; // NOLINT
40+
41+
// yz
42+
cloud.points[num_points_per_plane * 1 + i * num_points_per_line + j].x = 0; // NOLINT
43+
cloud.points[num_points_per_plane * 1 + i * num_points_per_line + j].y = u; // NOLINT
44+
cloud.points[num_points_per_plane * 1 + i * num_points_per_line + j].z = v; // NOLINT
45+
46+
// zx
47+
cloud.points[num_points_per_plane * 2 + i * num_points_per_line + j].x = u; // NOLINT
48+
cloud.points[num_points_per_plane * 2 + i * num_points_per_line + j].y = 0; // NOLINT
49+
cloud.points[num_points_per_plane * 2 + i * num_points_per_line + j].z = v; // NOLINT
3950
}
4051
}
4152
return cloud;

0 commit comments

Comments
 (0)