-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathtest_plugin_publisher.cpp
More file actions
117 lines (97 loc) · 4.39 KB
/
Copy pathtest_plugin_publisher.cpp
File metadata and controls
117 lines (97 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Copyright 2025 Davide Faconti
*
* 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 <memory>
#include <point_cloud_transport/point_cloud_transport.hpp>
#include <rclcpp/rclcpp.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>
/**
* @brief Test node that publishes point clouds using point_cloud_transport
*
* This node subscribes to a standard PointCloud2 topic and republishes it
* using point_cloud_transport, which automatically creates compressed versions
* using all available plugins (including Cloudini).
*/
class CloudiniPluginPublisherTestNode : public rclcpp::Node {
public:
CloudiniPluginPublisherTestNode() : Node("cloudini_plugin_publisher_test") {
this->declare_parameter<std::string>("input_topic", "/points");
this->declare_parameter<std::string>("output_topic", "/points_pct");
}
// Initialize point_cloud_transport (cannot be done in the constructor)
void init() {
std::string input_topic = this->get_parameter("input_topic").as_string();
std::string output_topic = this->get_parameter("output_topic").as_string();
RCLCPP_INFO(this->get_logger(), "Starting Cloudini plugin publisher test node");
RCLCPP_INFO(this->get_logger(), "Subscribing to: %s", input_topic.c_str());
RCLCPP_INFO(this->get_logger(), "Publishing to: %s", output_topic.c_str());
// Create point_cloud_transport publisher. PointCloudTransport binds the node by
// non-const lvalue ref (rclcpp::NodeInterfaces), so pass a named lvalue — Rolling
// dropped the deprecated by-value Node::SharedPtr ctor.
std::shared_ptr<rclcpp::Node> node = shared_from_this();
pct_ = std::make_shared<point_cloud_transport::PointCloudTransport>(node);
transport_publisher_ = pct_->advertise(output_topic, 10);
// Create standard ROS2 subscriber
subscription_ = this->create_subscription<sensor_msgs::msg::PointCloud2>(
input_topic, 10, [this](const sensor_msgs::msg::PointCloud2::SharedPtr msg) { this->pointCloudCallback(msg); });
RCLCPP_INFO(this->get_logger(), "Cloudini plugin publisher test node initialized successfully");
RCLCPP_INFO(this->get_logger(), "Point cloud transport will create compressed topics automatically");
}
private:
/**
* @brief Callback that receives point clouds and republishes via point_cloud_transport
*
* @param msg The incoming point cloud message
*/
void pointCloudCallback(const sensor_msgs::msg::PointCloud2::SharedPtr msg) {
message_count_++;
// Publish via point_cloud_transport
// This will automatically create compressed versions on topics like:
// - /points_pct (raw)
// - /points_pct/cloudini (compressed with Cloudini)
// - /points_pct/draco (if draco plugin is available)
transport_publisher_.publish(msg);
if (message_count_ % 10 == 0) {
RCLCPP_INFO(
this->get_logger(), "Published point cloud #%ld: %u points", message_count_, msg->width * msg->height);
}
}
// Point cloud transport instance
std::shared_ptr<point_cloud_transport::PointCloudTransport> pct_;
// Point cloud transport publisher
point_cloud_transport::Publisher transport_publisher_;
// Standard ROS2 subscription for input
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr subscription_;
// Message counter
size_t message_count_ = 0;
};
int main(int argc, char** argv) {
// Initialize ROS2
rclcpp::init(argc, argv);
// Create and initialize the publisher node
auto node = std::make_shared<CloudiniPluginPublisherTestNode>();
node->init();
RCLCPP_INFO(node->get_logger(), "Cloudini plugin publisher test node is running...");
RCLCPP_INFO(node->get_logger(), "Press Ctrl+C to exit");
try {
rclcpp::spin(node);
} catch (const std::exception& e) {
RCLCPP_ERROR(node->get_logger(), "Exception during spin: %s", e.what());
}
// Cleanup
rclcpp::shutdown();
RCLCPP_INFO(node->get_logger(), "Cloudini plugin publisher test node shutting down");
return 0;
}