Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
acceleration_trimming.cpp
Go to the documentation of this file.
2
4
6 const sensor_msgs::msg::PointCloud2::SharedPtr& cloud,
7 sensor_msgs::msg::PointCloud2::SharedPtr& trimmed_cloud) const {
8 // Copy metadata
9 trimmed_cloud->header = cloud->header;
10 trimmed_cloud->height = 1;
11 trimmed_cloud->is_dense = false;
12 trimmed_cloud->fields = cloud->fields;
13 trimmed_cloud->point_step = cloud->point_step;
14 trimmed_cloud->width = 0;
15 trimmed_cloud->row_step = 0;
16 trimmed_cloud->data.resize(cloud->data.size());
17
18 const auto& data = cloud->data;
19 const size_t n = cloud->width * cloud->height;
20
21 const bool rotate = params_.apply_rotation;
22
23 double cos_t = 1.0;
24 double sin_t = 0.0;
25 if (rotate) {
26 const double theta = params_.rotation * M_PI / 180.0;
27 cos_t = std::cos(theta);
28 sin_t = std::sin(theta);
29 }
30
31 // Rotation may not look optimal, but it garants fastest approach when no rotation is applied, and
32 // that is the real-case scenario. The rotation is only used for testing purposes with older
33 // datasets.
34 for (size_t i = 0; i < n; ++i) {
35 const float x = *reinterpret_cast<const float*>(&data[LidarPoint::PointX(i)]);
36 const float y = *reinterpret_cast<const float*>(&data[LidarPoint::PointY(i)]);
37 const float z = *reinterpret_cast<const float*>(&data[LidarPoint::PointZ(i)]);
38 const float intensity = *reinterpret_cast<const float*>(&data[LidarPoint::PointIntensity(i)]);
39
40 if (x == 0.0f && y == 0.0f && z == 0.0f) {
41 continue;
42 }
43
44 float rx = x;
45 float ry = y;
46
47 if (rotate) {
48 rx = static_cast<float>(x * cos_t - y * sin_t);
49 ry = static_cast<float>(x * sin_t + y * cos_t);
50 }
51
52 if (ry < params_.acc_max_y && ry > -params_.acc_max_y &&
53 within_limits(rx, ry, z, intensity, params_, params_.acc_max_range)) {
54 uint8_t* out = &trimmed_cloud->data[trimmed_cloud->width * LidarPoint::POINT_STEP];
55
56 static_cast<void>(std::memcpy(out, &data[LidarPoint::PointX(i)], LidarPoint::POINT_STEP));
57
58 // Write rotated coords if rotation applies
59 if (rotate) {
60 *reinterpret_cast<float*>(out + LidarPoint::PointX(0)) = rx;
61 *reinterpret_cast<float*>(out + LidarPoint::PointY(0)) = ry;
62 }
63
64 trimmed_cloud->width++;
65 }
66 }
67
68 trimmed_cloud->data.resize(trimmed_cloud->width * LidarPoint::POINT_STEP);
69 trimmed_cloud->row_step = trimmed_cloud->width * LidarPoint::POINT_STEP;
70}
AccelerationTrimming()=default
Default constructor.
void fov_trimming(const sensor_msgs::msg::PointCloud2::SharedPtr &point_cloud, sensor_msgs::msg::PointCloud2::SharedPtr &trimmed_cloud) const override
Perform ground removal on the input point cloud.
bool within_limits(float x, float y, float z, float intensity, const TrimmingParameters &params, const double max_range) const
TrimmingParameters params_
constexpr size_t PointZ(size_t idx)
constexpr size_t POINT_STEP
constexpr size_t PointX(size_t idx)
constexpr size_t PointIntensity(size_t idx)
constexpr size_t PointY(size_t idx)
Structure to hold parameters for trimming point cloud data.
double acc_max_range
(Acceleration Only) Maximum distance after trimming.
double acc_max_y
(Acceleration Only) Maximum lateral distance after trimming.
double rotation
Rotation angle to be applied to the point cloud.
bool apply_rotation
Whether to apply rotation to the point cloud.