Skip to content

Commit 6351aeb

Browse files
committed
fix: remove node_->get_clock() and use self-defined timestamp
Signed-off-by: vividf <yihsiang.fang@tier4.jp>
1 parent 13ad6e5 commit 6351aeb

File tree

1 file changed

+47
-51
lines changed

1 file changed

+47
-51
lines changed

sensing/pointcloud_preprocessor/test/test_distortion_corrector_node.cpp

+47-51
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ class DistortionCorrectorTest : public ::testing::Test
203203
pointcloud_msg.width = 0;
204204
pointcloud_msg.row_step = 0;
205205
}
206-
207206
return pointcloud_msg;
208207
}
209208

@@ -216,10 +215,7 @@ class DistortionCorrectorTest : public ::testing::Test
216215
for (size_t i = 0; i < number_of_points; ++i) {
217216
double timestamp = point_stamp.seconds();
218217
timestamps.push_back(timestamp);
219-
if (i > 0) {
220-
point_stamp = point_stamp + rclcpp::Duration::from_seconds(
221-
0.001); // Assuming 1ms offset for demonstration
222-
}
218+
point_stamp = addMilliseconds(point_stamp, 10);
223219
}
224220
}
225221
return timestamps;
@@ -231,7 +227,7 @@ class DistortionCorrectorTest : public ::testing::Test
231227
std::shared_ptr<tf2_ros::StaticTransformBroadcaster> tf_broadcaster_;
232228

233229
static constexpr double standard_tolerance = 1e-4;
234-
static constexpr double coarse_tolerance = 1e-3;
230+
static constexpr double coarse_tolerance = 5e-3;
235231

236232
// for debugging or regenerating the ground truth point cloud
237233
bool debug = false;
@@ -303,7 +299,7 @@ TEST_F(DistortionCorrectorTest, TestSetPointCloudTransformWithMissingFrame)
303299

304300
TEST_F(DistortionCorrectorTest, TestUndistortPointCloudWithEmptyTwist)
305301
{
306-
rclcpp::Time timestamp = node_->get_clock()->now();
302+
rclcpp::Time timestamp(10, 100000000, RCL_ROS_TIME);
307303
// Generate the point cloud message
308304
sensor_msgs::msg::PointCloud2 pointcloud = generatePointCloudMsg(true, false, timestamp);
309305

@@ -340,7 +336,7 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloudWithEmptyTwist)
340336

341337
TEST_F(DistortionCorrectorTest, TestUndistortPointCloudWithEmptyPointCloud)
342338
{
343-
rclcpp::Time timestamp = node_->get_clock()->now();
339+
rclcpp::Time timestamp(10, 100000000, RCL_ROS_TIME);
344340
// Generate and process multiple twist messages
345341
auto twist_msgs = generateTwistMsgs(timestamp);
346342
for (const auto & twist_msg : twist_msgs) {
@@ -361,7 +357,7 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloudWithEmptyPointCloud)
361357
TEST_F(DistortionCorrectorTest, TestUndistortPointCloud2dWithoutImuInBaseLink)
362358
{
363359
// Generate the point cloud message
364-
rclcpp::Time timestamp = node_->get_clock()->now();
360+
rclcpp::Time timestamp(10, 100000000, RCL_ROS_TIME);
365361
sensor_msgs::msg::PointCloud2 pointcloud = generatePointCloudMsg(true, false, timestamp);
366362

367363
// Generate and process multiple twist messages
@@ -381,10 +377,10 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloud2dWithoutImuInBaseLink)
381377

382378
// Expected undistorted point cloud values
383379
std::vector<std::array<float, 3>> expected_pointcloud = {
384-
{10.0f, 0.0f, 0.0f}, {0.0f, 10.0f, 0.0f}, {0.012002f, 5.75338e-07f, 10.0f},
385-
{20.024f, 0.00191863f, 0.0f}, {0.0340828f, 20.0f, 0.0f}, {0.0479994f, 4.02654e-06f, 20.0f},
386-
{30.06f, 0.00575818f, 0.0f}, {0.0662481f, 30.0f, 0.0f}, {0.0839996f, 1.03542e-05f, 30.0f},
387-
{10.0931f, 10.0029f, 10.0f},
380+
{10.0f, 0.0f, 0.0f}, {0.117124f, 10.0f, 0.0f}, {0.26f, 0.000135182f, 10.0f},
381+
{20.4f, 0.0213818f, 0.0f}, {0.50932f, 20.0005f, 0.0f}, {0.699999f, 0.000819721f, 20.0f},
382+
{30.8599f, 0.076f, 0.0f}, {0.947959f, 30.0016f, 0.0f}, {1.22f, 0.00244382f, 30.0f},
383+
{11.3568f, 10.0463f, 10.0f},
388384
};
389385

390386
// Verify each point in the undistorted point cloud
@@ -407,7 +403,7 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloud2dWithoutImuInBaseLink)
407403
TEST_F(DistortionCorrectorTest, TestUndistortPointCloud2dWithImuInBaseLink)
408404
{
409405
// Generate the point cloud message
410-
rclcpp::Time timestamp = node_->get_clock()->now();
406+
rclcpp::Time timestamp(10, 100000000, RCL_ROS_TIME);
411407
sensor_msgs::msg::PointCloud2 pointcloud = generatePointCloudMsg(true, false, timestamp);
412408

413409
// Generate and process multiple twist messages
@@ -432,10 +428,10 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloud2dWithImuInBaseLink)
432428

433429
// Expected undistorted point cloud values
434430
std::vector<std::array<float, 3>> expected_pointcloud = {
435-
{10.0f, 0.0f, 0.0f}, {0.0f, 10.0f, 0.0f}, {0.0119991f, 5.75201e-07f, 10.0f},
436-
{20.024f, 0.0019192f, 0.0f}, {0.0321653f, 20.0f, 0.0f}, {0.0479994f, 6.32762e-06f, 20.0f},
437-
{30.06f, 0.00863842f, 0.0f}, {0.063369f, 30.0f, 0.0f}, {0.0839996f, 1.84079e-05f, 30.0f},
438-
{10.0912f, 10.0048f, 10.0f},
431+
{10.0f, 0.0f, 0.0f}, {0.122876f, 9.99996f, 0.0f}, {0.26f, -0.000115049f, 10.0f},
432+
{20.4f, -0.0174931f, 0.0f}, {0.56301f, 19.9996f, 0.0f}, {0.7f, -0.000627014f, 20.0f},
433+
{30.86f, -0.052675f, 0.0f}, {1.1004f, 29.9987f, 0.0f}, {1.22f, -0.00166245f, 30.0f},
434+
{11.4249f, 9.97293f, 10.0f},
439435
};
440436

441437
// Verify each point in the undistorted point cloud
@@ -458,7 +454,7 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloud2dWithImuInBaseLink)
458454
TEST_F(DistortionCorrectorTest, TestUndistortPointCloud2dWithImuInLidarFrame)
459455
{
460456
// Generate the point cloud message
461-
rclcpp::Time timestamp = node_->get_clock()->now();
457+
rclcpp::Time timestamp(10, 100000000, RCL_ROS_TIME);
462458
sensor_msgs::msg::PointCloud2 pointcloud = generatePointCloudMsg(true, true, timestamp);
463459

464460
// Generate and process multiple twist messages
@@ -483,11 +479,11 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloud2dWithImuInLidarFrame)
483479

484480
// Expected undistorted point cloud values
485481
std::vector<std::array<float, 3>> expected_pointcloud = {
486-
{10.0f, -1.77636e-15f, -4.44089e-16f}, {-2.66454e-15f, 10.0f, -8.88178e-16f},
487-
{0.00622853f, 0.00600991f, 10.0084f}, {20.0106f, 0.010948f, 0.0157355f},
488-
{0.0176543f, 20.0176f, 0.0248379f}, {0.024499f, 0.0245179f, 20.0348f},
489-
{30.0266f, 0.0255826f, 0.0357166f}, {0.0355204f, 30.0353f, 0.0500275f},
490-
{0.047132f, 0.0439795f, 30.0606f}, {10.0488f, 10.046f, 10.0636f},
482+
{10.0f, -1.77636e-15f, -4.44089e-16f}, {0.049989f, 10.0608f, 0.0924992f},
483+
{0.106107f, 0.130237f, 10.1986f}, {20.1709f, 0.210011f, 0.32034f},
484+
{0.220674f, 20.2734f, 0.417974f}, {0.274146f, 0.347043f, 20.5341f},
485+
{30.3673f, 0.457564f, 0.700818f}, {0.418014f, 30.5259f, 0.807963f},
486+
{0.464088f, 0.600081f, 30.9292f}, {10.5657f, 10.7121f, 11.094f},
491487
};
492488

493489
// Verify each point in the undistorted point cloud
@@ -510,7 +506,7 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloud2dWithImuInLidarFrame)
510506
TEST_F(DistortionCorrectorTest, TestUndistortPointCloud3dWithoutImuInBaseLink)
511507
{
512508
// Generate the point cloud message
513-
rclcpp::Time timestamp = node_->get_clock()->now();
509+
rclcpp::Time timestamp(10, 100000000, RCL_ROS_TIME);
514510
sensor_msgs::msg::PointCloud2 pointcloud = generatePointCloudMsg(true, false, timestamp);
515511

516512
// Generate and process multiple twist messages
@@ -530,10 +526,10 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloud3dWithoutImuInBaseLink)
530526

531527
// Expected undistorted point cloud values
532528
std::vector<std::array<float, 3>> expected_pointcloud = {
533-
{10.0f, 0.0f, 0.0f}, {0.0f, 10.0f, 0.0f}, {0.0119991f, 0.0f, 10.0f},
534-
{20.024f, 0.00120042f, 0.0f}, {0.0342002f, 20.0f, 0.0f}, {0.0479994f, 2.15994e-06f, 20.0f},
535-
{30.06f, 0.00450349f, 0.0f}, {0.0666005f, 30.0f, 0.0f}, {0.0839996f, 7.55993e-06f, 30.0f},
536-
{10.0936f, 10.0024f, 10.0f},
529+
{10.0f, 0.0f, 0.0f}, {0.117f, 10.0f, 0.0f}, {0.26f, 9.27035e-05f, 10.0f},
530+
{20.4f, 0.0222176f, 0.0f}, {0.51f, 20.0004f, 0.0f}, {0.7f, 0.000706573f, 20.0f},
531+
{30.8599f, 0.0760946f, 0.0f}, {0.946998f, 30.0015f, 0.0f}, {1.22f, 0.00234201f, 30.0f},
532+
{11.3569f, 10.046f, 10.0f},
537533
};
538534

539535
// Verify each point in the undistorted point cloud
@@ -556,7 +552,7 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloud3dWithoutImuInBaseLink)
556552
TEST_F(DistortionCorrectorTest, TestUndistortPointCloud3dWithImuInBaseLink)
557553
{
558554
// Generate the point cloud message
559-
rclcpp::Time timestamp = node_->get_clock()->now();
555+
rclcpp::Time timestamp(10, 100000000, RCL_ROS_TIME);
560556
sensor_msgs::msg::PointCloud2 pointcloud = generatePointCloudMsg(true, false, timestamp);
561557

562558
// Generate and process multiple twist messages
@@ -582,15 +578,15 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloud3dWithImuInBaseLink)
582578
// Expected undistorted point cloud values
583579
std::vector<std::array<float, 3>> expected_pointcloud = {
584580
{10.0f, 0.0f, 0.0f},
585-
{0.0f, 10.0f, 0.0f},
586-
{0.0118491f, -0.000149993f, 10.0f},
587-
{20.024f, 0.00220075f, 0.000600241f},
588-
{0.0327002f, 20.0f, 0.000900472f},
589-
{0.0468023f, -0.00119623f, 20.0f},
590-
{30.06f, 0.0082567f, 0.00225216f},
591-
{0.0621003f, 30.0f, 0.00270227f},
592-
{0.0808503f, -0.00313673f, 30.0f},
593-
{10.0904f, 10.0032f, 10.0024f},
581+
{0.123015f, 9.99998f, 0.00430552f},
582+
{0.266103f, -0.00895269f, 9.99992f},
583+
{20.4f, -0.0176539f, -0.0193392f},
584+
{0.563265f, 19.9997f, 0.035628f},
585+
{0.734597f, -0.046068f, 19.9993f},
586+
{30.8599f, -0.0517931f, -0.0658165f},
587+
{1.0995f, 29.9989f, 0.0956997f},
588+
{1.31283f, -0.113544f, 29.9977f},
589+
{11.461f, 9.93096f, 10.0035f},
594590
};
595591

596592
// Verify each point in the undistorted point cloud
@@ -613,7 +609,7 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloud3dWithImuInBaseLink)
613609
TEST_F(DistortionCorrectorTest, TestUndistortPointCloud3dWithImuInLidarFrame)
614610
{
615611
// Generate the point cloud message
616-
rclcpp::Time timestamp = node_->get_clock()->now();
612+
rclcpp::Time timestamp(10, 100000000, RCL_ROS_TIME);
617613
sensor_msgs::msg::PointCloud2 pointcloud = generatePointCloudMsg(true, true, timestamp);
618614

619615
// Generate and process multiple twist messages
@@ -639,15 +635,15 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloud3dWithImuInLidarFrame)
639635
// Expected undistorted point cloud values
640636
std::vector<std::array<float, 3>> expected_pointcloud = {
641637
{10.0f, 0.0f, 0.0f},
642-
{-4.76837e-07f, 10.0f, 4.76837e-07f},
643-
{0.00572586f, 0.00616837f, 10.0086f},
644-
{20.0103f, 0.0117249f, 0.0149349f},
645-
{0.0158343f, 20.0179f, 0.024497f},
646-
{0.0251098f, 0.0254798f, 20.0343f},
647-
{30.0259f, 0.0290527f, 0.034577f},
648-
{0.0319824f, 30.0358f, 0.0477753f},
649-
{0.0478067f, 0.0460052f, 30.06f},
650-
{10.0462f, 10.0489f, 10.0625f},
638+
{0.046484f, 10.0622f, 0.098484f},
639+
{0.107595f, 0.123767f, 10.2026f},
640+
{20.1667f, 0.22465f, 0.313351f},
641+
{0.201149f, 20.2784f, 0.464665f},
642+
{0.290531f, 0.303489f, 20.5452f},
643+
{30.3598f, 0.494116f, 0.672914f},
644+
{0.375848f, 30.5336f, 0.933633f},
645+
{0.510001f, 0.479651f, 30.9493f},
646+
{10.5629f, 10.6855f, 11.1461f},
651647
};
652648

653649
// Verify each point in the undistorted point cloud
@@ -669,7 +665,7 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloud3dWithImuInLidarFrame)
669665

670666
TEST_F(DistortionCorrectorTest, TestUndistortPointCloudWithPureLinearMotion)
671667
{
672-
rclcpp::Time timestamp = node_->get_clock()->now();
668+
rclcpp::Time timestamp(10, 100000000, RCL_ROS_TIME);
673669
sensor_msgs::msg::PointCloud2 test2d_pointcloud = generatePointCloudMsg(true, false, timestamp);
674670
sensor_msgs::msg::PointCloud2 test3d_pointcloud = generatePointCloudMsg(true, false, timestamp);
675671

@@ -755,7 +751,7 @@ TEST_F(DistortionCorrectorTest, TestUndistortPointCloudWithPureLinearMotion)
755751

756752
TEST_F(DistortionCorrectorTest, TestUndistortPointCloudWithPureRotationalMotion)
757753
{
758-
rclcpp::Time timestamp = node_->get_clock()->now();
754+
rclcpp::Time timestamp(10, 100000000, RCL_ROS_TIME);
759755
sensor_msgs::msg::PointCloud2 test2d_pointcloud = generatePointCloudMsg(true, false, timestamp);
760756
sensor_msgs::msg::PointCloud2 test3d_pointcloud = generatePointCloudMsg(true, false, timestamp);
761757

0 commit comments

Comments
 (0)