Skip to content

Commit d62c45a

Browse files
takayuki5168karishma1911
authored andcommitted
feat(path_smoother): use polling subscriber (autowarefoundation#7214)
Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com>
1 parent 25a4ff1 commit d62c45a

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

planning/path_smoother/include/path_smoother/elastic_band_smoother.hpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "path_smoother/type_alias.hpp"
2323
#include "rclcpp/rclcpp.hpp"
2424
#include "tier4_autoware_utils/ros/logger_level_configure.hpp"
25+
#include "tier4_autoware_utils/ros/polling_subscriber.hpp"
2526

2627
#include <tier4_autoware_utils/ros/published_time_publisher.hpp>
2728

@@ -72,9 +73,6 @@ class ElasticBandSmoother : public rclcpp::Node
7273
CommonParam common_param_{};
7374
EgoNearestParam ego_nearest_param_{};
7475

75-
// variables for subscribers
76-
Odometry::ConstSharedPtr ego_state_ptr_;
77-
7876
// variables for previous information
7977
std::shared_ptr<std::vector<TrajectoryPoint>> prev_optimized_traj_points_ptr_;
8078

@@ -84,7 +82,7 @@ class ElasticBandSmoother : public rclcpp::Node
8482

8583
// interface subscriber
8684
rclcpp::Subscription<Path>::SharedPtr path_sub_;
87-
rclcpp::Subscription<Odometry>::SharedPtr odom_sub_;
85+
tier4_autoware_utils::InterProcessPollingSubscriber<Odometry> odom_sub_{this, "~/input/odometry"};
8886

8987
// debug publisher
9088
rclcpp::Publisher<Trajectory>::SharedPtr debug_extended_traj_pub_;
@@ -104,7 +102,8 @@ class ElasticBandSmoother : public rclcpp::Node
104102
void resetPreviousData();
105103

106104
// main functions
107-
bool isDataReady(const Path & path, rclcpp::Clock clock) const;
105+
bool isDataReady(
106+
const Path & path, const Odometry::ConstSharedPtr ego_state_ptr, rclcpp::Clock clock) const;
108107
void applyInputVelocity(
109108
std::vector<TrajectoryPoint> & output_traj_points,
110109
const std::vector<TrajectoryPoint> & input_traj_points,

planning/path_smoother/src/elastic_band_smoother.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ ElasticBandSmoother::ElasticBandSmoother(const rclcpp::NodeOptions & node_option
7979
// interface subscriber
8080
path_sub_ = create_subscription<Path>(
8181
"~/input/path", 1, std::bind(&ElasticBandSmoother::onPath, this, std::placeholders::_1));
82-
odom_sub_ = create_subscription<Odometry>(
83-
"~/input/odometry", 1, [this](const Odometry::ConstSharedPtr msg) { ego_state_ptr_ = msg; });
8482

8583
// debug publisher
8684
debug_extended_traj_pub_ = create_publisher<Trajectory>("~/debug/extended_traj", 1);
@@ -156,7 +154,8 @@ void ElasticBandSmoother::onPath(const Path::ConstSharedPtr path_ptr)
156154
time_keeper_ptr_->tic(__func__);
157155

158156
// check if data is ready and valid
159-
if (!isDataReady(*path_ptr, *get_clock())) {
157+
const auto ego_state_ptr = odom_sub_.takeData();
158+
if (!isDataReady(*path_ptr, ego_state_ptr, *get_clock())) {
160159
return;
161160
}
162161

@@ -181,7 +180,7 @@ void ElasticBandSmoother::onPath(const Path::ConstSharedPtr path_ptr)
181180
// 1. calculate trajectory with Elastic Band
182181
// 1.a check if replan (= optimization) is required
183182
PlannerData planner_data(
184-
input_traj_points, ego_state_ptr_->pose.pose, ego_state_ptr_->twist.twist.linear.x);
183+
input_traj_points, ego_state_ptr->pose.pose, ego_state_ptr->twist.twist.linear.x);
185184
const bool is_replan_required = [&]() {
186185
if (replan_checker_ptr_->isResetRequired(planner_data)) {
187186
// NOTE: always replan when resetting previous optimization
@@ -195,15 +194,15 @@ void ElasticBandSmoother::onPath(const Path::ConstSharedPtr path_ptr)
195194
replan_checker_ptr_->updateData(planner_data, is_replan_required, now());
196195
time_keeper_ptr_->tic(__func__);
197196
auto smoothed_traj_points = is_replan_required ? eb_path_smoother_ptr_->smoothTrajectory(
198-
input_traj_points, ego_state_ptr_->pose.pose)
197+
input_traj_points, ego_state_ptr->pose.pose)
199198
: *prev_optimized_traj_points_ptr_;
200199
time_keeper_ptr_->toc(__func__, " ");
201200

202201
prev_optimized_traj_points_ptr_ =
203202
std::make_shared<std::vector<TrajectoryPoint>>(smoothed_traj_points);
204203

205204
// 2. update velocity
206-
applyInputVelocity(smoothed_traj_points, input_traj_points, ego_state_ptr_->pose.pose);
205+
applyInputVelocity(smoothed_traj_points, input_traj_points, ego_state_ptr->pose.pose);
207206

208207
// 3. extend trajectory to connect the optimized trajectory and the following path smoothly
209208
auto full_traj_points = extendTrajectory(input_traj_points, smoothed_traj_points);
@@ -230,9 +229,10 @@ void ElasticBandSmoother::onPath(const Path::ConstSharedPtr path_ptr)
230229
published_time_publisher_->publish_if_subscribed(path_pub_, path_ptr->header.stamp);
231230
}
232231

233-
bool ElasticBandSmoother::isDataReady(const Path & path, rclcpp::Clock clock) const
232+
bool ElasticBandSmoother::isDataReady(
233+
const Path & path, const Odometry::ConstSharedPtr ego_state_ptr, rclcpp::Clock clock) const
234234
{
235-
if (!ego_state_ptr_) {
235+
if (!ego_state_ptr) {
236236
RCLCPP_INFO_SKIPFIRST_THROTTLE(get_logger(), clock, 5000, "Waiting for ego pose and twist.");
237237
return false;
238238
}

0 commit comments

Comments
 (0)