Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
cut_trimming_test.cpp
Go to the documentation of this file.
2
3#include <gtest/gtest.h>
4
5#include <sensor_msgs/msg/point_cloud2.hpp>
7
12class CutTrimmingTest : public ::testing::Test {
13protected:
14 void SetUp() override {
15 std::vector<std::array<float, 5>> pts = {
16 {1.1, -4.3, 0.5, 0.0, 39}, // Inside
17 {1.6, -29.0, 0.5, 0.0, 39}, // Outside max range
18 {1.0, -3.2, 3.0, 0.0, 39}, // Above max height
19 {0.1, -0.1, 0.5, 0.0, 39}, // Below min range
20 {-5.1, 2.0, 0.5, 0.0, 39} // Outside FOV trim angle
21 };
24
25 params.max_range = 1000.0;
26 params.min_range = 0.0;
27 params.max_height = 1000.0;
28 params.lidar_height = 0.0;
30 params.fov = 360.0;
32 params.rotation = 90.0;
33 }
34
35 sensor_msgs::msg::PointCloud2::SharedPtr cloud;
36 sensor_msgs::msg::PointCloud2::SharedPtr cloud_empty;
38};
39
44TEST_F(CutTrimmingTest, TestMaxRange) {
45 params.max_range = 15.0;
46 auto input_cloud = cloud;
47 auto output_cloud = test_utils::make_lidar_pointcloud2({});
48 const CutTrimming cut_trimming(params);
49 cut_trimming.fov_trimming(input_cloud, output_cloud);
50 ASSERT_EQ(output_cloud->width, 4);
51}
52
57TEST_F(CutTrimmingTest, TestMaxHeight) {
58 params.max_height = 2.0;
59 auto input_cloud = cloud;
60 auto output_cloud = test_utils::make_lidar_pointcloud2({});
61 const CutTrimming cut_trimming(params);
62 cut_trimming.fov_trimming(input_cloud, output_cloud);
63 ASSERT_EQ(output_cloud->width, 4);
64}
65
70TEST_F(CutTrimmingTest, TestMinRange) {
71 params.min_range = 0.5;
72 auto input_cloud = cloud;
73 auto output_cloud = test_utils::make_lidar_pointcloud2({});
74 const CutTrimming cut_trimming(params);
75 cut_trimming.fov_trimming(input_cloud, output_cloud);
76 ASSERT_EQ(output_cloud->width, 4);
77}
78
83TEST_F(CutTrimmingTest, TestFOVAngle) {
84 params.apply_fov_trimming = true;
85 params.fov = 180.0;
86 auto input_cloud = cloud;
87 auto output_cloud = test_utils::make_lidar_pointcloud2({});
88 const CutTrimming cut_trimming(params);
89 cut_trimming.fov_trimming(input_cloud, output_cloud);
90 ASSERT_EQ(output_cloud->width, 4);
91}
92
97TEST_F(CutTrimmingTest, TestEmptyPointCloud) {
98 auto input_cloud = cloud_empty;
99 auto output_cloud = test_utils::make_lidar_pointcloud2({});
100 const CutTrimming cut_trimming(params);
101 cut_trimming.fov_trimming(input_cloud, output_cloud);
102 ASSERT_EQ(output_cloud->width, 0);
103}
104
109TEST_F(CutTrimmingTest, TestGeneralResult) {
110 params.max_range = 10.0;
111 params.min_range = 0.2;
112 params.max_height = 2.5;
113 params.lidar_height = 0.0;
114 params.apply_fov_trimming = true;
115 params.fov = 45.0;
116 auto input_cloud = cloud;
117 auto output_cloud = test_utils::make_lidar_pointcloud2({});
118 const CutTrimming cut_trimming(params);
119 cut_trimming.fov_trimming(input_cloud, output_cloud);
120 ASSERT_EQ(output_cloud->width, 1);
121}
Test class for setting up data and testing CutTrimming algorithm.
void SetUp() override
TrimmingParameters params
sensor_msgs::msg::PointCloud2::SharedPtr cloud_empty
sensor_msgs::msg::PointCloud2::SharedPtr cloud
TEST_F(CutTrimmingTest, TestMaxRange)
Test case where points outside max range should be removed.
sensor_msgs::msg::PointCloud2::SharedPtr make_lidar_pointcloud2(const std::vector< std::array< float, 5 > > &pts)
Structure to hold parameters for trimming point cloud data.
bool apply_fov_trimming
Whether to apply field of view trimming.
double max_range
Minimum point cloud distance after trimming.
double max_height
Maximum point cloud height after trimming.
double rotation
Rotation angle to be applied to the point cloud.
double fov
Field of view.
double min_range
Maximum point cloud distance after trimming.
double lidar_height
LIDAR current height.
bool apply_rotation
Whether to apply rotation to the point cloud.