@@ -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+
403449void 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
0 commit comments