Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
cone_evaluator_test.cpp
Go to the documentation of this file.
1#include <gtest/gtest.h>
2
4#include <memory>
5#include <sensor_msgs/msg/point_cloud2.hpp>
7#include <utils/cluster.hpp>
10
13 params.small_cone_width = 0.25;
14 params.large_cone_width = 0.35;
15 params.small_cone_height = 0.35;
16 params.large_cone_height = 0.45;
17 params.n_out_points_ratio = 0.2;
18 params.max_distance_from_ground_min = 0.10;
19 params.max_distance_from_ground_max = 0.20;
20 params.n_points_intial_max = 20;
21 params.n_points_intial_min = 5;
24 return params;
25}
26
30TEST(ConeEvaluatorTest, CloseToGroundTrue) {
31 auto params = std::make_shared<EvaluatorParameters>(make_default_evaluator_params());
33 GroundGrid ground_grid(10.0, 1.0, 1.0, 0.0, 0.0, 360.0);
34
35 std::vector<std::array<float, 5>> pts = {{1.0, 2.0, 0.0, 0.1, 0}};
36 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
37 std::vector<int> indices = {0};
38 Cluster cluster(input_cloud, indices);
39 ground_grid.set_ground_height(1.0, 2.0, 0.0f);
40
41 ASSERT_TRUE(evaluator.close_to_ground(cluster, ground_grid));
42}
43
47TEST(ConeEvaluatorTest, CloseToGroundFalse) {
48 auto params = std::make_shared<EvaluatorParameters>(make_default_evaluator_params());
50 GroundGrid ground_grid(10.0, 1.0, 1.0, 0.0, 0.0, 360.0);
51
52 std::vector<std::array<float, 5>> pts = {{1.0, 2.0, 1.0, 0.1, 0}};
53 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
54 std::vector<int> indices = {0};
55 Cluster cluster(input_cloud, indices);
56 ground_grid.set_ground_height(1.0, 2.0, 0.0f);
57
58 ASSERT_FALSE(evaluator.close_to_ground(cluster, ground_grid));
59}
60
64TEST(ConeEvaluatorTest, CylinderFitsConeTrue) {
65 auto params = std::make_shared<EvaluatorParameters>(make_default_evaluator_params());
67
68 std::vector<std::array<float, 5>> pts = {{0.10, 0.05, 0.0, 0.1, 0}, {0.15, 0.0, 0.2, 0.1, 0}};
69 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
70 std::vector<int> indices = {0, 1};
71 Cluster cluster(input_cloud, indices);
72 ASSERT_TRUE(evaluator.cylinder_fits_cone(cluster));
73}
74
78TEST(ConeEvaluatorTest, CylinderFitsConeFalse) {
79 auto params = std::make_shared<EvaluatorParameters>(make_default_evaluator_params());
81
82 std::vector<std::array<float, 5>> pts = {{0.0, 0.0, 0.0, 0.1, 0}, {1.0, 0.0, 2.0, 0.1, 0}};
83 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
84 std::vector<int> indices = {0, 1};
85 Cluster cluster(input_cloud, indices);
86 ASSERT_FALSE(evaluator.cylinder_fits_cone(cluster));
87}
88
92TEST(ConeEvaluatorTest, NPointsValidTrue) {
93 auto params = std::make_shared<EvaluatorParameters>(make_default_evaluator_params());
95
96 std::vector<std::array<float, 5>> pts = {{0.0, 0.0, 0.0, 0.1, 0}, {0.1, 0.0, 0.0, 0.1, 0},
97 {0.2, 0.0, 0.0, 0.1, 0}, {0.3, 0.0, 0.0, 0.1, 0},
98 {0.4, 0.0, 0.0, 0.1, 0}, {0.5, 0.0, 0.0, 0.1, 0}};
99 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
100 std::vector<int> indices = {0, 1, 2, 3, 4, 5};
101 Cluster cluster(input_cloud, indices);
102 ASSERT_TRUE(evaluator.npoints_valid(cluster));
103}
104
108TEST(ConeEvaluatorTest, NPointsValidFalse) {
109 auto params = std::make_shared<EvaluatorParameters>(make_default_evaluator_params());
110 ConeEvaluator evaluator(params);
111
112 std::vector<std::array<float, 5>> pts = {{0.0, 0.0, 0.0, 0.1, 0}, {0.1, 0.0, 0.0, 0.1, 0}};
113 auto input_cloud = test_utils::make_lidar_pointcloud2(pts);
114 std::vector<int> indices = {0, 1};
115 Cluster cluster(input_cloud, indices);
116 ASSERT_FALSE(evaluator.npoints_valid(cluster));
117}
Represents a cluster of 3D points using PCL (Point Cloud Library).
Definition cluster.hpp:14
class that evaluates the cluster as a cone or not
Class to represent a ground height grid for ground proximity checks.
void set_ground_height(const float x, const float y, const float height)
Set the ground height at a specific (x, y) location.
TEST(ConeEvaluatorTest, CloseToGroundTrue)
Should return true when cluster is close to ground.
EvaluatorParameters make_default_evaluator_params()
sensor_msgs::msg::PointCloud2::SharedPtr make_lidar_pointcloud2(const std::vector< std::array< float, 5 > > &pts)
Structure to hold parameters for evaluating clusters as cones.