Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
himmelsbach_test.cpp
Go to the documentation of this file.
2
3#include <gtest/gtest.h>
4
5#include <memory>
8
9class HimmelsbachTest : public ::testing::Test {
10protected:
11 void SetUp() override {
12 // Points: x, y, z, intensity, ring
13 ground_pts = {{1.0, 0.0, -1.0, 0.5, 39}, {2.0, 0.0, -1.2, 0.5, 38}, {3.0, 0.0, -1.1, 0.5, 37}};
14 non_ground_pts = {{1.0, 0.0, 1.0, 0.5, 39}, {2.0, 0.0, 1.2, 0.5, 38}, {3.0, 0.0, 1.1, 0.5, 37}};
15 mixed_pts = {{1.0, 0.0, -1.0, 0.5, 39},
16 {2.0, 0.0, 1.2, 0.5, 38},
17 {3.0, 0.0, -1.1, 0.5, 37},
18 {4.0, 0.0, 1.3, 0.5, 37}};
19 empty_pts = {};
20
21 grid_angle = 0.1;
22 max_slope = 0.3;
23 initial_alpha = 0.2;
25 start_augmentation = 10.0;
26
29 trim_params.fov = 180.0;
37 trim_params.max_range = 100.0;
38 ground_grid = std::make_unique<GroundGrid>(30.0, 0.1, 0.5, 10.0, 0.1, 3.14);
39 algo = std::make_unique<Himmelsbach>(grid_angle, max_slope, initial_alpha, alpha_augmentation_m,
41 }
42
43 std::vector<std::array<float, 5>> ground_pts;
44 std::vector<std::array<float, 5>> non_ground_pts;
45 std::vector<std::array<float, 5>> mixed_pts;
46 std::vector<std::array<float, 5>> empty_pts;
49 std::unique_ptr<GroundGrid> ground_grid;
50 std::unique_ptr<Himmelsbach> algo;
51};
52
56TEST_F(HimmelsbachTest, EmptyCloudReturnsEmpty) {
57 auto cloud_ptr = test_utils::make_lidar_pointcloud2(empty_pts);
58 auto ground_removed_cloud_ptr = test_utils::make_lidar_pointcloud2({});
59 algo->ground_removal(cloud_ptr, ground_removed_cloud_ptr, *ground_grid);
60 ASSERT_EQ(ground_removed_cloud_ptr->width, 0);
61}
62
66TEST_F(HimmelsbachTest, AllGroundPointsRemoved) {
67 auto cloud_ptr = test_utils::make_lidar_pointcloud2(ground_pts);
68 auto ground_removed_cloud_ptr = test_utils::make_lidar_pointcloud2({});
69 algo->ground_removal(cloud_ptr, ground_removed_cloud_ptr, *ground_grid);
70 ASSERT_EQ(ground_removed_cloud_ptr->width, 0);
71}
72
76TEST_F(HimmelsbachTest, AllNonGroundPointsRetained) {
77 auto cloud_ptr = test_utils::make_lidar_pointcloud2(non_ground_pts);
78 auto ground_removed_cloud_ptr = test_utils::make_lidar_pointcloud2({});
79 algo->ground_removal(cloud_ptr, ground_removed_cloud_ptr, *ground_grid);
80 ASSERT_EQ(ground_removed_cloud_ptr->width, non_ground_pts.size());
81}
82
86TEST_F(HimmelsbachTest, MixedPointsOnlyNonGroundRetained) {
87 auto cloud_ptr = test_utils::make_lidar_pointcloud2(mixed_pts);
88 auto ground_removed_cloud_ptr = test_utils::make_lidar_pointcloud2({});
89 algo->ground_removal(cloud_ptr, ground_removed_cloud_ptr, *ground_grid);
90 ASSERT_EQ(ground_removed_cloud_ptr->width, 2);
91}
92
96TEST_F(HimmelsbachTest, GroundGridIsResetAndUpdated) {
97 auto cloud_ptr = test_utils::make_lidar_pointcloud2(ground_pts);
98 auto ground_removed_cloud_ptr = test_utils::make_lidar_pointcloud2({});
99 ground_grid->set_ground_height(1.0, 0.0, 99.0f);
100 algo->ground_removal(cloud_ptr, ground_removed_cloud_ptr, *ground_grid);
101
102 float h = ground_grid->get_ground_height(1.0f, 0.0f);
103 ASSERT_NE(h, 99.0f);
104}
void SetUp() override
std::vector< std::array< float, 5 > > mixed_pts
std::vector< std::array< float, 5 > > ground_pts
std::vector< std::array< float, 5 > > non_ground_pts
std::unique_ptr< GroundGrid > ground_grid
std::vector< std::array< float, 5 > > empty_pts
TrimmingParameters trim_params
std::unique_ptr< Himmelsbach > algo
TEST_F(HimmelsbachTest, EmptyCloudReturnsEmpty)
An empty input cloud should result in an empty output cloud.
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.
double lidar_horizontal_resolution
LIDAR horizontal resolution.
bool apply_fov_trimming
Whether to apply field of view trimming.
double max_range
Minimum point cloud distance after trimming.
double lidar_vertical_resolution
LIDAR vertical resolution.
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.