Skip to content

Commit 0f617f5

Browse files
committed
pointcloud transport
1 parent 4a62c13 commit 0f617f5

File tree

7 files changed

+72
-11
lines changed

7 files changed

+72
-11
lines changed

elevation_mapping_cupy/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ find_package(pcl_ros REQUIRED)
4040
find_package(tf2_eigen REQUIRED)
4141
find_package(ament_cmake_python REQUIRED)
4242
find_package(python_cmake_module REQUIRED)
43-
43+
find_package(point_cloud_transport REQUIRED)
4444

4545
_ament_cmake_python_register_environment_hook()
4646
ament_python_install_package(${PROJECT_NAME} PACKAGE_DIR script/${PROJECT_NAME})
@@ -61,6 +61,7 @@ set(dependencies
6161
pcl_ros
6262
message_filters
6363
tf2_eigen
64+
point_cloud_transport
6465
)
6566

6667
# Include directories

elevation_mapping_cupy/config/core/core_param.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ elevation_mapping:
109109
subscribers:
110110
pointcloud1:
111111
# topic_name: '/ouster/points'
112-
topic_name: '/camera/camera/depth/color/points'
112+
# topic_name: '/left/zed_node_1/point_cloud/cloud_registered'
113+
topic_name: '/left/zed_node/point_cloud/cloud_registered'
113114
data_type: 'pointcloud'
114115
image1:
115116
topic_name: '/feat_processing_node/semantic_feat'

elevation_mapping_cupy/include/elevation_mapping_cupy/elevation_mapping_ros.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
// Pybind
1616
#include <pybind11/embed.h> // everything needed for embedding
1717
#include <rclcpp/qos.hpp>
18-
// ROS
18+
// ROS2
1919
#include <geometry_msgs/msg/polygon_stamped.hpp>
20+
#include <point_cloud_transport/point_cloud_transport.hpp>
2021
#include <image_transport/image_transport.hpp>
2122
#include <image_transport/subscriber_filter.hpp>
2223
#include "message_filters/subscriber.h"
@@ -100,7 +101,9 @@ class ElevationMappingNode : public rclcpp::Node {
100101
void readParameters();
101102
void setupMapPublishers();
102103
void pointcloudCallback(const sensor_msgs::msg::PointCloud2::SharedPtr cloud, const std::string& key);
103-
void inputPointCloud(const sensor_msgs::msg::PointCloud2::SharedPtr cloud, const std::vector<std::string>& channels);
104+
void pointcloudtransportCallback(const sensor_msgs::msg::PointCloud2::ConstSharedPtr cloud, const std::string& key);
105+
106+
void inputPointCloud(const sensor_msgs::msg::PointCloud2::ConstSharedPtr cloud, const std::vector<std::string>& channels);
104107

105108
void inputImage(const sensor_msgs::msg::Image::ConstSharedPtr& image_msg,
106109
const sensor_msgs::msg::CameraInfo::ConstSharedPtr& camera_info_msg,
@@ -146,6 +149,9 @@ visualization_msgs::msg::Marker vectorToArrowMarker(const Eigen::Vector3d& start
146149
// image_transport::ImageTransport it_;
147150
std::vector<rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr> pointcloudSubs_;
148151

152+
// std::vector<point_cloud_transport::Subscriber>::SharedPtr> pointcloudtransportSubs_;
153+
std::vector<point_cloud_transport::Subscriber> pointcloudtransportSubs_;
154+
149155
std::vector<rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr> imageSubs_;
150156
std::vector<rclcpp::Subscription<sensor_msgs::msg::CameraInfo>::SharedPtr> cameraInfoSubs_;
151157
std::vector<rclcpp::Subscription<elevation_map_msgs::msg::ChannelInfo>::SharedPtr> channelInfoSubs_;

elevation_mapping_cupy/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<depend>std_srvs</depend>
1616
<depend>sensor_msgs</depend>
1717
<depend>geometry_msgs</depend>
18+
<depend>point_cloud_transport</depend>
1819

1920
<depend>message_filters</depend>
2021
<depend>grid_map_msgs</depend>

elevation_mapping_cupy/src/elevation_mapping_ros.cpp

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,40 @@ ElevationMappingNode::ElevationMappingNode()
189189
auto sensor_qos = rclcpp::QoS(rclcpp::QoSInitialization(sensor_qos_profile.history, sensor_qos_profile.depth), sensor_qos_profile);
190190

191191

192-
auto callback = [this, key](const sensor_msgs::msg::PointCloud2::SharedPtr msg) {
193-
this->pointcloudCallback(msg, key);
194-
};
195-
auto sub = this->create_subscription<sensor_msgs::msg::PointCloud2>(pointcloud_topic, sensor_qos, callback);
196-
pointcloudSubs_.push_back(sub);
192+
// point_cloud_transport::Subscriber pct_sub = pct.subscribe(
193+
// "pct/point_cloud", 100,
194+
// [node](const sensor_msgs::msg::PointCloud2::ConstSharedPtr & msg)
195+
// {
196+
// RCLCPP_INFO_STREAM(
197+
// node->get_logger(),
198+
// "Message received, number of points is: " << msg->width * msg->height);
199+
// }, {});
200+
// point_cloud_transport::Subscriber sub = pct.subscribe(pointcloud_topic, 100, callback, {}, transport_hint.get())
201+
202+
203+
auto callback_transport = [this, key](const sensor_msgs::msg::PointCloud2::ConstSharedPtr msg) {
204+
this->pointcloudtransportCallback(msg, key);
205+
};
206+
207+
// Create transport hints (e.g., "draco")
208+
// auto transport_hint = std::make_shared<point_cloud_transport::TransportHints>("draco");
209+
210+
211+
// Use PointCloudTransport to create a subscriber
212+
point_cloud_transport::PointCloudTransport pct(node_);
213+
auto sub_transport = pct.subscribe(pointcloud_topic, 100, callback_transport);
214+
215+
// Add the subscriber to the vector to manage its lifetime
216+
pointcloudtransportSubs_.push_back(sub_transport);
217+
218+
219+
// auto callback = [this, key](const sensor_msgs::msg::PointCloud2::SharedPtr msg) {
220+
// this->pointcloudCallback(msg, key);
221+
// };
222+
223+
// auto sub = this->create_subscription<sensor_msgs::msg::PointCloud2>(pointcloud_topic, sensor_qos, callback);
224+
225+
// pointcloudSubs_.push_back(sub);
197226
RCLCPP_INFO(this->get_logger(), "Subscribed to PointCloud2 topic: %s", pointcloud_topic.c_str());
198227
}
199228
}
@@ -400,6 +429,23 @@ imageChannelReady_[key] = std::make_pair(*channel_info, true);
400429
}
401430
}
402431

432+
433+
void ElevationMappingNode::pointcloudtransportCallback(const sensor_msgs::msg::PointCloud2::ConstSharedPtr cloud, const std::string& key) {
434+
435+
// get channels
436+
auto fields = cloud->fields;
437+
std::vector<std::string> channels;
438+
439+
for (size_t it = 0; it < fields.size(); it++) {
440+
auto& field = fields[it];
441+
channels.push_back(field.name);
442+
}
443+
inputPointCloud(cloud, channels);
444+
445+
// This is used for publishing as statistics.
446+
pointCloudProcessCounter_++;
447+
}
448+
403449
void ElevationMappingNode::pointcloudCallback(const sensor_msgs::msg::PointCloud2::SharedPtr cloud, const std::string& key) {
404450
// get channels
405451
auto fields = cloud->fields;
@@ -415,7 +461,7 @@ void ElevationMappingNode::pointcloudCallback(const sensor_msgs::msg::PointCloud
415461
pointCloudProcessCounter_++;
416462
}
417463

418-
void ElevationMappingNode::inputPointCloud(const sensor_msgs::msg::PointCloud2::SharedPtr cloud,
464+
void ElevationMappingNode::inputPointCloud(const sensor_msgs::msg::PointCloud2::ConstSharedPtr cloud,
419465
const std::vector<std::string>& channels) {
420466
auto start = this->now();
421467
// auto* raw_pcl_pc = new pcl::PCLPointCloud2;
@@ -640,10 +686,13 @@ bool ElevationMappingNode::getSubmap(
640686
Eigen::Isometry3d transformationOdomToMap;
641687
geometry_msgs::msg::Pose pose;
642688
grid_map::Position requestedSubmapPosition(request->position_x, request->position_y);
689+
690+
643691
if (requestedFrameId != mapFrameId_) {
644692
geometry_msgs::msg::TransformStamped transformStamped;
645-
const auto& timeStamp = this->now();
693+
646694
try {
695+
const auto& timeStamp = this->now();
647696
transformStamped = tfBuffer_->lookupTransform(requestedFrameId, mapFrameId_, timeStamp, tf2::durationFromSec(1.0));
648697

649698

@@ -691,6 +740,7 @@ bool ElevationMappingNode::getSubmap(
691740
response->map = *msg_ptr;
692741

693742
}
743+
694744
return isSuccess;
695745
}
696746

point_cloud_transport

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit fd9eb0d371c62cf3155de9ea8e312df3beafc59a

point_cloud_transport_plugins

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit f5005add81c3af44b33f884a7c99f87d407d70c7

0 commit comments

Comments
 (0)