@@ -79,8 +79,6 @@ ElasticBandSmoother::ElasticBandSmoother(const rclcpp::NodeOptions & node_option
79
79
// interface subscriber
80
80
path_sub_ = create_subscription<Path>(
81
81
" ~/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; });
84
82
85
83
// debug publisher
86
84
debug_extended_traj_pub_ = create_publisher<Trajectory>(" ~/debug/extended_traj" , 1 );
@@ -156,7 +154,8 @@ void ElasticBandSmoother::onPath(const Path::ConstSharedPtr path_ptr)
156
154
time_keeper_ptr_->tic (__func__);
157
155
158
156
// 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 ())) {
160
159
return ;
161
160
}
162
161
@@ -181,7 +180,7 @@ void ElasticBandSmoother::onPath(const Path::ConstSharedPtr path_ptr)
181
180
// 1. calculate trajectory with Elastic Band
182
181
// 1.a check if replan (= optimization) is required
183
182
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 );
185
184
const bool is_replan_required = [&]() {
186
185
if (replan_checker_ptr_->isResetRequired (planner_data)) {
187
186
// NOTE: always replan when resetting previous optimization
@@ -195,15 +194,15 @@ void ElasticBandSmoother::onPath(const Path::ConstSharedPtr path_ptr)
195
194
replan_checker_ptr_->updateData (planner_data, is_replan_required, now ());
196
195
time_keeper_ptr_->tic (__func__);
197
196
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 )
199
198
: *prev_optimized_traj_points_ptr_;
200
199
time_keeper_ptr_->toc (__func__, " " );
201
200
202
201
prev_optimized_traj_points_ptr_ =
203
202
std::make_shared<std::vector<TrajectoryPoint>>(smoothed_traj_points);
204
203
205
204
// 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 );
207
206
208
207
// 3. extend trajectory to connect the optimized trajectory and the following path smoothly
209
208
auto full_traj_points = extendTrajectory (input_traj_points, smoothed_traj_points);
@@ -230,9 +229,10 @@ void ElasticBandSmoother::onPath(const Path::ConstSharedPtr path_ptr)
230
229
published_time_publisher_->publish_if_subscribed (path_pub_, path_ptr->header .stamp );
231
230
}
232
231
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
234
234
{
235
- if (!ego_state_ptr_ ) {
235
+ if (!ego_state_ptr ) {
236
236
RCLCPP_INFO_SKIPFIRST_THROTTLE (get_logger (), clock , 5000 , " Waiting for ego pose and twist." );
237
237
return false ;
238
238
}
0 commit comments