Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
skidpad_trimming_test.cpp
Go to the documentation of this file.
2
3#include <gtest/gtest.h>
4
5#include <algorithm>
6#include <cmath>
7#include <sensor_msgs/msg/point_cloud2.hpp>
9
10class SkidpadTrimmingTest : public ::testing::Test {
11protected:
12 void SetUp() override {
13 params.skid_max_range = 20.25;
14 params.min_range = 0.0;
15 params.max_height = 1000.0;
16 params.lidar_height = 0.0;
18 params.fov = 180.0;
20 params.rotation = 90.0;
21 }
22
24};
25
31 std::vector<std::array<float, 5>> pts = {
32 {1.0, -4.0, 0.5, 0.0, 39}, // Inside
33 {1.0, -21.0, 0.5, 0.0, 39}, // Outside max range
34 {1.0, -3.5, 3.0, 0.0, 39}, // Above max height
35 {0.05, -0.05, 0.5, 0.0, 39}, // Below min range
36 {2.0, -0.2, 0.5, 0.0, 39} // Outside FOV trim angle
37 };
38 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
39 auto output_cloud = test_utils::make_lidar_pointcloud2({});
40 const SkidpadTrimming skidpad_trimming(params);
41 skidpad_trimming.fov_trimming(input_cloud, output_cloud);
42 ASSERT_EQ(output_cloud->width, 4);
43}
44
49TEST_F(SkidpadTrimmingTest, TestMaxHeight) {
50 params.max_height = 2.5;
51 std::vector<std::array<float, 5>> pts = {{1.0, -4.0, 0.5, 0.0, 39},
52 {1.0, -21.0, 0.5, 0.0, 39},
53 {1.0, -3.5, 3.0, 0.0, 39},
54 {0.05, -0.05, 0.5, 0.0, 39},
55 {2.0, -0.2, 0.5, 0.0, 39}};
56 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
57 auto output_cloud = test_utils::make_lidar_pointcloud2({});
58 const SkidpadTrimming skidpad_trimming(params);
59 skidpad_trimming.fov_trimming(input_cloud, output_cloud);
60 ASSERT_EQ(output_cloud->width, 3);
61}
62
68 params.min_range = 0.3;
69 std::vector<std::array<float, 5>> pts = {{1.0, -4.0, 0.5, 0.0, 39},
70 {1.0, -21.0, 0.5, 0.0, 39},
71 {1.0, -3.5, 3.0, 0.0, 39},
72 {0.05, -0.05, 0.5, 0.0, 39},
73 {2.0, -0.2, 0.5, 0.0, 39}};
74 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
75 auto output_cloud = test_utils::make_lidar_pointcloud2({});
76 const SkidpadTrimming skidpad_trimming(params);
77 skidpad_trimming.fov_trimming(input_cloud, output_cloud);
78 ASSERT_EQ(output_cloud->width, 3);
79}
80
86 params.apply_fov_trimming = true;
87 params.fov = 180.0;
88 params.max_range = 50.0;
89 std::vector<std::array<float, 5>> pts = {{1.0, -4.0, 0.5, 0.0, 39},
90 {1.0, -21.0, 0.5, 0.0, 39},
91 {1.0, -3.5, 3.0, 0.0, 39},
92 {0.05, -0.05, 0.5, 0.0, 39},
93 {2.0, -0.2, 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 SkidpadTrimming skidpad_trimming(params);
97 skidpad_trimming.fov_trimming(input_cloud, output_cloud);
98 ASSERT_EQ(output_cloud->width, 4);
99}
100
105TEST_F(SkidpadTrimmingTest, TestEmptyPointCloud) {
106 auto input_cloud = test_utils::make_lidar_pointcloud2({});
107 auto output_cloud = test_utils::make_lidar_pointcloud2({});
108 const SkidpadTrimming skidpad_trimming(params);
109 skidpad_trimming.fov_trimming(input_cloud, output_cloud);
110 ASSERT_EQ(output_cloud->width, 0);
111}
112
117TEST_F(SkidpadTrimmingTest, TestGeneralResult) {
118 params.min_range = 0.4;
119 params.max_height = 2.5;
120 params.apply_fov_trimming = true;
121 params.fov = 35.0;
122 std::vector<std::array<float, 5>> pts = {{1.0, -4.0, 0.5, 0.0, 39},
123 {1.0, -21.0, 0.5, 0.0, 39},
124 {1.0, -3.5, 3.0, 0.0, 39},
125 {0.05, -0.05, 0.5, 0.0, 39},
126 {2.0, -0.2, 0.5, 0.0, 39}};
127 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
128 auto output_cloud = test_utils::make_lidar_pointcloud2({});
129 const SkidpadTrimming skidpad_trimming(params);
130 skidpad_trimming.fov_trimming(input_cloud, output_cloud);
131 ASSERT_EQ(output_cloud->width, 1);
132}
sensor_msgs::msg::PointCloud2::SharedPtr make_lidar_pointcloud2(const std::vector< std::array< float, 5 > > &pts)
TEST_F(SkidpadTrimmingTest, TestMaxRange)
Test case where points outside max range should be removed.
Structure to hold parameters for trimming point cloud data.
bool apply_fov_trimming
Whether to apply field of view trimming.
double skid_max_range
(Skidpad Only) Maximum 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.