Skip to content

Commit 96708f9

Browse files
vividfmojomexpre-commit-ci[bot]
authored
feat(autoware_pointcloud_preprocessor): redesign concatenate and time sync node (#8300)
* chore: rebase main Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: solve conflicts Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix cpp check Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: add diagnostics readme Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: update figure Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: upload jitter.png and add old design link Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: add the link to the tool for analyzing timestamp Signed-off-by: vividf <yihsiang.fang@tier4.jp> * fix: fix bug that timer didn't cancel Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix logic for logging Signed-off-by: vividf <yihsiang.fang@tier4.jp> * Update sensing/autoware_pointcloud_preprocessor/docs/concatenate-data.md Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> * Update sensing/autoware_pointcloud_preprocessor/src/concatenate_data/combine_cloud_handler.cpp Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> * Update sensing/autoware_pointcloud_preprocessor/schema/cocatenate_and_time_sync_node.schema.json Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> * Update sensing/autoware_pointcloud_preprocessor/schema/cocatenate_and_time_sync_node.schema.json Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> * Update sensing/autoware_pointcloud_preprocessor/src/concatenate_data/combine_cloud_handler.cpp Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> * Update sensing/autoware_pointcloud_preprocessor/src/concatenate_data/combine_cloud_handler.cpp Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> * chore: remove distortion corrector related changes Signed-off-by: vividf <yihsiang.fang@tier4.jp> * feat: add managed tf buffer Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix filename Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: add explanataion for maximum queue size Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: add explanation for timeout_sec Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix schema's explanation Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix description for twist and odom Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: remove license that are not used Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: change guard to prama once Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: default value change to string Signed-off-by: vividf <yihsiang.fang@tier4.jp> * Update sensing/autoware_pointcloud_preprocessor/test/test_concatenate_node_unit.cpp Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> * Update sensing/autoware_pointcloud_preprocessor/test/test_concatenate_node_unit.cpp Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> * Update sensing/autoware_pointcloud_preprocessor/test/test_concatenate_node_unit.cpp Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> * Update sensing/autoware_pointcloud_preprocessor/test/test_concatenate_node_unit.cpp Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> * style(pre-commit): autofix * chore: clang-tidy style for static constexpr Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: remove unused vector header Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix naming concatenated_cloud_publisher Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix namimg diagnostic_updater_ Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: specify parameter in comment Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: change RCLCPP_WARN to RCLCPP_WARN_STREAM_THROTTLE Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: add comment for cancelling timer Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: Simplify loop structure for topic-to-cloud mapping Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix spell errors Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix more spell error Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: rename mutex and lock Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: const reference for string parameter Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: add explaination for RclcppTimeHash_ Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: change the concatenate node to parent node Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: clean processOdometry and processTwist Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: change twist shared pointer queue to twist queue Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: refactor compensate pointcloud to function Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: reallocate memory for concatenate_cloud_ptr Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: remove new to make shared Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: dis to distance Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: refacotr poitncloud_sub Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: return early return but throw runtime error Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: replace #define DEFAULT_SYNC_TOPIC_POSTFIX with member variable Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix spell error Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: remove redundant function call Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: replace conplex tuple to structure Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: use reference instead of a pointer to conveys node Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix camel to snake case Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix logic of publish synchronized pointcloud Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix cpp check Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: remove logging and throw error directly Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix clangd warnings Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix json schema Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix clangd warning Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: remove unused variable Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix launcher Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix clangd warning Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: ensure thread safety Signed-off-by: vividf <yihsiang.fang@tier4.jp> * style(pre-commit): autofix * chore: clean code Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: add parameters for handling rosbag replay in loops Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix diagonistic Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: reduce copy operation Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: reserve space for concatenated pointcloud Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix clangd error Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix pipeline latency Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: add debug mode Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: refactor convert_to_xyzirc_cloud function Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix json schema Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix logging output Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix the output order of the debug mode Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix pipeline latency output Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: clean code Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: set some parameters to false in testing Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix default value for schema Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix diagnostic msgs Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix parameter for sample ros bag Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: update readme Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix empty pointcloud Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: remove duplicated logic Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix logic for handling empty pointcloud Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: clean code Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: remove rosbag_replay parameter Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: remove nodelet cpp Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: clang tidy warning Signed-off-by: vividf <yihsiang.fang@tier4.jp> * feat: add naive approach for unsynchronized pointclouds Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: add more explanations in docs for naive approach Signed-off-by: vividf <yihsiang.fang@tier4.jp> * feat: refactor naive method and fix the multithreading issue Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: set parameter to naive Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix parameter Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix readme Signed-off-by: vividf <yihsiang.fang@tier4.jp> * Update sensing/autoware_pointcloud_preprocessor/docs/concatenate-data.md Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> * Update sensing/autoware_pointcloud_preprocessor/docs/concatenate-data.md Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> * style(pre-commit): autofix * feat: remove mutually exclusive approaches Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix spell error Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: remove unused variable Signed-off-by: vividf <yihsiang.fang@tier4.jp> * refactor: refactor collectorInfo to polymorphic Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix variable name Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: fix figure and diagnostic msg in readme Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chroe: refactor collectorinfo structure Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: revert wrong file changes Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: improve message Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: remove unused input topics Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: change to explicit check Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: tier4 debug msgs to autoware internal debug msgs Signed-off-by: vividf <yihsiang.fang@tier4.jp> * chore: update documentation Signed-off-by: vividf <yihsiang.fang@tier4.jp> --------- Signed-off-by: vividf <yihsiang.fang@tier4.jp> Co-authored-by: Max Schmeller <6088931+mojomex@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 3138d75 commit 96708f9

27 files changed

+9303
-1258
lines changed

sensing/autoware_pointcloud_preprocessor/CMakeLists.txt

+14-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ ament_target_dependencies(faster_voxel_grid_downsample_filter
6464
)
6565

6666
ament_auto_add_library(pointcloud_preprocessor_filter SHARED
67-
src/concatenate_data/concatenate_and_time_sync_nodelet.cpp
67+
src/concatenate_data/concatenate_and_time_sync_node.cpp
68+
src/concatenate_data/combine_cloud_handler.cpp
69+
src/concatenate_data/cloud_collector.cpp
70+
src/concatenate_data/collector_matching_strategy.cpp
6871
src/concatenate_data/concatenate_pointclouds.cpp
6972
src/crop_box_filter/crop_box_filter_node.cpp
7073
src/time_synchronizer/time_synchronizer_node.cpp
@@ -111,7 +114,7 @@ rclcpp_components_register_node(pointcloud_preprocessor_filter
111114
# ========== Concatenate and Sync data ==========
112115
rclcpp_components_register_node(pointcloud_preprocessor_filter
113116
PLUGIN "autoware::pointcloud_preprocessor::PointCloudConcatenateDataSynchronizerComponent"
114-
EXECUTABLE concatenate_data_node)
117+
EXECUTABLE concatenate_and_time_sync_node)
115118

116119
# ========== CropBox ==========
117120
rclcpp_components_register_node(pointcloud_preprocessor_filter
@@ -243,8 +246,17 @@ if(BUILD_TESTING)
243246
test/test_distortion_corrector_node.cpp
244247
)
245248

249+
ament_add_gtest(test_concatenate_node_unit
250+
test/test_concatenate_node_unit.cpp
251+
)
252+
246253
target_link_libraries(test_utilities pointcloud_preprocessor_filter)
247254
target_link_libraries(test_distortion_corrector_node pointcloud_preprocessor_filter)
255+
target_link_libraries(test_concatenate_node_unit pointcloud_preprocessor_filter)
248256

257+
add_ros_test(
258+
test/test_concatenate_node_component.py
259+
TIMEOUT "50"
260+
)
249261

250262
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**:
2+
ros__parameters:
3+
debug_mode: false
4+
has_static_tf_only: false
5+
rosbag_length: 10.0
6+
maximum_queue_size: 5
7+
timeout_sec: 0.2
8+
is_motion_compensated: true
9+
publish_synchronized_pointcloud: true
10+
keep_input_frame_in_synchronized_pointcloud: true
11+
publish_previous_but_late_pointcloud: false
12+
synchronized_pointcloud_postfix: pointcloud
13+
input_twist_topic_type: twist
14+
input_topics: [
15+
"/sensing/lidar/right/pointcloud_before_sync",
16+
"/sensing/lidar/top/pointcloud_before_sync",
17+
"/sensing/lidar/left/pointcloud_before_sync",
18+
]
19+
output_frame: base_link
20+
matching_strategy:
21+
type: naive

sensing/autoware_pointcloud_preprocessor/docs/concatenate-data.md

+192-43
Large diffs are not rendered by default.

sensing/autoware_pointcloud_preprocessor/docs/image/concatenate_algorithm.drawio.svg

+810
Loading
Loading

sensing/autoware_pointcloud_preprocessor/docs/image/concatenate_data.drawio.svg

-298
This file was deleted.

sensing/autoware_pointcloud_preprocessor/docs/image/concatenate_edge_case.drawio.svg

+2,361
Loading
Loading
Loading
Loading

sensing/autoware_pointcloud_preprocessor/docs/image/ideal_timestamp_offset.drawio.svg

+784
Loading
Loading

sensing/autoware_pointcloud_preprocessor/docs/image/noise_timestamp_offset.drawio.svg

+2,023
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright 2024 TIER IV, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include "combine_cloud_handler.hpp"
18+
19+
#include <memory>
20+
#include <string>
21+
#include <unordered_map>
22+
23+
namespace autoware::pointcloud_preprocessor
24+
{
25+
26+
class PointCloudConcatenateDataSynchronizerComponent;
27+
class CombineCloudHandler;
28+
29+
struct CollectorInfoBase
30+
{
31+
virtual ~CollectorInfoBase() = default;
32+
};
33+
34+
struct NaiveCollectorInfo : public CollectorInfoBase
35+
{
36+
double timestamp;
37+
38+
explicit NaiveCollectorInfo(double timestamp = 0.0) : timestamp(timestamp) {}
39+
};
40+
41+
struct AdvancedCollectorInfo : public CollectorInfoBase
42+
{
43+
double timestamp;
44+
double noise_window;
45+
46+
explicit AdvancedCollectorInfo(double timestamp = 0.0, double noise_window = 0.0)
47+
: timestamp(timestamp), noise_window(noise_window)
48+
{
49+
}
50+
};
51+
52+
class CloudCollector
53+
{
54+
public:
55+
CloudCollector(
56+
std::shared_ptr<PointCloudConcatenateDataSynchronizerComponent> && ros2_parent_node,
57+
std::shared_ptr<CombineCloudHandler> & combine_cloud_handler, int num_of_clouds,
58+
double timeout_sec, bool debug_mode);
59+
bool topic_exists(const std::string & topic_name);
60+
bool process_pointcloud(
61+
const std::string & topic_name, sensor_msgs::msg::PointCloud2::SharedPtr cloud);
62+
void concatenate_callback();
63+
64+
ConcatenatedCloudResult concatenate_pointclouds(
65+
std::unordered_map<std::string, sensor_msgs::msg::PointCloud2::SharedPtr> topic_to_cloud_map);
66+
67+
std::unordered_map<std::string, sensor_msgs::msg::PointCloud2::SharedPtr>
68+
get_topic_to_cloud_map();
69+
70+
[[nodiscard]] bool concatenate_finished() const;
71+
72+
void set_info(std::shared_ptr<CollectorInfoBase> collector_info);
73+
[[nodiscard]] std::shared_ptr<CollectorInfoBase> get_info() const;
74+
void show_debug_message();
75+
76+
private:
77+
std::shared_ptr<PointCloudConcatenateDataSynchronizerComponent> ros2_parent_node_;
78+
std::shared_ptr<CombineCloudHandler> combine_cloud_handler_;
79+
rclcpp::TimerBase::SharedPtr timer_;
80+
std::unordered_map<std::string, sensor_msgs::msg::PointCloud2::SharedPtr> topic_to_cloud_map_;
81+
uint64_t num_of_clouds_;
82+
double timeout_sec_;
83+
bool debug_mode_;
84+
bool concatenate_finished_{false};
85+
std::mutex concatenate_mutex_;
86+
std::shared_ptr<CollectorInfoBase> collector_info_;
87+
};
88+
89+
} // namespace autoware::pointcloud_preprocessor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2024 TIER IV, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include "cloud_collector.hpp"
18+
19+
#include <rclcpp/node.hpp>
20+
21+
#include <sensor_msgs/msg/point_cloud2.hpp>
22+
23+
#include <list>
24+
#include <memory>
25+
#include <optional>
26+
#include <string>
27+
#include <unordered_map>
28+
#include <vector>
29+
30+
namespace autoware::pointcloud_preprocessor
31+
{
32+
33+
struct MatchingParams
34+
{
35+
std::string topic_name;
36+
double cloud_timestamp;
37+
double cloud_arrival_time;
38+
};
39+
40+
class CollectorMatchingStrategy
41+
{
42+
public:
43+
virtual ~CollectorMatchingStrategy() = default;
44+
45+
[[nodiscard]] virtual std::optional<std::shared_ptr<CloudCollector>> match_cloud_to_collector(
46+
const std::list<std::shared_ptr<CloudCollector>> & cloud_collectors,
47+
const MatchingParams & params) const = 0;
48+
virtual void set_collector_info(
49+
std::shared_ptr<CloudCollector> & collector, const MatchingParams & matching_params) = 0;
50+
};
51+
52+
class NaiveMatchingStrategy : public CollectorMatchingStrategy
53+
{
54+
public:
55+
explicit NaiveMatchingStrategy(rclcpp::Node & node);
56+
[[nodiscard]] std::optional<std::shared_ptr<CloudCollector>> match_cloud_to_collector(
57+
const std::list<std::shared_ptr<CloudCollector>> & cloud_collectors,
58+
const MatchingParams & params) const override;
59+
void set_collector_info(
60+
std::shared_ptr<CloudCollector> & collector, const MatchingParams & matching_params) override;
61+
};
62+
63+
class AdvancedMatchingStrategy : public CollectorMatchingStrategy
64+
{
65+
public:
66+
explicit AdvancedMatchingStrategy(rclcpp::Node & node, std::vector<std::string> input_topics);
67+
68+
[[nodiscard]] std::optional<std::shared_ptr<CloudCollector>> match_cloud_to_collector(
69+
const std::list<std::shared_ptr<CloudCollector>> & cloud_collectors,
70+
const MatchingParams & params) const override;
71+
void set_collector_info(
72+
std::shared_ptr<CloudCollector> & collector, const MatchingParams & matching_params) override;
73+
74+
private:
75+
std::unordered_map<std::string, double> topic_to_offset_map_;
76+
std::unordered_map<std::string, double> topic_to_noise_window_map_;
77+
};
78+
79+
std::shared_ptr<CollectorMatchingStrategy> parse_matching_strategy(rclcpp::Node & node);
80+
81+
} // namespace autoware::pointcloud_preprocessor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright 2024 TIER IV, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <deque>
18+
#include <memory>
19+
#include <optional>
20+
#include <string>
21+
#include <unordered_map>
22+
#include <vector>
23+
24+
// ROS includes
25+
#include "autoware/point_types/types.hpp"
26+
27+
#include <autoware/universe_utils/ros/managed_transform_buffer.hpp>
28+
#include <diagnostic_updater/diagnostic_updater.hpp>
29+
#include <point_cloud_msg_wrapper/point_cloud_msg_wrapper.hpp>
30+
31+
#include <diagnostic_msgs/msg/diagnostic_status.hpp>
32+
#include <geometry_msgs/msg/twist_stamped.hpp>
33+
#include <geometry_msgs/msg/twist_with_covariance_stamped.hpp>
34+
#include <nav_msgs/msg/odometry.hpp>
35+
#include <sensor_msgs/msg/point_cloud2.hpp>
36+
#include <sensor_msgs/point_cloud2_iterator.hpp>
37+
#include <tier4_debug_msgs/msg/int32_stamped.hpp>
38+
#include <tier4_debug_msgs/msg/string_stamped.hpp>
39+
40+
#include <message_filters/pass_through.h>
41+
#include <message_filters/subscriber.h>
42+
#include <message_filters/sync_policies/approximate_time.h>
43+
#include <message_filters/sync_policies/exact_time.h>
44+
#include <message_filters/synchronizer.h>
45+
46+
namespace autoware::pointcloud_preprocessor
47+
{
48+
using autoware::point_types::PointXYZIRC;
49+
using point_cloud_msg_wrapper::PointCloud2Modifier;
50+
51+
struct ConcatenatedCloudResult
52+
{
53+
sensor_msgs::msg::PointCloud2::SharedPtr concatenate_cloud_ptr{nullptr};
54+
std::optional<std::unordered_map<std::string, sensor_msgs::msg::PointCloud2::SharedPtr>>
55+
topic_to_transformed_cloud_map;
56+
std::unordered_map<std::string, double> topic_to_original_stamp_map;
57+
};
58+
59+
class CombineCloudHandler
60+
{
61+
private:
62+
rclcpp::Node & node_;
63+
64+
std::string output_frame_;
65+
bool is_motion_compensated_;
66+
bool publish_synchronized_pointcloud_;
67+
bool keep_input_frame_in_synchronized_pointcloud_;
68+
std::unique_ptr<autoware::universe_utils::ManagedTransformBuffer> managed_tf_buffer_{nullptr};
69+
70+
std::deque<geometry_msgs::msg::TwistStamped> twist_queue_;
71+
72+
/// @brief RclcppTimeHash structure defines a custom hash function for the rclcpp::Time type by
73+
/// using its nanoseconds representation as the hash value.
74+
struct RclcppTimeHash
75+
{
76+
std::size_t operator()(const rclcpp::Time & t) const
77+
{
78+
return std::hash<int64_t>()(t.nanoseconds());
79+
}
80+
};
81+
82+
static void convert_to_xyzirc_cloud(
83+
const sensor_msgs::msg::PointCloud2::SharedPtr & input_cloud,
84+
sensor_msgs::msg::PointCloud2::SharedPtr & xyzirc_cloud);
85+
86+
void correct_pointcloud_motion(
87+
const std::shared_ptr<sensor_msgs::msg::PointCloud2> & transformed_cloud_ptr,
88+
const std::vector<rclcpp::Time> & pc_stamps,
89+
std::unordered_map<rclcpp::Time, Eigen::Matrix4f, RclcppTimeHash> & transform_memo,
90+
std::shared_ptr<sensor_msgs::msg::PointCloud2> transformed_delay_compensated_cloud_ptr);
91+
92+
public:
93+
CombineCloudHandler(
94+
rclcpp::Node & node, std::string output_frame, bool is_motion_compensated,
95+
bool publish_synchronized_pointcloud, bool keep_input_frame_in_synchronized_pointcloud,
96+
bool has_static_tf_only);
97+
void process_twist(
98+
const geometry_msgs::msg::TwistWithCovarianceStamped::ConstSharedPtr & twist_msg);
99+
void process_odometry(const nav_msgs::msg::Odometry::ConstSharedPtr & odometry_msg);
100+
101+
ConcatenatedCloudResult combine_pointclouds(
102+
std::unordered_map<std::string, sensor_msgs::msg::PointCloud2::SharedPtr> & topic_to_cloud_map);
103+
104+
Eigen::Matrix4f compute_transform_to_adjust_for_old_timestamp(
105+
const rclcpp::Time & old_stamp, const rclcpp::Time & new_stamp);
106+
107+
std::deque<geometry_msgs::msg::TwistStamped> get_twist_queue();
108+
};
109+
110+
} // namespace autoware::pointcloud_preprocessor

0 commit comments

Comments
 (0)