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.
refactor(ndt_scan_matcher): modularize map_callback (autowarefoundati…
…on#2249) * still work in progress Signed-off-by: kminoda <koji.minoda@tier4.jp> * ci(pre-commit): autofix * ptr_ptr yameru Signed-off-by: kminoda <koji.minoda@tier4.jp> * remove unnecessary newline Signed-off-by: kminoda <koji.minoda@tier4.jp> * revert launch setting Signed-off-by: kminoda <koji.minoda@tier4.jp> * ci(pre-commit): autofix * reverted debugging line Signed-off-by: kminoda <koji.minoda@tier4.jp> * pre-commit Signed-off-by: kminoda <koji.minoda@tier4.jp> * remove format inclusion Signed-off-by: kminoda <koji.minoda@tier4.jp> Signed-off-by: kminoda <koji.minoda@tier4.jp> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: yoshiri <yoshiyoshidetteiu@gmail.com>
- Loading branch information
Showing
5 changed files
with
102 additions
and
25 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
49 changes: 49 additions & 0 deletions
49
localization/ndt_scan_matcher/include/ndt_scan_matcher/map_module.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,49 @@ | ||
// Copyright 2022 Autoware Foundation | ||
// | ||
// 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 NDT_SCAN_MATCHER__MAP_MODULE_HPP_ | ||
#define NDT_SCAN_MATCHER__MAP_MODULE_HPP_ | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include <sensor_msgs/msg/point_cloud2.hpp> | ||
|
||
#include <pcl/point_types.h> | ||
#include <pcl_conversions/pcl_conversions.h> | ||
#include <pclomp/ndt_omp.h> | ||
|
||
#include <memory> | ||
|
||
class MapModule | ||
{ | ||
using PointSource = pcl::PointXYZ; | ||
using PointTarget = pcl::PointXYZ; | ||
using NormalDistributionsTransform = | ||
pclomp::NormalDistributionsTransform<PointSource, PointTarget>; | ||
|
||
public: | ||
MapModule( | ||
rclcpp::Node * node, std::mutex * ndt_ptr_mutex, | ||
std::shared_ptr<NormalDistributionsTransform> ndt_ptr, | ||
rclcpp::CallbackGroup::SharedPtr map_callback_group); | ||
|
||
private: | ||
void callback_map_points(sensor_msgs::msg::PointCloud2::ConstSharedPtr pointcloud2_msg_ptr); | ||
|
||
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr map_points_sub_; | ||
std::shared_ptr<NormalDistributionsTransform> ndt_ptr_; | ||
std::mutex * ndt_ptr_mutex_; | ||
}; | ||
|
||
#endif // NDT_SCAN_MATCHER__MAP_MODULE_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
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,49 @@ | ||
// Copyright 2022 Autoware Foundation | ||
// | ||
// 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. | ||
|
||
#include "ndt_scan_matcher/map_module.hpp" | ||
|
||
MapModule::MapModule( | ||
rclcpp::Node * node, std::mutex * ndt_ptr_mutex, | ||
std::shared_ptr<NormalDistributionsTransform> ndt_ptr, | ||
rclcpp::CallbackGroup::SharedPtr map_callback_group) | ||
: ndt_ptr_(ndt_ptr), ndt_ptr_mutex_(ndt_ptr_mutex) | ||
{ | ||
auto map_sub_opt = rclcpp::SubscriptionOptions(); | ||
map_sub_opt.callback_group = map_callback_group; | ||
|
||
map_points_sub_ = node->create_subscription<sensor_msgs::msg::PointCloud2>( | ||
"pointcloud_map", rclcpp::QoS{1}.transient_local(), | ||
std::bind(&MapModule::callback_map_points, this, std::placeholders::_1), map_sub_opt); | ||
} | ||
|
||
void MapModule::callback_map_points( | ||
sensor_msgs::msg::PointCloud2::ConstSharedPtr map_points_msg_ptr) | ||
{ | ||
NormalDistributionsTransform new_ndt; | ||
new_ndt.setParams(ndt_ptr_->getParams()); | ||
|
||
pcl::shared_ptr<pcl::PointCloud<PointTarget>> map_points_ptr(new pcl::PointCloud<PointTarget>); | ||
pcl::fromROSMsg(*map_points_msg_ptr, *map_points_ptr); | ||
new_ndt.setInputTarget(map_points_ptr); | ||
// create Thread | ||
// detach | ||
auto output_cloud = std::make_shared<pcl::PointCloud<PointSource>>(); | ||
new_ndt.align(*output_cloud); | ||
|
||
// swap | ||
ndt_ptr_mutex_->lock(); | ||
*ndt_ptr_ = new_ndt; | ||
ndt_ptr_mutex_->unlock(); | ||
} |
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