From 445b6aed53ad0fb07d72f868a61c3714e406748c Mon Sep 17 00:00:00 2001 From: Takayuki Murooka Date: Thu, 6 Jun 2024 14:12:16 +0900 Subject: [PATCH] feat(surround_obstacle_checker): use polling subscriber (#7215) Signed-off-by: Takayuki Murooka --- .../surround_obstacle_checker/node.hpp | 10 ++++-- .../surround_obstacle_checker/src/node.cpp | 31 +++---------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/planning/surround_obstacle_checker/include/surround_obstacle_checker/node.hpp b/planning/surround_obstacle_checker/include/surround_obstacle_checker/node.hpp index e009c77d3ea1b..d5b2c49df51cb 100644 --- a/planning/surround_obstacle_checker/include/surround_obstacle_checker/node.hpp +++ b/planning/surround_obstacle_checker/include/surround_obstacle_checker/node.hpp @@ -17,6 +17,7 @@ #include "surround_obstacle_checker/debug_marker.hpp" #include "tier4_autoware_utils/ros/logger_level_configure.hpp" +#include "tier4_autoware_utils/ros/polling_subscriber.hpp" #include #include @@ -110,9 +111,12 @@ class SurroundObstacleCheckerNode : public rclcpp::Node rclcpp::TimerBase::SharedPtr timer_; // publisher and subscriber - rclcpp::Subscription::SharedPtr sub_pointcloud_; - rclcpp::Subscription::SharedPtr sub_dynamic_objects_; - rclcpp::Subscription::SharedPtr sub_odometry_; + tier4_autoware_utils::InterProcessPollingSubscriber sub_odometry_{ + this, "~/input/odometry"}; + tier4_autoware_utils::InterProcessPollingSubscriber + sub_pointcloud_{this, "~/input/pointcloud"}; + tier4_autoware_utils::InterProcessPollingSubscriber sub_dynamic_objects_{ + this, "~/input/objects"}; rclcpp::Publisher::SharedPtr pub_stop_reason_; rclcpp::Publisher::SharedPtr pub_clear_velocity_limit_; rclcpp::Publisher::SharedPtr pub_velocity_limit_; diff --git a/planning/surround_obstacle_checker/src/node.cpp b/planning/surround_obstacle_checker/src/node.cpp index c19a04bbfeac0..af6dba8fcc0c9 100644 --- a/planning/surround_obstacle_checker/src/node.cpp +++ b/planning/surround_obstacle_checker/src/node.cpp @@ -206,17 +206,6 @@ SurroundObstacleCheckerNode::SurroundObstacleCheckerNode(const rclcpp::NodeOptio pub_velocity_limit_ = this->create_publisher( "~/output/max_velocity", rclcpp::QoS{1}.transient_local()); - // Subscribers - sub_pointcloud_ = this->create_subscription( - "~/input/pointcloud", rclcpp::SensorDataQoS(), - std::bind(&SurroundObstacleCheckerNode::onPointCloud, this, std::placeholders::_1)); - sub_dynamic_objects_ = this->create_subscription( - "~/input/objects", 1, - std::bind(&SurroundObstacleCheckerNode::onDynamicObjects, this, std::placeholders::_1)); - sub_odometry_ = this->create_subscription( - "~/input/odometry", 1, - std::bind(&SurroundObstacleCheckerNode::onOdometry, this, std::placeholders::_1)); - // Parameter callback set_param_res_ = this->add_on_set_parameters_callback( std::bind(&SurroundObstacleCheckerNode::onParam, this, std::placeholders::_1)); @@ -282,6 +271,10 @@ rcl_interfaces::msg::SetParametersResult SurroundObstacleCheckerNode::onParam( void SurroundObstacleCheckerNode::onTimer() { + odometry_ptr_ = sub_odometry_.takeData(); + pointcloud_ptr_ = sub_pointcloud_.takeData(); + object_ptr_ = sub_dynamic_objects_.takeData(); + if (!odometry_ptr_) { RCLCPP_INFO_THROTTLE( this->get_logger(), *this->get_clock(), 5000 /* ms */, "waiting for current velocity..."); @@ -377,22 +370,6 @@ void SurroundObstacleCheckerNode::onTimer() debug_ptr_->publish(); } -void SurroundObstacleCheckerNode::onPointCloud( - const sensor_msgs::msg::PointCloud2::ConstSharedPtr msg) -{ - pointcloud_ptr_ = msg; -} - -void SurroundObstacleCheckerNode::onDynamicObjects(const PredictedObjects::ConstSharedPtr msg) -{ - object_ptr_ = msg; -} - -void SurroundObstacleCheckerNode::onOdometry(const nav_msgs::msg::Odometry::ConstSharedPtr msg) -{ - odometry_ptr_ = msg; -} - std::optional SurroundObstacleCheckerNode::getNearestObstacle() const { const auto nearest_pointcloud = getNearestObstacleByPointCloud();