Skip to content

Commit

Permalink
feat(pcd): add debug processing time ms
Browse files Browse the repository at this point in the history
Signed-off-by: tanaka3 <ttatcoder@outlook.jp>
  • Loading branch information
taikitanaka3 committed May 13, 2022
1 parent 700a826 commit 427c42a
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 0 deletions.
1 change: 1 addition & 0 deletions perception/compare_map_segmentation/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>sensor_msgs</depend>
<depend>tier4_autoware_utils</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>autoware_lint_common</test_depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ VoxelBasedCompareMapFilterComponent::VoxelBasedCompareMapFilterComponent(
const rclcpp::NodeOptions & options)
: Filter("VoxelBasedCompareMapFilter", options)
{
// initialize debug tool
{
using tier4_autoware_utils::DebugPublisher;
using tier4_autoware_utils::StopWatch;
stop_watch_ptr_ = std::make_unique<StopWatch<std::chrono::milliseconds>>();
debug_publisher_ = std::make_unique<DebugPublisher>(this, "voxel_based_compare_map_filter");
stop_watch_ptr_->tic();
}

distance_threshold_ = static_cast<double>(declare_parameter("distance_threshold", 0.3));

set_map_in_voxel_grid_ = false;
Expand All @@ -46,6 +55,13 @@ void VoxelBasedCompareMapFilterComponent::filter(
PointCloud2 & output)
{
boost::mutex::scoped_lock lock(mutex_);
// add processing time for debug
{
const double processing_time_ms = stop_watch_ptr_->toc(true);
debug_publisher_->publish<tier4_debug_msgs::msg::Float64Stamped>(
"debug/processing_time_ms", processing_time_ms);
}
stop_watch_ptr_->tic();
if (voxel_map_ptr_ == NULL) {
output = *input;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "lidar_apollo_instance_segmentation/debugger.hpp"

#include <rclcpp/rclcpp.hpp>
#include <tier4_autoware_utils/ros/debug_publisher.hpp>
#include <tier4_autoware_utils/system/stop_watch.hpp>

#include <sensor_msgs/msg/point_cloud2.hpp>
#include <tier4_perception_msgs/msg/detected_objects_with_feature.hpp>
Expand All @@ -40,6 +42,8 @@ class LidarInstanceSegmentationNode : public rclcpp::Node
std::shared_ptr<LidarInstanceSegmentationInterface> detector_ptr_;
std::shared_ptr<Debugger> debugger_ptr_;
void pointCloudCallback(const sensor_msgs::msg::PointCloud2::ConstSharedPtr msg);
std::unique_ptr<tier4_autoware_utils::StopWatch<std::chrono::milliseconds>> stop_watch_ptr_;
std::unique_ptr<tier4_autoware_utils::DebugPublisher> debug_publisher_;

public:
explicit LidarInstanceSegmentationNode(const rclcpp::NodeOptions & node_options);
Expand Down
1 change: 1 addition & 0 deletions perception/lidar_apollo_instance_segmentation/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<depend>tf2_eigen</depend>
<depend>tf2_geometry_msgs</depend>
<depend>tf2_ros</depend>
<depend>tier4_autoware_utils</depend>
<depend>tier4_perception_msgs</depend>

<test_depend>ament_cmake_cppcheck</test_depend>
Expand Down
18 changes: 18 additions & 0 deletions perception/lidar_apollo_instance_segmentation/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@

#include "lidar_apollo_instance_segmentation/detector.hpp"

#include <tier4_autoware_utils/ros/debug_publisher.hpp>
#include <tier4_autoware_utils/system/stop_watch.hpp>

LidarInstanceSegmentationNode::LidarInstanceSegmentationNode(
const rclcpp::NodeOptions & node_options)
: Node("lidar_apollo_instance_segmentation_node", node_options)
{
using std::placeholders::_1;
// initialize debug tool
{
using tier4_autoware_utils::DebugPublisher;
using tier4_autoware_utils::StopWatch;
stop_watch_ptr_ = std::make_unique<StopWatch<std::chrono::milliseconds>>();
debug_publisher_ = std::make_unique<DebugPublisher>(this, "lidar_apollo_instance_segmentation");
stop_watch_ptr_->tic();
}
detector_ptr_ = std::make_shared<LidarApolloInstanceSegmentation>(this);
debugger_ptr_ = std::make_shared<Debugger>(this);
pointcloud_sub_ = this->create_subscription<sensor_msgs::msg::PointCloud2>(
Expand All @@ -34,6 +45,13 @@ LidarInstanceSegmentationNode::LidarInstanceSegmentationNode(
void LidarInstanceSegmentationNode::pointCloudCallback(
const sensor_msgs::msg::PointCloud2::ConstSharedPtr msg)
{
// add processing time for debug
{
const double processing_time_ms = stop_watch_ptr_->toc(true);
debug_publisher_->publish<tier4_debug_msgs::msg::Float64Stamped>(
"debug/processing_time_ms", processing_time_ms);
}
stop_watch_ptr_->tic();
tier4_perception_msgs::msg::DetectedObjectsWithFeature output_msg;
detector_ptr_->detectDynamicObjects(*msg, output_msg);
dynamic_objects_pub_->publish(output_msg);
Expand Down
67 changes: 67 additions & 0 deletions sensing/pointcloud_preprocessor/config/processing_time_ms.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version='1.0' encoding='UTF-8'?>
<root>
<tabbed_widget parent="main_window" name="Main Window">
<Tab tab_name="processing_time_ms" containers="1">
<Container>
<DockSplitter sizes="1" count="1" orientation="-">
<DockArea name="...">
<plot flip_x="false" mode="TimeSeries" flip_y="false" style="Lines">
<range right="1652341869.555872" top="50.000000" bottom="0.000000" left="1652341767.841453"/>
<limitY max="50" min="0"/>
<curve name="/sensing/lidar/right/ring_outlier_filter/debug/processing_time_ms/data" color="#1f77b4"/>
<curve name="/sensing/lidar/top/ring_outlier_filter/debug/processing_time_ms/data" color="#d62728"/>
<curve name="/sensing/lidar/rear/ring_outlier_filter/debug/processing_time_ms/data" color="#1ac938"/>
<curve name="/sensing/lidar/left/ring_outlier_filter/debug/processing_time_ms/data" color="#ff7f0e"/>
<curve name="/perception/obstacle_segmentation/crop_box_filter/debug/processing_time_ms/data" color="#f14cc1"/>
<curve name="/sensing/lidar/left/crop_box_filter/debug/processing_time_ms/data" color="#9467bd"/>
<curve name="/sensing/lidar/rear/crop_box_filter/debug/processing_time_ms/data" color="#17becf"/>
<curve name="/sensing/lidar/top/crop_box_filter/debug/processing_time_ms/data" color="#bcbd22"/>
<curve name="/sensing/lidar/right/crop_box_filter/debug/processing_time_ms/data" color="#1f77b4"/>
</plot>
</DockArea>
</DockSplitter>
</Container>
</Tab>
<currentTabIndex index="0"/>
</tabbed_widget>
<use_relative_time_offset enabled="0"/>
<!-- - - - - - - - - - - - - - - -->
<!-- - - - - - - - - - - - - - - -->
<Plugins>
<plugin ID="DataLoad CSV">
<default time_axis="" delimiter="0"/>
</plugin>
<plugin ID="DataLoad ROS2 bags">
<use_header_stamp value="false"/>
<discard_large_arrays value="true"/>
<max_array_size value="100"/>
<boolean_strings_to_number value="true"/>
<remove_suffix_from_strings value="true"/>
</plugin>
<plugin ID="DataLoad ULog"/>
<plugin ID="ROS2 Topic Subscriber">
<use_header_stamp value="false"/>
<discard_large_arrays value="false"/>
<max_array_size value="10"/>
<boolean_strings_to_number value="false"/>
<remove_suffix_from_strings value="false"/>
</plugin>
<plugin ID="UDP Server"/>
<plugin ID="WebSocket Server"/>
<plugin ID="Fast Fourier Transform"/>
<plugin ID="Quaternion to RPY"/>
<plugin ID="Reactive Script Editor">
<library code="--[[ Helper function to create a ScatterXY series from arrays.&#xa;&#xa; series_name: name of the created ScatterXY series&#xa; prefix: prefix of the timeseries, before the index of the array&#xa; suffix_X: suffix to complete the name of the series containing the X value.&#xa; if [nil], the index of the array will be used.&#xa; suffix_Y: suffix to complete the name of the series containing the Y value&#xa; timestamp: usually the tracker_time variable&#xa; &#xa; Example:&#xa; &#xa; Assuming we have multiple series in the form:&#xa; &#xa; /trajectory/node.{N}/position/x&#xa; /trajectory/node.{N}/position/y&#xa; &#xa; where {N} is the index of the array (integer). We can create a reactive series from the array with:&#xa; &#xa; CreateSeriesFromArray( &quot;my_trajectory&quot;, &quot;/trajectory/node&quot;, &quot;position/x&quot;, &quot;position/y&quot;, tracker_time );&#xa;]]--&#xa;&#xa;function CreateSeriesFromArray( series_name, prefix, suffix_X, suffix_Y, timestamp )&#xa; --- create a new series or overwite the previous one&#xa; new_series = MutableScatterXY.new(series_name)&#xa; &#xa; --- Append points to new_series&#xa; index = 0&#xa; while(true) do&#xa;&#xa; x = index;&#xa; -- if not nil, get the X coordinate from a series&#xa; if suffix_X ~= nil then &#xa; series_x = TimeseriesView.find( string.format( &quot;%s.%d/%s&quot;, prefix, index, suffix_X) )&#xa; if series_x == nil then break end&#xa; x = series_x:atTime(timestamp)&#x9; &#xa; end&#xa; &#xa; series_y = TimeseriesView.find( string.format( &quot;%s.%d/%s&quot;, prefix, index, suffix_Y) )&#xa; if series_x == nil then break end &#xa; y = series_y:atTime(timestamp)&#xa; &#xa; new_series:push_back(x,y)&#xa; index = index+1&#xa; end&#xa;end&#xa;"/>
<scripts/>
</plugin>
<plugin ID="CSV Exporter"/>
<plugin ID="ROS2 Topic Re-Publisher"/>
</Plugins>
<!-- - - - - - - - - - - - - - - -->
<previouslyLoaded_Datafiles/>
<previouslyLoaded_Streamer name="ROS2 Topic Subscriber"/>
<!-- - - - - - - - - - - - - - - -->
<customMathEquations/>
<snippets/>
<!-- - - - - - - - - - - - - - - -->
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
#include <tf2_ros/create_timer_ros.h>
#include <tf2_ros/transform_listener.h>

// Include tier4 autoware utils
#include <tier4_autoware_utils/ros/debug_publisher.hpp>
#include <tier4_autoware_utils/system/stop_watch.hpp>

namespace pointcloud_preprocessor
{
namespace sync_policies = message_filters::sync_policies;
Expand Down Expand Up @@ -168,6 +172,10 @@ class Filter : public rclcpp::Node
/** \brief Internal mutex. */
boost::mutex mutex_;

/** \brief processing time publisher. **/
std::unique_ptr<tier4_autoware_utils::StopWatch<std::chrono::milliseconds>> stop_watch_ptr_;
std::unique_ptr<tier4_autoware_utils::DebugPublisher> debug_publisher_;

/** \brief Virtual abstract filter method. To be implemented by every child.
* \param input the input point cloud dataset.
* \param indices a pointer to the vector of point indices to use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ namespace pointcloud_preprocessor
CropBoxFilterComponent::CropBoxFilterComponent(const rclcpp::NodeOptions & options)
: Filter("CropBoxFilter", options)
{
// initialize debug tool
{
using tier4_autoware_utils::DebugPublisher;
using tier4_autoware_utils::StopWatch;
stop_watch_ptr_ = std::make_unique<StopWatch<std::chrono::milliseconds>>();
debug_publisher_ = std::make_unique<DebugPublisher>(this, "crop_box_filter");
stop_watch_ptr_->tic();
}

// set initial parameters
{
auto & p = param_;
Expand Down Expand Up @@ -91,6 +100,13 @@ void CropBoxFilterComponent::filter(
PointCloud2 & output)
{
boost::mutex::scoped_lock lock(mutex_);
// add processing time for debug
{
const double processing_time_ms = stop_watch_ptr_->toc(true);
debug_publisher_->publish<tier4_debug_msgs::msg::Float64Stamped>(
"debug/processing_time_ms", processing_time_ms);
}
stop_watch_ptr_->tic();

output.data.resize(input->data.size());
Eigen::Vector3f pt(Eigen::Vector3f::Zero());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ namespace pointcloud_preprocessor
RingOutlierFilterComponent::RingOutlierFilterComponent(const rclcpp::NodeOptions & options)
: Filter("RingOutlierFilter", options)
{
// initialize debug tool
{
using tier4_autoware_utils::DebugPublisher;
using tier4_autoware_utils::StopWatch;
stop_watch_ptr_ = std::make_unique<StopWatch<std::chrono::milliseconds>>();
debug_publisher_ = std::make_unique<DebugPublisher>(this, "ring_outlier_filter");
stop_watch_ptr_->tic();
}

// set initial parameters
{
distance_ratio_ = static_cast<double>(declare_parameter("distance_ratio", 1.03));
Expand All @@ -39,6 +48,13 @@ void RingOutlierFilterComponent::filter(
PointCloud2 & output)
{
boost::mutex::scoped_lock lock(mutex_);
// add processing time for debug
{
const double processing_time_ms = stop_watch_ptr_->toc(true);
debug_publisher_->publish<tier4_debug_msgs::msg::Float64Stamped>(
"debug/processing_time_ms", processing_time_ms);
}
stop_watch_ptr_->tic();
std::unordered_map<uint16_t, std::vector<std::size_t>> input_ring_map;
input_ring_map.reserve(128);
sensor_msgs::msg::PointCloud2::SharedPtr input_ptr =
Expand Down

0 comments on commit 427c42a

Please sign in to comment.