Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
least_squares_differentiation.cpp
Go to the documentation of this file.
1#include <Eigen/Dense>
3
5 int n = cone_point_cloud->get_point_indices().size();
6
7 // It is impractical to compute a parabola using fewer than three points
8 if (n < 3) {
9 cone_point_cloud->set_color("undefined");
10 return;
11 }
12
13 // Solve x for: Ax = b
14 Eigen::MatrixXd A(n, 3);
15 Eigen::VectorXd B(n);
16
17 // Creation of matrix A and vector b
18 for (int i = 0; i < n; ++i) {
19 float z = *reinterpret_cast<const float*>(
20 &cone_point_cloud->get_point_cloud()
21 ->data[LidarPoint::PointZ(cone_point_cloud->get_point_indices()[i])]);
22 float intensity = *reinterpret_cast<const float*>(
23 &cone_point_cloud->get_point_cloud()
24 ->data[LidarPoint::PointIntensity(cone_point_cloud->get_point_indices()[i])]);
25 A(i, 0) = z * z;
26 A(i, 1) = z;
27 A(i, 2) = 1.0;
28 B(i) = intensity;
29 }
30
31 // Solve the linear system
32 Eigen::Vector3d coefficients = A.colPivHouseholderQr().solve(B);
33
34 if (coefficients[0] > 0) {
35 cone_point_cloud->set_color("yellow");
36 } else {
37 cone_point_cloud->set_color("blue");
38 }
39}
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
void set_color(const std::string &new_color)
Set the color for the cluster.
Definition cluster.cpp:32
void coneDifferentiation(Cluster *cone_point_cloud) const override
Perform cone differentiation on a cone's point cloud using the Least Squares Method.
constexpr size_t PointZ(size_t idx)
constexpr size_t PointIntensity(size_t idx)