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.
- Loading branch information
1 parent
6ee60b2
commit bc6bbcb
Showing
4 changed files
with
169 additions
and
1 deletion.
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
43 changes: 43 additions & 0 deletions
43
localization/lidar_feature_localization/include/ros_dependent/map_receiver.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,43 @@ | ||
// Copyright 2023 The Autoware Contributors | ||
// | ||
// 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 ROS_DEPENDENT__MAP_RECEIVER_HPP_ | ||
#define ROS_DEPENDENT__MAP_RECEIVER_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
#include <sensor_msgs/msg/point_cloud2.hpp> | ||
|
||
#include <pcl/point_types.h> | ||
#include <pcl/point_cloud.h> | ||
|
||
class MapReceiver | ||
{ | ||
public: | ||
MapReceiver(std::shared_ptr<rclcpp::Node> node, const std::string & topic_name); | ||
|
||
void Callback(const sensor_msgs::msg::PointCloud2::ConstSharedPtr map_points_msg_ptr); | ||
|
||
bool IsAvailable() const; | ||
|
||
pcl::PointCloud<pcl::PointXYZ>::Ptr Get() const; | ||
|
||
private: | ||
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr map_points_sub_; | ||
pcl::PointCloud<pcl::PointXYZ>::Ptr map_points_ptr_; | ||
}; | ||
|
||
#endif // ROS_DEPENDENT__MAP_RECEIVER_HPP_ |
44 changes: 44 additions & 0 deletions
44
localization/lidar_feature_localization/src/ros_dependent/map_receiver.cpp
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,44 @@ | ||
// Copyright 2023 The Autoware Contributors | ||
// | ||
// 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 "ros_dependent/map_receiver.hpp" | ||
|
||
#include <pcl_conversions/pcl_conversions.h> | ||
|
||
#include <string> | ||
|
||
|
||
MapReceiver::MapReceiver(std::shared_ptr<rclcpp::Node> node, const std::string & topic_name) | ||
: map_points_sub_( | ||
node->create_subscription<sensor_msgs::msg::PointCloud2>( | ||
topic_name, rclcpp::QoS{1}.transient_local(), | ||
std::bind(&MapReceiver::Callback, this, std::placeholders::_1))), | ||
map_points_ptr_(new pcl::PointCloud<pcl::PointXYZ>()) | ||
{ | ||
} | ||
|
||
void MapReceiver::Callback(const sensor_msgs::msg::PointCloud2::ConstSharedPtr map_points_msg_ptr) | ||
{ | ||
pcl::fromROSMsg(*map_points_msg_ptr, *(this->map_points_ptr_)); | ||
} | ||
|
||
bool MapReceiver::IsAvailable() const | ||
{ | ||
return this->map_points_ptr_->size() > 0; | ||
} | ||
|
||
pcl::PointCloud<pcl::PointXYZ>::Ptr MapReceiver::Get() const | ||
{ | ||
return this->map_points_ptr_; | ||
} |
57 changes: 57 additions & 0 deletions
57
localization/lidar_feature_localization/test/ros_dependent/test_map_reciever.cpp
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,57 @@ | ||
// Copyright 2023 The Autoware Contributors | ||
// | ||
// 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 <gtest/gtest.h> | ||
#include <pcl_conversions/pcl_conversions.h> | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include "ros_dependent/map_receiver.hpp" | ||
|
||
|
||
class MapTestSuite : public ::testing::Test | ||
{ | ||
protected: | ||
void SetUp() {rclcpp::init(0, nullptr);} | ||
void TearDown() {(void)rclcpp::shutdown();} | ||
}; | ||
|
||
TEST_F(MapTestSuite, MapReciever) | ||
{ | ||
pcl::PointCloud<pcl::PointXYZ> pcl_pointcloud; | ||
pcl_pointcloud.push_back(pcl::PointXYZ(1., 1., 1.)); | ||
|
||
sensor_msgs::msg::PointCloud2 ros_pointcloud; | ||
pcl::toROSMsg(pcl_pointcloud, ros_pointcloud); | ||
|
||
rclcpp::NodeOptions node_options; | ||
const std::string topic_name = "pointcloud_map"; | ||
auto node = std::make_shared<rclcpp::Node>("test_map_node", node_options); | ||
auto pub_pose = node->create_publisher<sensor_msgs::msg::PointCloud2>( | ||
topic_name, rclcpp::QoS{1}.transient_local()); | ||
|
||
MapReceiver receiver(node, topic_name); | ||
EXPECT_FALSE(receiver.IsAvailable()); | ||
|
||
for (int i = 0; i < 20; ++i) { | ||
pub_pose->publish(ros_pointcloud); | ||
rclcpp::spin_some(node); | ||
rclcpp::sleep_for(std::chrono::milliseconds(100)); | ||
} | ||
|
||
EXPECT_TRUE(receiver.IsAvailable()); | ||
const auto received_cloud = receiver.Get(); | ||
EXPECT_GT(received_cloud->size(), 0U); | ||
EXPECT_EQ(received_cloud->size(), pcl_pointcloud.size()); | ||
} |