Skip to content

Commit a6495c9

Browse files
committed
feat: add nosie window for timestamp
Signed-off-by: vividf <yihsiang.fang@tier4.jp>
1 parent 01ab930 commit a6495c9

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
/**:
22
ros__parameters:
33
maximum_queue_size: 5
4-
timeout_sec: 0.5
5-
offset_tolerance: 0.03
4+
timeout_sec: 0.1
5+
#offset_tolerance: 0.03
66
is_motion_compensated: true
77
publish_synchronized_pointcloud: true
88
keep_input_frame_in_synchronized_pointcloud: true
99
synchronized_pointcloud_postfix: pointcloud
1010
input_twist_topic_type: twist
1111
input_topics: [
12-
"/sensing/lidar/right/pointcloud_before_sync",
1312
"/sensing/lidar/left/pointcloud_before_sync",
13+
"/sensing/lidar/right/pointcloud_before_sync",
1414
"/sensing/lidar/top/pointcloud_before_sync"
1515
]
1616
output_frame: base_link
17-
lidar_timestamp_offsets: [0.0, 0.03, 0.04]
17+
lidar_timestamp_offsets: [0.0, 0.04, 0.08]
18+
lidar_timestamp_noise_window: [0.01, 0.01, 0.01]

sensing/pointcloud_preprocessor/include/pointcloud_preprocessor/concatenate_data/cloud_collector.hpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@
5454

5555
#include "combine_cloud_handler.hpp"
5656

57+
#include <list>
5758
#include <memory>
5859
#include <string>
60+
#include <tuple>
5961
#include <unordered_map>
6062
#include <vector>
61-
#include <list>
6263

6364
namespace pointcloud_preprocessor
6465
{
@@ -74,13 +75,13 @@ class CloudCollector
7475
std::list<std::shared_ptr<CloudCollector>> & collectors,
7576
std::shared_ptr<CombineCloudHandler> combine_cloud_handler, int num_of_clouds, double time);
7677

77-
void setTimeStamp(double timestamp);
78-
double getTimeStamp();
78+
void setReferenceTimeStamp(double timestamp, double noise_window);
79+
std::tuple<double, double> getReferenceTimeStampBoundary();
7980
void processCloud(std::string topic_name, sensor_msgs::msg::PointCloud2::SharedPtr cloud);
8081
void combineClouds();
8182
void deleteCollector();
8283
// for debugging
83-
void printTimer();
84+
void printTimer();
8485

8586
private:
8687
std::shared_ptr<PointCloudConcatenateDataSynchronizerComponent> concatenate_node_;
@@ -90,7 +91,8 @@ class CloudCollector
9091
std::unordered_map<std::string, sensor_msgs::msg::PointCloud2::SharedPtr> topic_cloud_map_;
9192
uint64_t num_of_clouds_;
9293
double timeout_sec_;
93-
double timestamp_;
94+
double reference_timestamp_min_;
95+
double reference_timestamp_max_;
9496
std::mutex mutex_;
9597
};
9698

sensing/pointcloud_preprocessor/include/pointcloud_preprocessor/concatenate_data/concatenate_and_time_sync_node.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class PointCloudConcatenateDataSynchronizerComponent : public rclcpp::Node
101101
{
102102
int maximum_queue_size;
103103
double timeout_sec;
104-
double offset_tolerance;
104+
double offset_tolerance; // TODO(vivid): remove this
105105
bool is_motion_compensated;
106106
bool publish_synchronized_pointcloud;
107107
bool keep_input_frame_in_synchronized_pointcloud;
@@ -110,6 +110,7 @@ class PointCloudConcatenateDataSynchronizerComponent : public rclcpp::Node
110110
std::vector<std::string> input_topics;
111111
std::string output_frame;
112112
std::vector<double> lidar_timestamp_offsets;
113+
std::vector<double> lidar_timestamp_noise_window;
113114
} params_;
114115

115116
std::set<std::string> missed_cloud_;
@@ -118,6 +119,7 @@ class PointCloudConcatenateDataSynchronizerComponent : public rclcpp::Node
118119
std::list<std::shared_ptr<CloudCollector>> cloud_collectors_;
119120
std::mutex mutex_;
120121
std::unordered_map<std::string, double> topic_to_offset_map_;
122+
std::unordered_map<std::string, double> topic_to_noise_window_map;
121123

122124
// subscribers
123125
std::vector<rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr> pointcloud_subs;

sensing/pointcloud_preprocessor/src/concatenate_data/cloud_collector.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656

5757
#include <rclcpp/rclcpp.hpp>
5858

59+
#include <tuple>
60+
5961
namespace pointcloud_preprocessor
6062
{
6163

@@ -69,7 +71,7 @@ CloudCollector::CloudCollector(
6971
num_of_clouds_(num_of_clouds),
7072
timeout_sec_(timeout_sec)
7173
{
72-
timestamp_ = 0.0;
74+
// timestamp_ = 0.0;
7375
const auto period_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
7476
std::chrono::duration<double>(timeout_sec_));
7577

@@ -78,14 +80,15 @@ CloudCollector::CloudCollector(
7880
std::bind(&CloudCollector::combineClouds, this));
7981
}
8082

81-
void CloudCollector::setTimeStamp(double timestamp)
83+
void CloudCollector::setReferenceTimeStamp(double timestamp, double noise_window)
8284
{
83-
timestamp_ = timestamp;
85+
reference_timestamp_max_ = timestamp + noise_window;
86+
reference_timestamp_min_ = timestamp - noise_window;
8487
}
8588

86-
double CloudCollector::getTimeStamp()
89+
std::tuple<double, double> CloudCollector::getReferenceTimeStampBoundary()
8790
{
88-
return timestamp_;
91+
return std::make_tuple(reference_timestamp_min_, reference_timestamp_max_);
8992
}
9093

9194
void CloudCollector::processCloud(

sensing/pointcloud_preprocessor/src/concatenate_data/concatenate_and_time_sync_node.cpp

+20-7
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ PointCloudConcatenateDataSynchronizerComponent::PointCloudConcatenateDataSynchro
9696
params_.output_frame = declare_parameter<std::string>("output_frame");
9797
params_.lidar_timestamp_offsets =
9898
declare_parameter<std::vector<double>>("lidar_timestamp_offsets");
99+
params_.lidar_timestamp_noise_window =
100+
declare_parameter<std::vector<double>>("lidar_timestamp_noise_window");
99101

100102
if (params_.input_topics.empty()) {
101103
RCLCPP_ERROR(get_logger(), "Need a 'input_topics' parameter to be set before continuing!");
@@ -110,12 +112,19 @@ PointCloudConcatenateDataSynchronizerComponent::PointCloudConcatenateDataSynchro
110112
return;
111113
}
112114
if (params_.lidar_timestamp_offsets.size() != params_.input_topics.size()) {
113-
RCLCPP_ERROR(get_logger(), "The number of topics does not match the number of offsets");
115+
RCLCPP_ERROR(
116+
get_logger(), "The number of topics does not match the number of timestamp offsets");
117+
return;
118+
}
119+
if (params_.lidar_timestamp_noise_window.size() != params_.input_topics.size()) {
120+
RCLCPP_ERROR(
121+
get_logger(), "The number of topics does not match the number of timestamp noise windwo");
114122
return;
115123
}
116124

117125
for (size_t i = 0; i < params_.input_topics.size(); i++) {
118126
topic_to_offset_map_[params_.input_topics[i]] = params_.lidar_timestamp_offsets[i];
127+
topic_to_noise_window_map[params_.input_topics[i]] = params_.lidar_timestamp_noise_window[i];
119128
}
120129

121130
// Publishers
@@ -237,14 +246,17 @@ void PointCloudConcatenateDataSynchronizerComponent::cloud_callback(
237246
for (const auto & cloud_collector : cloud_collectors_) {
238247
// std::cout << "collector timestamp: " << std::fixed << std::setprecision(9) <<
239248
// cloud_collector->getTimeStamp() << std::endl; cloud_collector->printTimer();
249+
auto [reference_timestamp_max, reference_timestamp_min] =
250+
cloud_collector->getReferenceTimeStampBoundary();
240251
if (
241-
std::abs(
242-
rclcpp::Time(input_ptr->header.stamp).seconds() - topic_to_offset_map_[topic_name] -
243-
cloud_collector->getTimeStamp()) < params_.offset_tolerance) {
252+
rclcpp::Time(input_ptr->header.stamp).seconds() - topic_to_offset_map_[topic_name] <
253+
reference_timestamp_max + topic_to_noise_window_map[topic_name] &&
254+
rclcpp::Time(input_ptr->header.stamp).seconds() - topic_to_offset_map_[topic_name] >
255+
reference_timestamp_min - topic_to_noise_window_map[topic_name]) {
244256
lock.unlock();
245257
cloud_collector->processCloud(topic_name, input_ptr);
246258
collector_found = true;
247-
// std::cout << "find collector " << cloud_collector << std::endl;
259+
std::cout << "find collector " << cloud_collector << std::endl;
248260
break;
249261
}
250262
}
@@ -258,8 +270,9 @@ void PointCloudConcatenateDataSynchronizerComponent::cloud_callback(
258270

259271
cloud_collectors_.push_back(new_cloud_collector);
260272
lock.unlock();
261-
new_cloud_collector->setTimeStamp(
262-
rclcpp::Time(input_ptr->header.stamp).seconds() - topic_to_offset_map_[topic_name]);
273+
new_cloud_collector->setReferenceTimeStamp(
274+
rclcpp::Time(input_ptr->header.stamp).seconds() - topic_to_offset_map_[topic_name],
275+
topic_to_noise_window_map[topic_name]);
263276
new_cloud_collector->processCloud(topic_name, input_ptr);
264277
}
265278
}

0 commit comments

Comments
 (0)