Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
acceleration_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>
8
13class AccelerationTrimmingTest : public ::testing::Test {
14protected:
15 void SetUp() override {
16 params.acc_max_range = 20.25;
18 params.fov = 180.0;
19 params.min_range = 0.0;
20 params.max_height = 10.0;
22 params.acc_max_y = 10.0;
24 params.rotation = 90.0;
25 }
26
28};
29
35 std::vector<std::array<float, 5>> pts = {{1.1, -4.3, 0.5, 0.0, 39},
36 {1.6, -29.0, 0.5, 0.0, 39},
37 {1.0, -3.2, 3.0, 0.0, 39},
38 {0.1, -0.1, 0.5, 0.0, 39},
39 {-5.1, -5.0, 0.5, 0.0, 39}};
40 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
41 auto output_cloud = test_utils::make_lidar_pointcloud2({});
42 const AccelerationTrimming acc_trimming(params);
43 acc_trimming.fov_trimming(input_cloud, output_cloud);
44 ASSERT_EQ(output_cloud->width, 4);
45}
46
52 params.max_height = 2.0;
53 std::vector<std::array<float, 5>> pts = {{1.1, -4.3, 0.5, 0.0, 39},
54 {1.6, -29.0, 0.5, 0.0, 39},
55 {1.0, -3.2, 3.0, 0.0, 39},
56 {0.1, -0.1, 0.5, 0.0, 39},
57 {-5.1, -5.0, 0.5, 0.0, 39}};
58 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
59 auto output_cloud = test_utils::make_lidar_pointcloud2({});
60 const AccelerationTrimming acc_trimming(params);
61 acc_trimming.fov_trimming(input_cloud, output_cloud);
62 ASSERT_EQ(output_cloud->width, 3);
63}
64
70 params.min_range = 0.2;
71 std::vector<std::array<float, 5>> pts = {{1.1, -4.3, 0.5, 0.0, 39},
72 {1.6, -29.0, 0.5, 0.0, 39},
73 {1.0, -3.2, 3.0, 0.0, 39},
74 {0.1, -0.1, 0.5, 0.0, 39},
75 {-5.1, -5.0, 0.5, 0.0, 39}};
76 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
77 auto output_cloud = test_utils::make_lidar_pointcloud2({});
78 const AccelerationTrimming acc_trimming(params);
79 acc_trimming.fov_trimming(input_cloud, output_cloud);
80 ASSERT_EQ(output_cloud->width, 3);
81}
82
88 params.acc_max_y = 4.0;
89 std::vector<std::array<float, 5>> pts = {{1.1, -4.3, 0.5, 0.0, 39},
90 {1.6, -29.0, 0.5, 0.0, 39},
91 {1.0, -3.2, 3.0, 0.0, 39},
92 {0.1, -0.1, 0.5, 0.0, 39},
93 {-5.1, -5.0, 0.5, 0.0, 39}};
94 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
95 auto output_cloud = test_utils::make_lidar_pointcloud2({});
96 const AccelerationTrimming acc_trimming(params);
97 acc_trimming.fov_trimming(input_cloud, output_cloud);
98 ASSERT_EQ(output_cloud->width, 3);
99}
100
105TEST_F(AccelerationTrimmingTest, TestEmptyPointCloud) {
106 params.min_range = 0.2;
107 params.max_height = 2.0;
108 params.lidar_height = 0;
109 params.acc_max_y = 4.0;
110 auto input_cloud = test_utils::make_lidar_pointcloud2({});
111 auto output_cloud = test_utils::make_lidar_pointcloud2({});
112 const AccelerationTrimming acc_trimming(params);
113 acc_trimming.fov_trimming(input_cloud, output_cloud);
114 ASSERT_EQ(output_cloud->width, 0);
115}
116
121TEST_F(AccelerationTrimmingTest, TestGeneralResult) {
122 params.min_range = 0.2;
123 params.max_height = 2.0;
124 params.lidar_height = 0;
125 params.acc_max_y = 4.0;
126 std::vector<std::array<float, 5>> pts = {{1.1, -4.3, 0.5, 0.0, 39},
127 {1.6, -29.0, 0.5, 0.0, 39},
128 {1.0, -3.2, 3.0, 0.0, 39},
129 {0.1, -0.1, 0.5, 0.0, 39},
130 {-5.1, -5.0, 0.5, 0.0, 39}};
131 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
132 auto output_cloud = test_utils::make_lidar_pointcloud2({});
133 const AccelerationTrimming acc_trimming(params);
134 acc_trimming.fov_trimming(input_cloud, output_cloud);
135 ASSERT_EQ(output_cloud->width, 1);
136}
TEST_F(AccelerationTrimmingTest, TestMaxRange)
Test case where points outside max range should be removed.
Test class for setting up data and testing AccelerationTrimming algorithm.
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 acc_max_range
(Acceleration Only) Maximum distance after trimming.
double max_height
Maximum point cloud height after trimming.
double acc_max_y
(Acceleration Only) Maximum lateral distance 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.