Skip to content

Commit 01ab930

Browse files
committed
feat: add schema
1 parent 7f6d279 commit 01ab930

File tree

8 files changed

+232
-129
lines changed

8 files changed

+232
-129
lines changed

sensing/pointcloud_preprocessor/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ament_target_dependencies(faster_voxel_grid_downsample_filter
5858

5959
ament_auto_add_library(pointcloud_preprocessor_filter SHARED
6060
src/utility/utilities.cpp
61-
src/concatenate_data/concatenate_and_time_sync_nodelet.cpp
61+
src/concatenate_data/concatenate_and_time_sync_node.cpp
6262
src/concatenate_data/combine_cloud_handler.cpp
6363
src/concatenate_data/cloud_collector.cpp
6464
src/concatenate_data/concatenate_pointclouds.cpp
@@ -104,7 +104,7 @@ rclcpp_components_register_node(pointcloud_preprocessor_filter
104104
# ========== Concatenate and Sync data ==========
105105
rclcpp_components_register_node(pointcloud_preprocessor_filter
106106
PLUGIN "pointcloud_preprocessor::PointCloudConcatenateDataSynchronizerComponent"
107-
EXECUTABLE concatenate_data_node)
107+
EXECUTABLE concatenate_and_time_sync_node)
108108

109109
# ========== CropBox ==========
110110
rclcpp_components_register_node(pointcloud_preprocessor_filter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**:
2+
ros__parameters:
3+
maximum_queue_size: 5
4+
timeout_sec: 0.5
5+
offset_tolerance: 0.03
6+
is_motion_compensated: true
7+
publish_synchronized_pointcloud: true
8+
keep_input_frame_in_synchronized_pointcloud: true
9+
synchronized_pointcloud_postfix: pointcloud
10+
input_twist_topic_type: twist
11+
input_topics: [
12+
"/sensing/lidar/right/pointcloud_before_sync",
13+
"/sensing/lidar/left/pointcloud_before_sync",
14+
"/sensing/lidar/top/pointcloud_before_sync"
15+
]
16+
output_frame: base_link
17+
lidar_timestamp_offsets: [0.0, 0.03, 0.04]

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

+8-9
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@
4949
*
5050
*/
5151

52-
#ifndef POINTCLOUD_PREPROCESSOR__CONCATENATE_DATA__CONCATENATE_AND_TIME_SYNC_NODELET_HPP_
53-
#define POINTCLOUD_PREPROCESSOR__CONCATENATE_DATA__CONCATENATE_AND_TIME_SYNC_NODELET_HPP_
52+
#ifndef POINTCLOUD_PREPROCESSOR__CONCATENATE_DATA__CONCATENATE_AND_TIME_SYNC_NODE_HPP_
53+
#define POINTCLOUD_PREPROCESSOR__CONCATENATE_DATA__CONCATENATE_AND_TIME_SYNC_NODE_HPP_
5454

5555
#include <deque>
56+
#include <list>
5657
#include <memory>
5758
#include <mutex>
5859
#include <set>
5960
#include <string>
6061
#include <unordered_map>
6162
#include <vector>
62-
#include <list>
6363

6464
// ROS includes
6565
#include "autoware_point_types/types.hpp"
@@ -92,24 +92,24 @@ namespace pointcloud_preprocessor
9292
class PointCloudConcatenateDataSynchronizerComponent : public rclcpp::Node
9393
{
9494
public:
95-
9695
explicit PointCloudConcatenateDataSynchronizerComponent(const rclcpp::NodeOptions & node_options);
9796
virtual ~PointCloudConcatenateDataSynchronizerComponent() {}
9897
void publishClouds();
98+
9999
private:
100100
struct Parameters
101101
{
102102
int maximum_queue_size;
103103
double timeout_sec;
104+
double offset_tolerance;
104105
bool is_motion_compensated;
105106
bool publish_synchronized_pointcloud;
106107
bool keep_input_frame_in_synchronized_pointcloud;
107108
std::string synchronized_pointcloud_postfix;
108109
std::string input_twist_topic_type;
109-
std::string output_frame;
110110
std::vector<std::string> input_topics;
111+
std::string output_frame;
111112
std::vector<double> lidar_timestamp_offsets;
112-
double offset_tolerance;
113113
} params_;
114114

115115
std::set<std::string> missed_cloud_;
@@ -134,8 +134,7 @@ class PointCloudConcatenateDataSynchronizerComponent : public rclcpp::Node
134134
diagnostic_updater::Updater updater_{this};
135135

136136
void cloud_callback(
137-
const sensor_msgs::msg::PointCloud2::SharedPtr & input_ptr,
138-
const std::string & topic_name);
137+
const sensor_msgs::msg::PointCloud2::SharedPtr & input_ptr, const std::string & topic_name);
139138
void twist_callback(const geometry_msgs::msg::TwistWithCovarianceStamped::ConstSharedPtr input);
140139
void odom_callback(const nav_msgs::msg::Odometry::ConstSharedPtr input);
141140
void checkConcatStatus(diagnostic_updater::DiagnosticStatusWrapper & stat);
@@ -145,4 +144,4 @@ class PointCloudConcatenateDataSynchronizerComponent : public rclcpp::Node
145144

146145
} // namespace pointcloud_preprocessor
147146

148-
#endif // POINTCLOUD_PREPROCESSOR__CONCATENATE_DATA__CONCATENATE_AND_TIME_SYNC_NODELET_HPP_
147+
#endif // POINTCLOUD_PREPROCESSOR__CONCATENATE_DATA__CONCATENATE_AND_TIME_SYNC_NODE_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<launch>
2+
<arg name="input/twist" default="/sensing/vehicle_velocity_converter/twist_with_covariance"/>
3+
<arg name="output" default="/sensing/lidar/concatenated/pointcloud"/>
4+
<!-- Parameter -->
5+
<arg name="param_file" default="$(find-pkg-share pointcloud_preprocessor)/config/concatenate_and_time_sync.param.yaml"/>
6+
<node pkg="pointcloud_preprocessor" exec="concatenate_and_time_sync_node" name="concatenate_and_time_sync_node" output="screen">
7+
<remap from="~/input/twist" to="$(var input/twist)"/>
8+
<remap from="~/output" to="$(var output)"/>
9+
<param from="$(var param_file)"/>
10+
</node>
11+
</launch>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "Parameters for Concatenate and Time Synchronize Node",
4+
"type": "object",
5+
"definitions": {
6+
"distortion_corrector": {
7+
"type": "object",
8+
"properties": {
9+
"maximum_queue_size": {
10+
"type": "integer",
11+
"default": 5,
12+
"description": "Maximum size of the queue."
13+
},
14+
"timeout_sec": {
15+
"type": "number",
16+
"default": 0.0,
17+
"description": "Timeout in seconds."
18+
},
19+
"offset_tolerance": {
20+
"type": "number",
21+
"default": 0.0,
22+
"description": "Tolerance for offset."
23+
},
24+
"is_motion_compensated": {
25+
"type": "boolean",
26+
"default": true,
27+
"description": "Flag to indicate if motion compensation is enabled."
28+
},
29+
"publish_synchronized_pointcloud": {
30+
"type": "boolean",
31+
"default": true,
32+
"description": "Flag to indicate if synchronized point cloud should be published."
33+
},
34+
"keep_input_frame_in_synchronized_pointcloud": {
35+
"type": "boolean",
36+
"default": true,
37+
"description": "Flag to indicate if input frame should be kept in synchronized point cloud."
38+
},
39+
"synchronized_pointcloud_postfix": {
40+
"type": "string",
41+
"default": "pointcloud",
42+
"description": "Postfix for the synchronized point cloud."
43+
},
44+
"input_twist_topic_type": {
45+
"type": "string",
46+
"default": "twist",
47+
"description": "Type of the input twist topic."
48+
},
49+
"input_topics": {
50+
"type": "array",
51+
"items": {
52+
"type": "string"
53+
},
54+
"default": [],
55+
"description": "List of input topics."
56+
},
57+
"output_frame": {
58+
"type": "string",
59+
"default": "",
60+
"description": "Output frame."
61+
},
62+
"lidar_timestamp_offsets": {
63+
"type": "array",
64+
"items": {
65+
"type": "number"
66+
},
67+
"default": [],
68+
"description": "List of LiDAR timestamp offsets."
69+
}
70+
},
71+
"required": [
72+
"maximum_queue_size",
73+
"timeout_sec",
74+
"offset_tolerance",
75+
"is_motion_compensated",
76+
"publish_synchronized_pointcloud",
77+
"keep_input_frame_in_synchronized_pointcloud",
78+
"synchronized_pointcloud_postfix",
79+
"input_twist_topic_type",
80+
"input_topics",
81+
"output_frame",
82+
"lidar_timestamp_offsets"
83+
]
84+
}
85+
},
86+
"properties": {
87+
"/**": {
88+
"type": "object",
89+
"properties": {
90+
"ros__parameters": {
91+
"$ref": "#/definitions/distortion_corrector"
92+
}
93+
},
94+
"required": ["ros__parameters"]
95+
}
96+
},
97+
"required": ["/**"]
98+
}

sensing/pointcloud_preprocessor/src/concatenate_data/cloud_collector.cpp

+7-10
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#include "pointcloud_preprocessor/concatenate_data/cloud_collector.hpp"
5353

5454
#include "pointcloud_preprocessor/concatenate_data/combine_cloud_handler.hpp"
55-
#include "pointcloud_preprocessor/concatenate_data/concatenate_and_time_sync_nodelet.hpp"
55+
#include "pointcloud_preprocessor/concatenate_data/concatenate_and_time_sync_node.hpp"
5656

5757
#include <rclcpp/rclcpp.hpp>
5858

@@ -71,13 +71,13 @@ CloudCollector::CloudCollector(
7171
{
7272
timestamp_ = 0.0;
7373
const auto period_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
74-
std::chrono::duration<double>(timeout_sec_));
75-
74+
std::chrono::duration<double>(timeout_sec_));
75+
7676
timer_ = rclcpp::create_timer(
77-
concatenate_node_, concatenate_node_->get_clock(), period_ns, std::bind(&CloudCollector::combineClouds, this));
77+
concatenate_node_, concatenate_node_->get_clock(), period_ns,
78+
std::bind(&CloudCollector::combineClouds, this));
7879
}
7980

80-
8181
void CloudCollector::setTimeStamp(double timestamp)
8282
{
8383
timestamp_ = timestamp;
@@ -91,10 +91,9 @@ double CloudCollector::getTimeStamp()
9191
void CloudCollector::processCloud(
9292
std::string topic_name, sensor_msgs::msg::PointCloud2::SharedPtr cloud)
9393
{
94+
// TODO(vivid): do I need a check here to see if map already exists for same topic?
9495
topic_cloud_map_[topic_name] = cloud;
9596
if (topic_cloud_map_.size() == num_of_clouds_) combineClouds();
96-
97-
9897
}
9998

10099
void CloudCollector::combineClouds()
@@ -103,7 +102,6 @@ void CloudCollector::combineClouds()
103102
concatenate_node_->publishClouds();
104103
std::lock_guard<std::mutex> lock(mutex_);
105104
deleteCollector();
106-
107105
}
108106

109107
void CloudCollector::deleteCollector()
@@ -119,8 +117,7 @@ void CloudCollector::deleteCollector()
119117
// debug
120118
void CloudCollector::printTimer()
121119
{
122-
//std::cout << "time to ended: " << timer_->time_until_trigger().count() << std::endl;
120+
std::cout << "time to ended: " << timer_->time_until_trigger().count() << std::endl;
123121
}
124122

125-
126123
} // namespace pointcloud_preprocessor

sensing/pointcloud_preprocessor/src/concatenate_data/combine_cloud_handler.cpp

+19-27
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,9 @@
6767
namespace pointcloud_preprocessor
6868
{
6969

70-
7170
CombineCloudHandler::CombineCloudHandler(
72-
rclcpp::Node * node, std::vector<std::string> input_topics,
73-
std::string output_frame,
74-
bool is_motion_compensated, bool keep_input_frame_in_synchronized_pointcloud)
71+
rclcpp::Node * node, std::vector<std::string> input_topics, std::string output_frame,
72+
bool is_motion_compensated, bool keep_input_frame_in_synchronized_pointcloud)
7573
: node_(node),
7674
tf_buffer_(node_->get_clock()),
7775
tf_listener_(tf_buffer_),
@@ -110,7 +108,6 @@ void CombineCloudHandler::processTwist(
110108
twist_ptr->header = input->header;
111109
twist_ptr->twist = input->twist.twist;
112110
twist_ptr_queue_.push_back(twist_ptr);
113-
114111
}
115112

116113
void CombineCloudHandler::processOdometry(const nav_msgs::msg::Odometry::ConstSharedPtr & input)
@@ -187,8 +184,7 @@ void CombineCloudHandler::resetCloud()
187184
}
188185

189186
void CombineCloudHandler::combinePointClouds(
190-
std::unordered_map<std::string, sensor_msgs::msg::PointCloud2::SharedPtr> &
191-
topic_to_cloud_map_)
187+
std::unordered_map<std::string, sensor_msgs::msg::PointCloud2::SharedPtr> & topic_to_cloud_map_)
192188
{
193189
std::vector<rclcpp::Time> pc_stamps;
194190
for (const auto & pair : topic_to_cloud_map_) {
@@ -198,44 +194,43 @@ void CombineCloudHandler::combinePointClouds(
198194
std::sort(pc_stamps.begin(), pc_stamps.end(), std::greater<rclcpp::Time>());
199195
const auto oldest_stamp = pc_stamps.back();
200196

201-
202197
std::unordered_map<rclcpp::Time, Eigen::Matrix4f, RclcppTimeHash_> transform_memo;
203198

204199
for (const auto & pair : topic_to_cloud_map_) {
205200
std::string topic_name = pair.first;
206201
sensor_msgs::msg::PointCloud2::SharedPtr cloud = pair.second;
207-
//std::cout << "in combination topic: " << topic_name << std::endl;
202+
// std::cout << "in combination topic: " << topic_name << std::endl;
208203

209204
auto transformed_cloud_ptr = std::make_shared<sensor_msgs::msg::PointCloud2>();
210205
if (output_frame_ != cloud->header.frame_id) {
211-
if (!pcl_ros::transformPointCloud(output_frame_, *cloud, *transformed_cloud_ptr, tf_buffer_)) {
206+
if (!pcl_ros::transformPointCloud(
207+
output_frame_, *cloud, *transformed_cloud_ptr, tf_buffer_)) {
212208
RCLCPP_ERROR(
213209
node_->get_logger(),
214210
"[transformPointCloud] Error converting first input dataset from %s to %s.",
215211
cloud->header.frame_id.c_str(), output_frame_.c_str());
216212
return;
217213
}
218-
}
219-
else {
214+
} else {
220215
transformed_cloud_ptr = cloud;
221216
}
222217

223-
auto start = std::chrono::high_resolution_clock::now();
224-
auto transformed_delay_compensated_cloud_ptr = std::make_shared<sensor_msgs::msg::PointCloud2>();
225-
226-
if(is_motion_compensated_) {
218+
auto transformed_delay_compensated_cloud_ptr =
219+
std::make_shared<sensor_msgs::msg::PointCloud2>();
220+
221+
if (is_motion_compensated_) {
227222
Eigen::Matrix4f adjust_to_old_data_transform = Eigen::Matrix4f::Identity();
228223
rclcpp::Time current_cloud_stamp = rclcpp::Time(cloud->header.stamp);
229224
for (const auto & stamp : pc_stamps) {
230-
if(stamp >= current_cloud_stamp)
231-
continue;
225+
if (stamp >= current_cloud_stamp) continue;
232226

233227
Eigen::Matrix4f new_to_old_transform;
234228
if (transform_memo.find(stamp) != transform_memo.end()) {
235-
new_to_old_transform = transform_memo[stamp];
229+
new_to_old_transform = transform_memo[stamp];
236230
} else {
237-
new_to_old_transform = computeTransformToAdjustForOldTimestamp(stamp, current_cloud_stamp);
238-
transform_memo[stamp] = new_to_old_transform;
231+
new_to_old_transform =
232+
computeTransformToAdjustForOldTimestamp(stamp, current_cloud_stamp);
233+
transform_memo[stamp] = new_to_old_transform;
239234
}
240235
adjust_to_old_data_transform = new_to_old_transform * adjust_to_old_data_transform;
241236
current_cloud_stamp = stamp;
@@ -244,8 +239,7 @@ void CombineCloudHandler::combinePointClouds(
244239
adjust_to_old_data_transform, *transformed_cloud_ptr,
245240
*transformed_delay_compensated_cloud_ptr);
246241

247-
}
248-
else {
242+
} else {
249243
transformed_delay_compensated_cloud_ptr = transformed_cloud_ptr;
250244
}
251245

@@ -278,8 +272,6 @@ void CombineCloudHandler::combinePointClouds(
278272
concatenate_cloud_ptr_->header.stamp = oldest_stamp;
279273
}
280274

281-
282-
283275
Eigen::Matrix4f CombineCloudHandler::computeTransformToAdjustForOldTimestamp(
284276
const rclcpp::Time & old_stamp, const rclcpp::Time & new_stamp)
285277
{
@@ -334,10 +326,10 @@ Eigen::Matrix4f CombineCloudHandler::computeTransformToAdjustForOldTimestamp(
334326
}
335327

336328
Eigen::Matrix4f transformation_matrix = Eigen::Matrix4f::Identity();
337-
329+
338330
float cos_yaw = std::cos(yaw);
339331
float sin_yaw = std::sin(yaw);
340-
332+
341333
transformation_matrix(0, 3) = x;
342334
transformation_matrix(1, 3) = y;
343335
transformation_matrix(0, 0) = cos_yaw;

0 commit comments

Comments
 (0)