Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
cone_evaluator.cpp
Go to the documentation of this file.
2
3ConeEvaluator::ConeEvaluator(std::shared_ptr<EvaluatorParameters> params) : params_(params) {}
4
5bool ConeEvaluator::close_to_ground(Cluster &cluster, const GroundGrid &ground_grid) const {
6 Eigen::Vector4f centroid = cluster.get_centroid();
7
8 auto &data = cluster.get_point_cloud()->data;
9 auto &indices = cluster.get_point_indices();
10 float min_z = std::numeric_limits<float>::max();
11 float max_z = std::numeric_limits<float>::lowest();
12
13 for (const auto &idx : indices) {
14 float z = *reinterpret_cast<const float *>(&data[LidarPoint::PointZ(idx)]);
15 min_z = std::min(z, min_z);
16 max_z = std::max(z, max_z);
17 }
18
19 double ground_height = ground_grid.get_ground_height(centroid.x(), centroid.y());
20
21 if (std::isnan(ground_height)) {
22 return false;
23 }
24
25 double max_distance_above = max_z - ground_height;
26 double min_distance_above = min_z - ground_height;
27
28 bool result = true;
29
30 result &= min_distance_above < params_->max_distance_from_ground_min;
31
32 result &= max_distance_above < params_->max_distance_from_ground_max;
33
34 return result;
35}
36
38 const auto &cloud_data = cluster.get_point_cloud()->data;
39 const auto &indices = cluster.get_point_indices();
40 const auto &centroid = cluster.get_centroid();
41
42 int n_out_points = 0;
43
44 // Loop over points in the cluster
45 for (size_t idx : indices) {
46 float x = *reinterpret_cast<const float *>(&cloud_data[LidarPoint::PointX(idx)]);
47 float y = *reinterpret_cast<const float *>(&cloud_data[LidarPoint::PointY(idx)]);
48 float z = *reinterpret_cast<const float *>(&cloud_data[LidarPoint::PointZ(idx)]);
49
50 double dx = x - centroid.x();
51 double dy = y - centroid.y();
52 double dz = std::abs(z - centroid.z());
53
54 double distanceXY = std::sqrt(dx * dx + dy * dy);
55
56 // Choose radius/height depending on cone size
57 double radius = 0;
58 double half_height = 0;
59 if (cluster.get_is_large()) {
60 radius = params_->large_cone_width / 2.0;
61 half_height = params_->large_cone_height / 2.0;
62 } else {
63 radius = params_->small_cone_width / 2.0;
64 half_height = params_->small_cone_height / 2.0;
65 }
66
67 if (distanceXY > radius || dz > half_height) {
68 n_out_points++;
69 }
70 }
71
72 // Compute ratio of points outside the expected cylinder
73 double out_ratio = static_cast<double>(n_out_points) / indices.size();
74
75 // Validation passes if most points are within expected cone shape
76 return out_ratio < params_->n_out_points_ratio;
77}
78
80 Eigen::Vector4f center = cluster.get_centroid();
81 double distance = std::sqrt(center.x() * center.x() + center.y() * center.y());
82 double n_points = static_cast<double>(cluster.get_point_indices().size());
83
84 // Max and min number of points based on distance
85 double max_points = std::max(
86 params_->n_points_intial_max - (distance * params_->n_points_max_distance_reduction), 4.0);
87 double min_points = std::max(
88 params_->n_points_intial_min - (distance * params_->n_points_min_distance_reduction), 1.0);
89
90 return n_points <= max_points && n_points >= min_points;
91}
92
93bool ConeEvaluator::evaluateCluster(Cluster &cluster, const GroundGrid &ground_grid) {
94 bool result = true;
95
96 result &= close_to_ground(cluster, ground_grid);
97
98 result &= cylinder_fits_cone(cluster);
99
100 result &= npoints_valid(cluster);
101
102 return result;
103}
Represents a cluster of 3D points using PCL (Point Cloud Library).
Definition cluster.hpp:14
const std::vector< int > & get_point_indices()
Get the Point Cloud data of the cluster.
Definition cluster.cpp:44
const sensor_msgs::msg::PointCloud2::SharedPtr & get_point_cloud()
Get the Point Cloud data of the cluster.
Definition cluster.cpp:46
Eigen::Vector4f get_centroid()
Get the centroid of the cluster.
Definition cluster.cpp:7
bool get_is_large()
Get cluster's corresponding cone size.
Definition cluster.cpp:101
ConeEvaluator(std::shared_ptr< EvaluatorParameters > params)
Constructs a new DeviationValidator object with specified intervals on the deviation.
bool evaluateCluster(Cluster &cluster, const GroundGrid &ground_grid)
Perform the cluster evaluation, guaranteeing they pass all validators.
std::shared_ptr< EvaluatorParameters > params_
bool npoints_valid(Cluster &cluster) const
Check if the number of points in the cluster is valid, according to the distance.
bool close_to_ground(Cluster &cluster, const GroundGrid &ground_grid) const
Check if the cluster is close to the ground.
bool cylinder_fits_cone(Cluster &cluster) const
Check if a cylinder fits the cone dimensions.
Class to represent a ground height grid for ground proximity checks.
float get_ground_height(const float x, const float y) const
Get the ground height at a specific (x, y) location.
constexpr size_t PointZ(size_t idx)
constexpr size_t PointX(size_t idx)
constexpr size_t PointY(size_t idx)