Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(autoware_pointcloud_preprocessor): cuda-accelerated pointcloud concatenation #9455

Draft
wants to merge 103 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
306d8a2
chore: rebase main
vividf Sep 19, 2024
946365a
chore: solve conflicts
vividf Sep 19, 2024
d4978f7
chore: fix cpp check
vividf Aug 1, 2024
63a870b
chore: add diagnostics readme
vividf Aug 1, 2024
c8cca1f
chore: update figure
vividf Aug 1, 2024
89650a2
chore: upload jitter.png and add old design link
vividf Aug 2, 2024
d423a22
chore: add the link to the tool for analyzing timestamp
vividf Aug 2, 2024
3d21b6c
fix: fix bug that timer didn't cancel
vividf Sep 4, 2024
542ce97
chore: fix logic for logging
vividf Sep 5, 2024
77a3a79
Update sensing/autoware_pointcloud_preprocessor/docs/concatenate-data.md
vividf Sep 18, 2024
52030a7
Update sensing/autoware_pointcloud_preprocessor/src/concatenate_data/…
vividf Sep 18, 2024
3ddf249
Update sensing/autoware_pointcloud_preprocessor/schema/cocatenate_and…
vividf Sep 18, 2024
d679736
Update sensing/autoware_pointcloud_preprocessor/schema/cocatenate_and…
vividf Sep 18, 2024
1f9d24c
Update sensing/autoware_pointcloud_preprocessor/src/concatenate_data/…
vividf Sep 18, 2024
09452e7
Update sensing/autoware_pointcloud_preprocessor/src/concatenate_data/…
vividf Sep 18, 2024
d900d3f
chore: remove distortion corrector related changes
vividf Sep 19, 2024
bcbe94a
feat: add managed tf buffer
vividf Sep 19, 2024
22b654a
chore: fix filename
vividf Sep 20, 2024
076bfaa
chore: add explanataion for maximum queue size
vividf Sep 20, 2024
0e59f48
chore: add explanation for timeout_sec
vividf Sep 20, 2024
8e79976
chore: fix schema's explanation
vividf Sep 20, 2024
66b4092
chore: fix description for twist and odom
vividf Sep 20, 2024
10d83ee
chore: remove license that are not used
vividf Sep 20, 2024
fbb5fe9
chore: change guard to prama once
vividf Sep 20, 2024
3f0732e
chore: default value change to string
vividf Sep 20, 2024
c19250b
Update sensing/autoware_pointcloud_preprocessor/test/test_concatenate…
vividf Sep 20, 2024
089e108
Merge branch 'feature/redesign_concatenate_and_time_sync_node' of git…
vividf Sep 20, 2024
5ec228c
Update sensing/autoware_pointcloud_preprocessor/test/test_concatenate…
vividf Sep 20, 2024
f4c869e
Update sensing/autoware_pointcloud_preprocessor/test/test_concatenate…
vividf Sep 20, 2024
4cca6c1
Update sensing/autoware_pointcloud_preprocessor/test/test_concatenate…
vividf Sep 20, 2024
53279b5
style(pre-commit): autofix
pre-commit-ci[bot] Sep 20, 2024
853b8fe
chore: clang-tidy style for static constexpr
vividf Sep 20, 2024
d32dfbc
chore: remove unused vector header
vividf Sep 20, 2024
07cb753
chore: fix naming concatenated_cloud_publisher
vividf Sep 20, 2024
490b15c
chore: fix namimg diagnostic_updater_
vividf Sep 20, 2024
8f16896
chore: specify parameter in comment
vividf Sep 20, 2024
1d89cdd
chore: change RCLCPP_WARN to RCLCPP_WARN_STREAM_THROTTLE
vividf Sep 20, 2024
651c666
chore: add comment for cancelling timer
vividf Sep 20, 2024
0aae2ec
chore: merge remote branch
vividf Sep 20, 2024
370483c
chore: Simplify loop structure for topic-to-cloud mapping
vividf Sep 23, 2024
4c0b585
chore: fix spell errors
vividf Sep 23, 2024
2decb65
chore: fix more spell error
vividf Sep 23, 2024
eeb310d
chore: rename mutex and lock
vividf Sep 25, 2024
9a85a52
chore: const reference for string parameter
vividf Sep 25, 2024
1114898
chore: add explaination for RclcppTimeHash_
vividf Sep 25, 2024
84b547c
chore: change the concatenate node to parent node
vividf Sep 25, 2024
e49d521
chore: clean processOdometry and processTwist
vividf Sep 25, 2024
5ae681c
chore: change twist shared pointer queue to twist queue
vividf Sep 26, 2024
3a8ff07
chore: refactor compensate pointcloud to function
vividf Sep 26, 2024
49b54d4
chore: reallocate memory for concatenate_cloud_ptr
vividf Sep 26, 2024
de94fa6
chore: remove new to make shared
vividf Sep 26, 2024
7979153
chore: dis to distance
vividf Sep 26, 2024
b344427
chore: refacotr poitncloud_sub
vividf Sep 26, 2024
b0c8a7c
chore: return early return but throw runtime error
vividf Sep 26, 2024
fa0c4dc
chore: replace #define DEFAULT_SYNC_TOPIC_POSTFIX with member variable
vividf Sep 26, 2024
66a62d1
chore: fix spell error
vividf Sep 26, 2024
67bfa26
chore: remove redundant function call
vividf Sep 26, 2024
bafaea1
chore: replace conplex tuple to structure
vividf Sep 26, 2024
c1a4001
chore: use reference instead of a pointer to conveys node
vividf Sep 26, 2024
7ebd332
chore: fix camel to snake case
vividf Sep 26, 2024
52ed5ed
chore: fix logic of publish synchronized pointcloud
vividf Sep 27, 2024
b863d49
chore: fix cpp check
vividf Sep 27, 2024
92d69a4
chore: remove logging and throw error directly
vividf Sep 30, 2024
edb0610
chore: fix clangd warnings
vividf Sep 30, 2024
b6700a9
chore: fix json schema
vividf Sep 30, 2024
130bcb8
chore: fix clangd warning
vividf Sep 30, 2024
31500f8
chore: remove unused variable
vividf Sep 30, 2024
000c890
chore: fix launcher
vividf Oct 1, 2024
55e0d24
chore: fix clangd warning
vividf Oct 1, 2024
0611bb9
Merge branch 'main' into feature/redesign_concatenate_and_time_sync_node
vividf Oct 4, 2024
9199a3d
chore: ensure thread safety
vividf Oct 4, 2024
d6c7a48
style(pre-commit): autofix
pre-commit-ci[bot] Oct 4, 2024
4815917
chore: clean code
vividf Oct 7, 2024
40fe11e
chore: add parameters for handling rosbag replay in loops
vividf Oct 7, 2024
3433bf0
chore: fix diagonistic
vividf Oct 7, 2024
09b8ce3
chore: reduce copy operation
vividf Oct 21, 2024
782228f
chore: reserve space for concatenated pointcloud
vividf Oct 21, 2024
3606114
chore: fix clangd error
vividf Oct 21, 2024
6ed7537
chore: fix pipeline latency
vividf Oct 21, 2024
0248a24
chore: add debug mode
vividf Oct 21, 2024
76d3b4c
chore: refactor convert_to_xyzirc_cloud function
vividf Oct 22, 2024
e709d37
chore: fix json schema
vividf Oct 22, 2024
fcdb989
chore: fix logging output
vividf Oct 22, 2024
460b467
chore: fix the output order of the debug mode
vividf Oct 22, 2024
798cbd6
chore: fix pipeline latency output
vividf Oct 23, 2024
a2e8b77
chore: clean code
vividf Oct 24, 2024
2562d6e
chore: set some parameters to false in testing
vividf Oct 24, 2024
a970f79
chore: fix default value for schema
vividf Oct 24, 2024
4d95a01
Merge branch 'main' into feature/redesign_concatenate_and_time_sync_node
vividf Oct 25, 2024
4e39bbc
chore: fix diagnostic msgs
vividf Oct 28, 2024
fe2e5c2
Merge branch 'feature/redesign_concatenate_and_time_sync_node' of git…
vividf Oct 28, 2024
50036b5
Merge branch 'main' into feature/redesign_concatenate_and_time_sync_node
vividf Oct 29, 2024
afa000d
chore: fix parameter for sample ros bag
vividf Oct 29, 2024
19170a1
chore: autoware point type namespace
vividf Nov 7, 2024
e4dea9f
Merge branch 'main' into feature/redesign_concatenate_and_time_sync_node
vividf Nov 7, 2024
d0d5b51
Merge branch 'main' into feature/redesign_concatenate_and_time_sync_node
vividf Nov 11, 2024
3123849
chore: update readme
vividf Nov 13, 2024
ce2119b
Merge branch 'feature/redesign_concatenate_and_time_sync_node' of git…
vividf Nov 13, 2024
4c2fd67
Merge remote-tracking branch 'awf/main' into feature/redesign_concate…
knzo25 Nov 21, 2024
1b2f2b2
Merge branch 'autowarefoundation:main' into feature/redesign_concaten…
vividf Nov 22, 2024
414db5d
Merge branch 'feature/redesign_concatenate_and_time_sync_node' of git…
knzo25 Nov 25, 2024
4f7b536
feat: implemented a cuda accelerated pointcloud concatenation and int…
knzo25 Nov 22, 2024
7fc85e9
chore: updated schemaand tests
knzo25 Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions sensing/autoware_pointcloud_preprocessor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ find_package(Sophus REQUIRED)
find_package(Boost REQUIRED)
find_package(PCL REQUIRED)
find_package(CGAL REQUIRED COMPONENTS Core)
find_package(CUDA)

if(${CUDA_FOUND})
add_definitions(-DUSE_CUDA)
else()
message("CUDA wat not found. Disabling CUDA-dependent functionalities")
endif()

include_directories(
include
SYSTEM
${Boost_INCLUDE_DIRS}
${CUDA_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS}
${Sophus_INCLUDE_DIRS}
Expand Down Expand Up @@ -63,8 +71,18 @@ ament_target_dependencies(faster_voxel_grid_downsample_filter
sensor_msgs
)

cuda_add_library(pointcloud_preprocessor_filter_cuda SHARED
src/concatenate_data/combine_cloud_handler_kernel.cu
)

target_include_directories(pointcloud_preprocessor_filter_cuda PUBLIC
${cuda_blackboard_INCLUDE_DIRS}
)

ament_auto_add_library(pointcloud_preprocessor_filter SHARED
src/concatenate_data/concatenate_and_time_sync_nodelet.cpp
src/concatenate_data/concatenate_and_time_sync_node.cpp
src/concatenate_data/combine_cloud_handler.cpp
src/concatenate_data/cloud_collector.cpp
src/concatenate_data/concatenate_pointclouds.cpp
src/crop_box_filter/crop_box_filter_node.cpp
src/time_synchronizer/time_synchronizer_node.cpp
Expand All @@ -91,8 +109,10 @@ ament_auto_add_library(pointcloud_preprocessor_filter SHARED

target_link_libraries(pointcloud_preprocessor_filter
pointcloud_preprocessor_filter_base
pointcloud_preprocessor_filter_cuda
faster_voxel_grid_downsample_filter
${Boost_LIBRARIES}
${CUDA_LIBRARIES}
${OpenCV_LIBRARIES}
${Sophus_LIBRARIES}
${PCL_LIBRARIES}
Expand All @@ -111,7 +131,7 @@ rclcpp_components_register_node(pointcloud_preprocessor_filter
# ========== Concatenate and Sync data ==========
rclcpp_components_register_node(pointcloud_preprocessor_filter
PLUGIN "autoware::pointcloud_preprocessor::PointCloudConcatenateDataSynchronizerComponent"
EXECUTABLE concatenate_data_node)
EXECUTABLE concatenate_and_time_sync_node)

# ========== CropBox ==========
rclcpp_components_register_node(pointcloud_preprocessor_filter
Expand Down Expand Up @@ -243,8 +263,17 @@ if(BUILD_TESTING)
test/test_distortion_corrector_node.cpp
)

ament_add_gtest(test_concatenate_node_unit
test/test_concatenate_node_unit.cpp
)

target_link_libraries(test_utilities pointcloud_preprocessor_filter)
target_link_libraries(test_distortion_corrector_node pointcloud_preprocessor_filter)
target_link_libraries(test_concatenate_node_unit pointcloud_preprocessor_filter)

add_ros_test(
test/test_concatenate_node_component.py
TIMEOUT "50"
)

endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**:
ros__parameters:
use_cuda: false
debug_mode: false
has_static_tf_only: false
rosbag_replay: false
rosbag_length: 20.0
maximum_queue_size: 5
timeout_sec: 0.2
is_motion_compensated: true
publish_synchronized_pointcloud: true
keep_input_frame_in_synchronized_pointcloud: true
publish_previous_but_late_pointcloud: false
synchronized_pointcloud_postfix: pointcloud
input_twist_topic_type: twist
input_topics: [
"/sensing/lidar/right/pointcloud_before_sync",
"/sensing/lidar/top/pointcloud_before_sync",
"/sensing/lidar/left/pointcloud_before_sync",
]
output_frame: base_link
lidar_timestamp_offsets: [0.0, 0.015, 0.016]
lidar_timestamp_noise_window: [0.01, 0.01, 0.01]
221 changes: 178 additions & 43 deletions sensing/autoware_pointcloud_preprocessor/docs/concatenate-data.md

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2024 TIER IV, Inc.
//
// 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.

#pragma once

#include "combine_cloud_handler.hpp"

#include <memory>
#include <string>
#include <tuple>
#include <unordered_map>

namespace autoware::pointcloud_preprocessor
{

class PointCloudConcatenateDataSynchronizerComponent;

template <typename PointCloudMessage>
class CombineCloudHandler;

template <typename PointCloudMessage>
class CloudCollector
{
public:
CloudCollector(
std::shared_ptr<PointCloudConcatenateDataSynchronizerComponent> && ros2_parent_node,
std::shared_ptr<CombineCloudHandler<PointCloudMessage>> & combine_cloud_handler,
int num_of_clouds, double timeout_sec, bool debug_mode);

void set_reference_timestamp(double timestamp, double noise_window);
std::tuple<double, double> get_reference_timestamp_boundary();
void process_pointcloud(
const std::string & topic_name, typename PointCloudMessage::ConstSharedPtr cloud);
void concatenate_callback();

ConcatenatedCloudResult<PointCloudMessage> concatenate_pointclouds(
std::unordered_map<std::string, typename PointCloudMessage::ConstSharedPtr> topic_to_cloud_map);

std::unordered_map<std::string, typename PointCloudMessage::ConstSharedPtr>
get_topic_to_cloud_map();

private:
std::shared_ptr<PointCloudConcatenateDataSynchronizerComponent> ros2_parent_node_;
std::shared_ptr<CombineCloudHandler<PointCloudMessage>> combine_cloud_handler_;
rclcpp::TimerBase::SharedPtr timer_;
std::unordered_map<std::string, typename PointCloudMessage::ConstSharedPtr> topic_to_cloud_map_;
uint64_t num_of_clouds_;
double timeout_sec_;
double reference_timestamp_min_{0.0};
double reference_timestamp_max_{0.0};
bool debug_mode_;
};

} // namespace autoware::pointcloud_preprocessor
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
// Copyright 2024 TIER IV, Inc.
//
// 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.

#pragma once

#include <deque>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>

// ROS includes
#include "autoware/point_types/types.hpp"

#include <autoware/universe_utils/ros/managed_transform_buffer.hpp>
#include <diagnostic_updater/diagnostic_updater.hpp>
#include <point_cloud_msg_wrapper/point_cloud_msg_wrapper.hpp>

#include <diagnostic_msgs/msg/diagnostic_status.hpp>
#include <geometry_msgs/msg/twist_stamped.hpp>
#include <geometry_msgs/msg/twist_with_covariance_stamped.hpp>
#include <nav_msgs/msg/odometry.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <sensor_msgs/point_cloud2_iterator.hpp>
#include <tier4_debug_msgs/msg/int32_stamped.hpp>
#include <tier4_debug_msgs/msg/string_stamped.hpp>

#include <message_filters/pass_through.h>
#include <message_filters/subscriber.h>
#include <message_filters/sync_policies/approximate_time.h>
#include <message_filters/sync_policies/exact_time.h>
#include <message_filters/synchronizer.h>

#ifdef USE_CUDA
#include <cuda_blackboard/cuda_pointcloud2.hpp>
#endif

namespace autoware::pointcloud_preprocessor
{
using autoware::point_types::PointXYZIRC;
using point_cloud_msg_wrapper::PointCloud2Modifier;

template <typename PointCloudMessage>
struct ConcatenatedCloudResult;

template <>
struct ConcatenatedCloudResult<sensor_msgs::msg::PointCloud2>
{
sensor_msgs::msg::PointCloud2::SharedPtr concatenate_cloud_ptr{nullptr};
std::optional<std::unordered_map<std::string, sensor_msgs::msg::PointCloud2::SharedPtr>>
topic_to_transformed_cloud_map;
std::unordered_map<std::string, double> topic_to_original_stamp_map;
};

#ifdef USE_CUDA
template <>
struct ConcatenatedCloudResult<cuda_blackboard::CudaPointCloud2>
{
cuda_blackboard::CudaPointCloud2::UniquePtr concatenate_cloud_ptr{nullptr};
std::optional<std::unordered_map<std::string, cuda_blackboard::CudaPointCloud2::UniquePtr>>
topic_to_transformed_cloud_map;
std::unordered_map<std::string, double> topic_to_original_stamp_map;
};
#endif

class CombineCloudHandlerBase
{
protected:
rclcpp::Node & node_;

std::vector<std::string> input_topics_;
std::string output_frame_;
bool is_motion_compensated_;
bool publish_synchronized_pointcloud_;
bool keep_input_frame_in_synchronized_pointcloud_;
std::unique_ptr<autoware::universe_utils::ManagedTransformBuffer> managed_tf_buffer_{nullptr};

std::deque<geometry_msgs::msg::TwistStamped> twist_queue_;

/// @brief RclcppTimeHash structure defines a custom hash function for the rclcpp::Time type by
/// using its nanoseconds representation as the hash value.
struct RclcppTimeHash
{
std::size_t operator()(const rclcpp::Time & t) const
{
return std::hash<int64_t>()(t.nanoseconds());
}
};

public:
CombineCloudHandlerBase(
rclcpp::Node & node, std::vector<std::string> input_topics, std::string output_frame,
bool is_motion_compensated, bool publish_synchronized_pointcloud,
bool keep_input_frame_in_synchronized_pointcloud, bool has_static_tf_only);

virtual ~CombineCloudHandlerBase() = default;

void process_twist(
const geometry_msgs::msg::TwistWithCovarianceStamped::ConstSharedPtr & twist_msg);

void process_odometry(const nav_msgs::msg::Odometry::ConstSharedPtr & input);

Eigen::Matrix4f compute_transform_to_adjust_for_old_timestamp(
const rclcpp::Time & old_stamp, const rclcpp::Time & new_stamp);

std::deque<geometry_msgs::msg::TwistStamped> get_twist_queue();
};

template <typename PointCloudMessage>
class CombineCloudHandler : public CombineCloudHandlerBase
{
public:
ConcatenatedCloudResult<PointCloudMessage> combine_pointclouds(
std::unordered_map<std::string, typename PointCloudMessage::ConstSharedPtr> &
topic_to_cloud_map);
};

template <>
class CombineCloudHandler<sensor_msgs::msg::PointCloud2> : public CombineCloudHandlerBase
{
protected:
static void convert_to_xyzirc_cloud(
const typename sensor_msgs::msg::PointCloud2::ConstSharedPtr & input_cloud,
typename sensor_msgs::msg::PointCloud2::SharedPtr & xyzirc_cloud);

void correct_pointcloud_motion(
const std::shared_ptr<sensor_msgs::msg::PointCloud2> & transformed_cloud_ptr,
const std::vector<rclcpp::Time> & pc_stamps,
std::unordered_map<rclcpp::Time, Eigen::Matrix4f, RclcppTimeHash> & transform_memo,
std::shared_ptr<sensor_msgs::msg::PointCloud2> transformed_delay_compensated_cloud_ptr);

public:
CombineCloudHandler(
rclcpp::Node & node, std::vector<std::string> input_topics, std::string output_frame,
bool is_motion_compensated, bool publish_synchronized_pointcloud,
bool keep_input_frame_in_synchronized_pointcloud, bool has_static_tf_only);

ConcatenatedCloudResult<sensor_msgs::msg::PointCloud2> combine_pointclouds(
std::unordered_map<std::string, sensor_msgs::msg::PointCloud2::ConstSharedPtr> &
topic_to_cloud_map);
};

#ifdef USE_CUDA

template <>
class CombineCloudHandler<cuda_blackboard::CudaPointCloud2> : public CombineCloudHandlerBase
{
protected:
struct CudaConcatStruct
{
cudaStream_t stream;
std::unique_ptr<cuda_blackboard::CudaPointCloud2> cloud_ptr;
std::size_t max_pointcloud_size_{0};
};

std::unordered_map<std::string, CudaConcatStruct> cuda_concat_struct_map_;
std::unique_ptr<cuda_blackboard::CudaPointCloud2> concatenated_cloud_ptr;
std::size_t max_concat_pointcloud_size_{0};
std::mutex mutex_;

public:
CombineCloudHandler(
rclcpp::Node & node, std::vector<std::string> input_topics, std::string output_frame,
bool is_motion_compensated, bool publish_synchronized_pointcloud,
bool keep_input_frame_in_synchronized_pointcloud, bool has_static_tf_only);

void allocate_pointclouds();

public:
ConcatenatedCloudResult<cuda_blackboard::CudaPointCloud2> combine_pointclouds(
std::unordered_map<std::string, cuda_blackboard::CudaPointCloud2::ConstSharedPtr> &
topic_to_cloud_map);
};

#endif

} // namespace autoware::pointcloud_preprocessor
Loading
Loading