forked from autowarefoundation/autoware.universe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(autoware_ground_segmentation): scan ground filter refactoring (a…
…utowarefoundation#9061) * chore: Add comment classification logic for point cloud grid scan Signed-off-by: Taekjin LEE <[email protected]> * chore: renamed horizontal angle to azimuth angle Signed-off-by: Taekjin LEE <[email protected]> * chore: rename offset to data_index Signed-off-by: Taekjin LEE <[email protected]> * chore: rename ground_cluster to centroid_bin chore: Refactor recheckGroundCluster function in scan_ground_filter Signed-off-by: Taekjin LEE <[email protected]> * chore: rename too short variables Signed-off-by: Taekjin LEE <[email protected]> * refactor: set input to be const Signed-off-by: Taekjin LEE <[email protected]> * refactor: update functions to be const Signed-off-by: Taekjin LEE <[email protected]> * chore: reorder params Signed-off-by: Taekjin LEE <[email protected]> * refactor: Add ScanGroundGrid class for managing grid data Signed-off-by: Taekjin LEE <[email protected]> * refactor: Update grid parameters and calculations in ScanGroundGrid class Signed-off-by: Taekjin LEE <[email protected]> * refactor: remove unused methods Signed-off-by: Taekjin LEE <[email protected]> * refactor: classification description Signed-off-by: Taekjin LEE <[email protected]> * refactor: initialize members in ScanGroundGrid class Signed-off-by: Taekjin LEE <[email protected]> * refactor: remove unused value Signed-off-by: Taekjin LEE <[email protected]> * chore: reduce scope Signed-off-by: Taekjin LEE <[email protected]> * refactor: align structure between convertPointcloud and convertPointcloudGridScan Signed-off-by: Taekjin LEE <[email protected]> --------- Signed-off-by: Taekjin LEE <[email protected]>
- Loading branch information
1 parent
41e08dc
commit f49e7a6
Showing
4 changed files
with
432 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
perception/autoware_ground_segmentation/src/scan_ground_filter/grid.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright 2024 TIER IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef SCAN_GROUND_FILTER__GRID_HPP_ | ||
#define SCAN_GROUND_FILTER__GRID_HPP_ | ||
|
||
#include <autoware/universe_utils/geometry/geometry.hpp> | ||
#include <autoware/universe_utils/math/normalization.hpp> | ||
|
||
#include <cmath> | ||
|
||
namespace autoware::ground_segmentation | ||
{ | ||
|
||
class ScanGroundGrid | ||
{ | ||
public: | ||
ScanGroundGrid() = default; | ||
~ScanGroundGrid() = default; | ||
|
||
void initialize( | ||
const float grid_size_m, const float grid_mode_switch_radius, const float virtual_lidar_z) | ||
{ | ||
grid_size_m_ = grid_size_m; | ||
mode_switch_radius_ = grid_mode_switch_radius; | ||
virtual_lidar_z_ = virtual_lidar_z; | ||
|
||
// calculate parameters | ||
inv_grid_size_m_ = 1.0f / grid_size_m_; | ||
mode_switch_grid_id_ = mode_switch_radius_ * inv_grid_size_m_; | ||
mode_switch_angle_rad_ = std::atan2(mode_switch_radius_, virtual_lidar_z_); | ||
|
||
grid_size_rad_ = universe_utils::normalizeRadian( | ||
std::atan2(mode_switch_radius_ + grid_size_m_, virtual_lidar_z_)) - | ||
universe_utils::normalizeRadian(mode_switch_angle_rad_); | ||
inv_grid_size_rad_ = 1.0f / grid_size_rad_; | ||
tan_grid_size_rad_ = std::tan(grid_size_rad_); | ||
grid_id_offset_ = mode_switch_grid_id_ - mode_switch_angle_rad_ * inv_grid_size_rad_; | ||
|
||
is_initialized_ = true; | ||
} | ||
|
||
float getGridSize(const float radius, const size_t grid_id) const | ||
{ | ||
// check if initialized | ||
if (!is_initialized_) { | ||
throw std::runtime_error("ScanGroundGrid is not initialized."); | ||
} | ||
|
||
float grid_size = grid_size_m_; | ||
constexpr uint16_t back_steps_num = 1; | ||
|
||
if (radius > mode_switch_radius_ && grid_id > mode_switch_grid_id_ + back_steps_num) { | ||
// equivalent to grid_size = (std::tan(gamma) - std::tan(gamma - grid_size_rad_)) * | ||
// virtual_lidar_z_ | ||
// where gamma = normalizeRadian(std::atan2(radius, virtual_lidar_z_), 0.0f) | ||
grid_size = radius - (radius - tan_grid_size_rad_ * virtual_lidar_z_) / | ||
(1 + radius * tan_grid_size_rad_ / virtual_lidar_z_); | ||
} | ||
return grid_size; | ||
} | ||
|
||
uint16_t getGridId(const float radius) const | ||
{ | ||
// check if initialized | ||
if (!is_initialized_) { | ||
throw std::runtime_error("ScanGroundGrid is not initialized."); | ||
} | ||
|
||
uint16_t grid_id = 0; | ||
if (radius <= mode_switch_radius_) { | ||
grid_id = static_cast<uint16_t>(radius * inv_grid_size_m_); | ||
} else { | ||
auto gamma{universe_utils::normalizeRadian(std::atan2(radius, virtual_lidar_z_), 0.0f)}; | ||
grid_id = grid_id_offset_ + gamma * inv_grid_size_rad_; | ||
} | ||
return grid_id; | ||
} | ||
|
||
private: | ||
bool is_initialized_ = false; | ||
|
||
// configured parameters | ||
float grid_size_m_ = 0.0f; | ||
float mode_switch_radius_ = 0.0f; | ||
float virtual_lidar_z_ = 0.0f; | ||
|
||
// calculated parameters | ||
float inv_grid_size_m_ = 0.0f; | ||
float grid_size_rad_ = 0.0f; | ||
float inv_grid_size_rad_ = 0.0f; | ||
float tan_grid_size_rad_ = 0.0f; | ||
float mode_switch_grid_id_ = 0.0f; | ||
float mode_switch_angle_rad_ = 0.0f; | ||
float grid_id_offset_ = 0.0f; | ||
}; | ||
|
||
} // namespace autoware::ground_segmentation | ||
|
||
#endif // SCAN_GROUND_FILTER__GRID_HPP_ |
Oops, something went wrong.