Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
height_validator.cpp
Go to the documentation of this file.
2
3HeightValidator::HeightValidator(double min_height, double large_max_height,
4 double small_max_height, double height_cap)
5 : _min_height_(min_height),
6 _large_max_height_(large_max_height),
7 _small_max_height_(small_max_height),
8 _height_cap_(height_cap) {}
9
10std::vector<double> HeightValidator::coneValidator(Cluster* cone_cluster, Plane& plane) const {
11 const auto& cloud_data = cone_cluster->get_point_cloud()->data;
12 const auto& indices = cone_cluster->get_point_indices();
13
14 // Initialize maxZ with the distance of the first point to the plane
15 float x0 = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointX(indices[0])]);
16 float y0 = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointY(indices[0])]);
17 float z0 = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointZ(indices[0])]);
18
19 double maxZ = plane.get_distance_to_point(x0, y0, z0);
20
21 // Track the point corresponding to maxZ (optional)
22 Eigen::Vector3f maxPoint(x0, y0, z0);
23
24 for (size_t i = 1; i < indices.size(); ++i) {
25 float x = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointX(indices[i])]);
26 float y = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointY(indices[i])]);
27 float z = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointZ(indices[i])]);
28
29 double distance = plane.get_distance_to_point(x, y, z);
30 if (distance > maxZ) {
31 maxZ = distance;
32 maxPoint = Eigen::Vector3f(x, y, z);
33 }
34 }
35
36 std::vector<double> res;
37 double r1 = 0, r2 = 0;
38 if (maxZ > _small_max_height_) {
39 cone_cluster->set_is_large();
40
41 if (_min_height_ > 0) {
42 r1 = std::min({_large_max_height_ / maxZ, maxZ / _min_height_, 1.0});
43 } else {
44 r1 = std::min({_large_max_height_ / maxZ, 1.0});
45 }
46
47 if (r1 == 1.0) {
48 r2 = maxZ / _large_max_height_;
49 } else {
50 r2 = 0.0;
51 }
52 res.push_back(r1);
53 res.push_back(r2);
54 } else {
55 if (_min_height_ > 0) {
56 r1 = std::min({_small_max_height_ / maxZ, maxZ / _min_height_, 1.0});
57 } else {
58 r1 = std::min({_small_max_height_ / maxZ, 1.0});
59 }
60
61 if (r1 == 1.0) {
62 r2 = maxZ / _small_max_height_;
63 } else {
64 r2 = 0.0;
65 }
66 res.push_back(r1);
67 res.push_back(r2);
68 }
69
70 if (res[0] < _height_cap_) {
71 res[0] = 0.0;
72 }
73
74 // index 0 = if not in height interval, ratio between the height of the cluster and the maximum or
75 // minimum height, whichever is closest to.
76 // index 1 = if in height interval, how close is it to the maximum height, else 0.
77 return res;
78}
Represents a cluster of 3D points using PCL (Point Cloud Library).
Definition cluster.hpp:14
void set_is_large()
Set cluster as a contender for a large cone.
Definition cluster.cpp:103
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
double _small_max_height_
Max Height treshhold for small cones *‍/.
HeightValidator(double min_height, double large_max_height, double small_max_height, double height_cap)
Constructs a new HeightValidator object with the specified height threshold.
double _height_cap_
Minimum ratio result needed for return values to not be 0. *‍/.
double _min_height_
Min Height threshold for cone validation *‍/.
std::vector< double > coneValidator(Cluster *cone_point_cloud, Plane &plane) const override
Validates a cone based on its height relative to a plane.
double _large_max_height_
Max Height threshold for large cones *‍/.
The Plane class represents a 3D plane defined by its equation ax + by + cz + d = 0.
Definition plane.hpp:12
double get_distance_to_point(float x, float y, float z) const
Calculates the distance from a point to the plane.
Definition plane.cpp:15
constexpr size_t PointZ(size_t idx)
constexpr size_t PointX(size_t idx)
constexpr size_t PointY(size_t idx)