28
28
#include < string>
29
29
#include < vector>
30
30
31
- namespace
32
- {
33
- rclcpp::SubscriptionOptions createSubscriptionOptions (rclcpp::Node * node_ptr)
34
- {
35
- rclcpp::CallbackGroup::SharedPtr callback_group =
36
- node_ptr->create_callback_group (rclcpp::CallbackGroupType::MutuallyExclusive);
37
-
38
- auto sub_opt = rclcpp::SubscriptionOptions ();
39
- sub_opt.callback_group = callback_group;
40
-
41
- return sub_opt;
42
- }
43
- } // namespace
44
-
45
31
namespace autoware ::behavior_path_planner
46
32
{
47
33
using autoware::vehicle_info_utils::VehicleInfoUtils;
@@ -78,54 +64,6 @@ BehaviorPathPlannerNode::BehaviorPathPlannerNode(const rclcpp::NodeOptions & nod
78
64
79
65
bound_publisher_ = create_publisher<MarkerArray>(" ~/debug/bound" , 1 );
80
66
81
- const auto qos_transient_local = rclcpp::QoS{1 }.transient_local ();
82
- // subscriber
83
- velocity_subscriber_ = create_subscription<Odometry>(
84
- " ~/input/odometry" , 1 , std::bind (&BehaviorPathPlannerNode::onOdometry, this , _1),
85
- createSubscriptionOptions (this ));
86
- acceleration_subscriber_ = create_subscription<AccelWithCovarianceStamped>(
87
- " ~/input/accel" , 1 , std::bind (&BehaviorPathPlannerNode::onAcceleration, this , _1),
88
- createSubscriptionOptions (this ));
89
- perception_subscriber_ = create_subscription<PredictedObjects>(
90
- " ~/input/perception" , 1 , std::bind (&BehaviorPathPlannerNode::onPerception, this , _1),
91
- createSubscriptionOptions (this ));
92
- occupancy_grid_subscriber_ = create_subscription<OccupancyGrid>(
93
- " ~/input/occupancy_grid_map" , 1 , std::bind (&BehaviorPathPlannerNode::onOccupancyGrid, this , _1),
94
- createSubscriptionOptions (this ));
95
- costmap_subscriber_ = create_subscription<OccupancyGrid>(
96
- " ~/input/costmap" , 1 , std::bind (&BehaviorPathPlannerNode::onCostMap, this , _1),
97
- createSubscriptionOptions (this ));
98
- traffic_signals_subscriber_ =
99
- this ->create_subscription <autoware_perception_msgs::msg::TrafficLightGroupArray>(
100
- " ~/input/traffic_signals" , 1 , std::bind (&BehaviorPathPlannerNode::onTrafficSignals, this , _1),
101
- createSubscriptionOptions (this ));
102
- lateral_offset_subscriber_ = this ->create_subscription <LateralOffset>(
103
- " ~/input/lateral_offset" , 1 , std::bind (&BehaviorPathPlannerNode::onLateralOffset, this , _1),
104
- createSubscriptionOptions (this ));
105
- operation_mode_subscriber_ = create_subscription<OperationModeState>(
106
- " /system/operation_mode/state" , qos_transient_local,
107
- std::bind (&BehaviorPathPlannerNode::onOperationMode, this , _1),
108
- createSubscriptionOptions (this ));
109
- scenario_subscriber_ = create_subscription<Scenario>(
110
- " ~/input/scenario" , 1 ,
111
- [this ](const Scenario::ConstSharedPtr msg) {
112
- current_scenario_ = std::make_shared<Scenario>(*msg);
113
- },
114
- createSubscriptionOptions (this ));
115
- external_limit_max_velocity_subscriber_ =
116
- create_subscription<tier4_planning_msgs::msg::VelocityLimit>(
117
- " /planning/scenario_planning/max_velocity" , 1 ,
118
- std::bind (&BehaviorPathPlannerNode::on_external_velocity_limiter, this , _1),
119
- createSubscriptionOptions (this ));
120
-
121
- // route_handler
122
- vector_map_subscriber_ = create_subscription<LaneletMapBin>(
123
- " ~/input/vector_map" , qos_transient_local, std::bind (&BehaviorPathPlannerNode::onMap, this , _1),
124
- createSubscriptionOptions (this ));
125
- route_subscriber_ = create_subscription<LaneletRoute>(
126
- " ~/input/route" , qos_transient_local, std::bind (&BehaviorPathPlannerNode::onRoute, this , _1),
127
- createSubscriptionOptions (this ));
128
-
129
67
{
130
68
const std::string path_candidate_name_space = " /planning/path_candidate/" ;
131
69
const std::string path_reference_name_space = " /planning/path_reference/" ;
@@ -274,6 +212,100 @@ BehaviorPathPlannerParameters BehaviorPathPlannerNode::getCommonParam()
274
212
return p;
275
213
}
276
214
215
+ void BehaviorPathPlannerNode::takeData ()
216
+ {
217
+ // route
218
+ {
219
+ const auto msg = route_subscriber_.takeNewData ();
220
+ if (msg) {
221
+ if (msg->segments .empty ()) {
222
+ RCLCPP_ERROR (get_logger (), " input route is empty. ignored" );
223
+ } else {
224
+ route_ptr_ = msg;
225
+ has_received_route_ = true ;
226
+ }
227
+ }
228
+ }
229
+ // map
230
+ {
231
+ const auto msg = vector_map_subscriber_.takeNewData ();
232
+ if (msg) {
233
+ map_ptr_ = msg;
234
+ has_received_map_ = true ;
235
+ }
236
+ }
237
+ // velocity
238
+ {
239
+ const auto msg = velocity_subscriber_.takeData ();
240
+ if (msg) {
241
+ planner_data_->self_odometry = msg;
242
+ }
243
+ }
244
+ // acceleration
245
+ {
246
+ const auto msg = acceleration_subscriber_.takeData ();
247
+ if (msg) {
248
+ planner_data_->self_acceleration = msg;
249
+ }
250
+ }
251
+ // scenario
252
+ {
253
+ const auto msg = scenario_subscriber_.takeData ();
254
+ if (msg) {
255
+ current_scenario_ = msg;
256
+ }
257
+ }
258
+ // perception
259
+ {
260
+ const auto msg = perception_subscriber_.takeData ();
261
+ if (msg) {
262
+ planner_data_->dynamic_object = msg;
263
+ }
264
+ }
265
+ // occupancy_grid
266
+ {
267
+ const auto msg = occupancy_grid_subscriber_.takeData ();
268
+ if (msg) {
269
+ planner_data_->occupancy_grid = msg;
270
+ }
271
+ }
272
+ // costmap
273
+ {
274
+ const auto msg = costmap_subscriber_.takeData ();
275
+ if (msg) {
276
+ planner_data_->costmap = msg;
277
+ }
278
+ }
279
+ // traffic_signal
280
+ {
281
+ const auto msg = traffic_signals_subscriber_.takeData ();
282
+ if (msg) {
283
+ onTrafficSignals (msg);
284
+ }
285
+ }
286
+ // lateral_offset
287
+ {
288
+ const auto msg = lateral_offset_subscriber_.takeData ();
289
+ if (msg) {
290
+ onLateralOffset (msg);
291
+ }
292
+ }
293
+ // operation_mode
294
+ {
295
+ const auto msg = operation_mode_subscriber_.takeData ();
296
+ if (msg) {
297
+ planner_data_->operation_mode = msg;
298
+ }
299
+ }
300
+ // external_velocity_limiter
301
+ {
302
+ const auto msg = external_limit_max_velocity_subscriber_.takeData ();
303
+ if (msg) {
304
+ planner_data_->external_limit_max_velocity = msg;
305
+ }
306
+ }
307
+ }
308
+
277
309
// wait until mandatory data is ready
278
310
bool BehaviorPathPlannerNode::isDataReady ()
279
311
{
@@ -287,21 +319,17 @@ bool BehaviorPathPlannerNode::isDataReady()
287
319
}
288
320
289
321
{
290
- std::lock_guard<std::mutex> lk_route (mutex_route_);
291
322
if (!route_ptr_) {
292
323
return missing (" route" );
293
324
}
294
325
}
295
326
296
327
{
297
- std::lock_guard<std::mutex> lk_map (mutex_map_);
298
328
if (!map_ptr_) {
299
329
return missing (" map" );
300
330
}
301
331
}
302
332
303
- const std::lock_guard<std::mutex> lock (mutex_pd_); // for planner_data_
304
-
305
333
if (!planner_data_->dynamic_object ) {
306
334
return missing (" dynamic_object" );
307
335
}
@@ -327,6 +355,8 @@ bool BehaviorPathPlannerNode::isDataReady()
327
355
328
356
void BehaviorPathPlannerNode::run ()
329
357
{
358
+ takeData ();
359
+
330
360
if (!isDataReady ()) {
331
361
return ;
332
362
}
@@ -341,7 +371,6 @@ void BehaviorPathPlannerNode::run()
341
371
// check for map update
342
372
LaneletMapBin::ConstSharedPtr map_ptr{nullptr };
343
373
{
344
- std::lock_guard<std::mutex> lk_map (mutex_map_); // for has_received_map_ and map_ptr_
345
374
if (has_received_map_) {
346
375
// Note: duplicating the shared_ptr prevents the data from being deleted by another thread!
347
376
map_ptr = map_ptr_;
@@ -352,7 +381,6 @@ void BehaviorPathPlannerNode::run()
352
381
// check for route update
353
382
LaneletRoute::ConstSharedPtr route_ptr{nullptr };
354
383
{
355
- std::lock_guard<std::mutex> lk_route (mutex_route_); // for has_received_route_ and route_ptr_
356
384
if (has_received_route_) {
357
385
// Note: duplicating the shared_ptr prevents the data from being deleted by another thread!
358
386
route_ptr = route_ptr_;
@@ -765,35 +793,8 @@ bool BehaviorPathPlannerNode::keepInputPoints(
765
793
return false ;
766
794
}
767
795
768
- void BehaviorPathPlannerNode::onOdometry (const Odometry::ConstSharedPtr msg)
769
- {
770
- const std::lock_guard<std::mutex> lock (mutex_pd_);
771
- planner_data_->self_odometry = msg;
772
- }
773
- void BehaviorPathPlannerNode::onAcceleration (const AccelWithCovarianceStamped::ConstSharedPtr msg)
774
- {
775
- const std::lock_guard<std::mutex> lock (mutex_pd_);
776
- planner_data_->self_acceleration = msg;
777
- }
778
- void BehaviorPathPlannerNode::onPerception (const PredictedObjects::ConstSharedPtr msg)
779
- {
780
- const std::lock_guard<std::mutex> lock (mutex_pd_);
781
- planner_data_->dynamic_object = msg;
782
- }
783
- void BehaviorPathPlannerNode::onOccupancyGrid (const OccupancyGrid::ConstSharedPtr msg)
784
- {
785
- const std::lock_guard<std::mutex> lock (mutex_pd_);
786
- planner_data_->occupancy_grid = msg;
787
- }
788
- void BehaviorPathPlannerNode::onCostMap (const OccupancyGrid::ConstSharedPtr msg)
789
- {
790
- const std::lock_guard<std::mutex> lock (mutex_pd_);
791
- planner_data_->costmap = msg;
792
- }
793
796
void BehaviorPathPlannerNode::onTrafficSignals (const TrafficLightGroupArray::ConstSharedPtr msg)
794
797
{
795
- std::lock_guard<std::mutex> lock (mutex_pd_);
796
-
797
798
planner_data_->traffic_light_id_map .clear ();
798
799
for (const auto & signal : msg->traffic_light_groups ) {
799
800
TrafficSignalStamped traffic_signal;
@@ -802,45 +803,9 @@ void BehaviorPathPlannerNode::onTrafficSignals(const TrafficLightGroupArray::Con
802
803
planner_data_->traffic_light_id_map [signal .traffic_light_group_id ] = traffic_signal;
803
804
}
804
805
}
805
- void BehaviorPathPlannerNode::onMap (const LaneletMapBin::ConstSharedPtr msg)
806
- {
807
- const std::lock_guard<std::mutex> lock (mutex_map_);
808
- map_ptr_ = msg;
809
- has_received_map_ = true ;
810
- }
811
- void BehaviorPathPlannerNode::onRoute (const LaneletRoute::ConstSharedPtr msg)
812
- {
813
- if (msg->segments .empty ()) {
814
- RCLCPP_ERROR (get_logger (), " input route is empty. ignored" );
815
- return ;
816
- }
817
-
818
- const std::lock_guard<std::mutex> lock (mutex_route_);
819
- route_ptr_ = msg;
820
- has_received_route_ = true ;
821
- }
822
- void BehaviorPathPlannerNode::onOperationMode (const OperationModeState::ConstSharedPtr msg)
823
- {
824
- const std::lock_guard<std::mutex> lock (mutex_pd_);
825
- planner_data_->operation_mode = msg;
826
- }
827
806
828
- void BehaviorPathPlannerNode::on_external_velocity_limiter (
829
- const tier4_planning_msgs::msg::VelocityLimit::ConstSharedPtr msg)
830
- {
831
- // Note: Using this parameter during path planning might cause unexpected deceleration or jerk.
832
- // Therefore, do not use it for anything other than safety checks.
833
- if (!msg) {
834
- return ;
835
- }
836
-
837
- const std::lock_guard<std::mutex> lock (mutex_pd_);
838
- planner_data_->external_limit_max_velocity = msg;
839
- }
840
807
void BehaviorPathPlannerNode::onLateralOffset (const LateralOffset::ConstSharedPtr msg)
841
808
{
842
- std::lock_guard<std::mutex> lock (mutex_pd_);
843
-
844
809
if (!planner_data_->lateral_offset ) {
845
810
planner_data_->lateral_offset = msg;
846
811
return ;
0 commit comments