Skip to content

Commit 10ea99f

Browse files
committed
feat: enable to change synchronized pointcloud message
Signed-off-by: yoshiri <yoshiyoshidetteiu@gmail.com>
1 parent 86b4335 commit 10ea99f

File tree

6 files changed

+68
-11
lines changed

6 files changed

+68
-11
lines changed

perception/probabilistic_occupancy_grid_map/src/pointcloud_based_occupancy_grid_map/pointcloud_based_occupancy_grid_map_node.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ void PointcloudBasedOccupancyGridMapNode::onPointcloudWithObstacleAndRaw(
136136
if (stop_watch_ptr_) {
137137
stop_watch_ptr_->toc("processing_time", true);
138138
}
139+
// if scan_origin_frame_ is "", replace it with input_raw_msg->header.frame_id
140+
if (scan_origin_frame_.empty()) {
141+
scan_origin_frame_ = input_raw_msg->header.frame_id;
142+
}
143+
139144
// Apply height filter
140145
PointCloud2 cropped_obstacle_pc{};
141146
PointCloud2 cropped_raw_pc{};

sensing/pointcloud_preprocessor/include/pointcloud_preprocessor/concatenate_data/concatenate_and_time_sync_nodelet.hpp

+19
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,24 @@
8585
#include <tf2_ros/buffer.h>
8686
#include <tf2_ros/transform_listener.h>
8787

88+
// replace topic name postfix
89+
inline std::string replace_topic_name_postfix(
90+
const std::string & original_topic_name, const std::string & postfix)
91+
{
92+
// separate the topic name by '/' and replace the last element with the new postfix
93+
size_t pos = original_topic_name.find_last_of("/");
94+
if (pos == std::string::npos) {
95+
// not found '/': this is not a namespaced topic
96+
std::cerr
97+
<< "The topic name is not namespaced. The postfix will be added to the end of the topic name."
98+
<< std::endl;
99+
return original_topic_name + postfix;
100+
} else {
101+
// replace the last element with the new postfix
102+
return original_topic_name.substr(0, pos) + postfix;
103+
}
104+
}
105+
88106
namespace pointcloud_preprocessor
89107
{
90108
using autoware_point_types::PointXYZI;
@@ -126,6 +144,7 @@ class PointCloudConcatenateDataSynchronizerComponent : public rclcpp::Node
126144
double timeout_sec_ = 0.1;
127145

128146
bool publish_synchronized_pointcloud_;
147+
std::string synchronized_pointcloud_postfix_;
129148

130149
std::set<std::string> not_subscribed_topic_names_;
131150

sensing/pointcloud_preprocessor/include/pointcloud_preprocessor/time_synchronizer/time_synchronizer_nodelet.hpp

+17
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,23 @@
8585
#include <tf2_ros/buffer.h>
8686
#include <tf2_ros/transform_listener.h>
8787

88+
// replace topic name postfix
89+
inline std::string replace_topic_name_postfix(
90+
const std::string & original_topic_name, const std::string & postfix)
91+
{
92+
// separate the topic name by '/' and replace the last element with the new postfix
93+
size_t pos = original_topic_name.find_last_of("/");
94+
if (pos == std::string::npos) {
95+
// not found '/': this is not a namespaced topic
96+
std::cerr
97+
<< "The topic name is not namespaced. The postfix will be added to the end of the topic name."
98+
<< std::endl;
99+
return original_topic_name + postfix;
100+
} else {
101+
// replace the last element with the new postfix
102+
return original_topic_name.substr(0, pos) + postfix;
103+
}
104+
}
88105
namespace pointcloud_preprocessor
89106
{
90107
using autoware_point_types::PointXYZI;

sensing/pointcloud_preprocessor/src/concatenate_data/concatenate_and_time_sync_nodelet.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
#include <utility>
6262
#include <vector>
6363

64-
#define POSTFIX_NAME "_synchronized"
64+
#define POSTFIX_NAME "_synchronized" // default postfix name for synchronized pointcloud
6565

6666
//////////////////////////////////////////////////////////////////////////////////////////////
6767

@@ -112,6 +112,8 @@ PointCloudConcatenateDataSynchronizerComponent::PointCloudConcatenateDataSynchro
112112

113113
// Check if publish synchronized pointcloud
114114
publish_synchronized_pointcloud_ = declare_parameter("publish_synchronized_pointcloud", false);
115+
synchronized_pointcloud_postfix_ =
116+
declare_parameter("synchronized_pointcloud_postfix", "pointcloud");
115117
}
116118

117119
// Initialize not_subscribed_topic_names_
@@ -185,10 +187,18 @@ PointCloudConcatenateDataSynchronizerComponent::PointCloudConcatenateDataSynchro
185187
}
186188
}
187189

188-
// Transformed Raw PointCloud2 Publisher
189-
{
190+
// Transformed Raw PointCloud2 Publisher to publish the transformed pointcloud
191+
if (publish_synchronized_pointcloud_) {
190192
for (auto & topic : input_topics_) {
191-
std::string new_topic = topic + POSTFIX_NAME;
193+
std::string new_topic = replace_topic_name_postfix(topic, synchronized_pointcloud_postfix_);
194+
if (new_topic == topic) {
195+
RCLCPP_WARN_STREAM(
196+
get_logger(),
197+
"The topic name "
198+
<< topic
199+
<< " does not have a postfix. The postfix will be added to the end of the topic name.");
200+
new_topic = topic + POSTFIX_NAME;
201+
}
192202
auto publisher = this->create_publisher<sensor_msgs::msg::PointCloud2>(
193203
new_topic, rclcpp::SensorDataQoS().keep_last(maximum_queue_size_));
194204
transformed_raw_pc_publisher_map_.insert({topic, publisher});

sensing/pointcloud_preprocessor/src/concatenate_data/concatenate_pointclouds.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ PointCloudConcatenationComponent::PointCloudConcatenationComponent(
7474
return;
7575
}
7676
}
77-
// add postfix to topic names
78-
{
79-
for (auto & topic : input_topics_) {
80-
topic = topic + POSTFIX_NAME;
81-
}
82-
}
8377

8478
// Initialize not_subscribed_topic_names_
8579
{

sensing/pointcloud_preprocessor/src/time_synchronizer/time_synchronizer_nodelet.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ PointCloudDataSynchronizerComponent::PointCloudDataSynchronizerComponent(
5555
}
5656

5757
// Set parameters
58+
std::string synchronized_pointcloud_postfix;
5859
{
5960
output_frame_ = static_cast<std::string>(declare_parameter("output_frame", ""));
6061
if (output_frame_.empty()) {
@@ -71,6 +72,9 @@ PointCloudDataSynchronizerComponent::PointCloudDataSynchronizerComponent(
7172
RCLCPP_ERROR(get_logger(), "Only one topic given. Need at least two topics to continue.");
7273
return;
7374
}
75+
// output topic name postfix
76+
synchronized_pointcloud_postfix =
77+
declare_parameter("synchronized_pointcloud_postfix", "pointcloud");
7478

7579
// Optional parameters
7680
maximum_queue_size_ = static_cast<int>(declare_parameter("max_queue_size", 5));
@@ -150,7 +154,15 @@ PointCloudDataSynchronizerComponent::PointCloudDataSynchronizerComponent(
150154
// Transformed Raw PointCloud2 Publisher
151155
{
152156
for (auto & topic : input_topics_) {
153-
std::string new_topic = topic + POSTFIX_NAME;
157+
std::string new_topic = replace_topic_name_postfix(topic, synchronized_pointcloud_postfix);
158+
if (new_topic == topic) {
159+
RCLCPP_WARN_STREAM(
160+
get_logger(),
161+
"The topic name "
162+
<< topic
163+
<< " does not have a postfix. The postfix will be added to the end of the topic name.");
164+
new_topic = topic + POSTFIX_NAME;
165+
}
154166
auto publisher = this->create_publisher<sensor_msgs::msg::PointCloud2>(
155167
new_topic, rclcpp::SensorDataQoS().keep_last(maximum_queue_size_));
156168
transformed_raw_pc_publisher_map_.insert({topic, publisher});

0 commit comments

Comments
 (0)