|
37 | 37 | #include <autoware_auto_planning_msgs/msg/path_with_lane_id.hpp>
|
38 | 38 | #include <autoware_auto_vehicle_msgs/msg/hazard_lights_command.hpp>
|
39 | 39 |
|
| 40 | +#include <atomic> |
40 | 41 | #include <deque>
|
41 | 42 | #include <limits>
|
42 | 43 | #include <memory>
|
@@ -290,6 +291,35 @@ class GoalPlannerModule : public SceneModuleInterface
|
290 | 291 | std::unordered_map<std::string, std::shared_ptr<ObjectsOfInterestMarkerInterface>> &
|
291 | 292 | objects_of_interest_marker_interface_ptr_map);
|
292 | 293 |
|
| 294 | + ~GoalPlannerModule() |
| 295 | + { |
| 296 | + if (lane_parking_timer_) { |
| 297 | + lane_parking_timer_->cancel(); |
| 298 | + } |
| 299 | + if (freespace_parking_timer_) { |
| 300 | + freespace_parking_timer_->cancel(); |
| 301 | + } |
| 302 | + |
| 303 | + while (is_lane_parking_cb_running_.load() || is_freespace_parking_cb_running_.load()) { |
| 304 | + const std::string running_callbacks = std::invoke([&]() { |
| 305 | + if (is_lane_parking_cb_running_ && is_freespace_parking_cb_running_) { |
| 306 | + return "lane parking and freespace parking"; |
| 307 | + } |
| 308 | + if (is_lane_parking_cb_running_) { |
| 309 | + return "lane parking"; |
| 310 | + } |
| 311 | + return "freespace parking"; |
| 312 | + }); |
| 313 | + RCLCPP_INFO_THROTTLE( |
| 314 | + getLogger(), *clock_, 1000, "Waiting for %s callback to finish...", |
| 315 | + running_callbacks.c_str()); |
| 316 | + std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
| 317 | + } |
| 318 | + |
| 319 | + RCLCPP_INFO_THROTTLE( |
| 320 | + getLogger(), *clock_, 1000, "lane parking and freespace parking callbacks finished"); |
| 321 | + } |
| 322 | + |
293 | 323 | void updateModuleParams(const std::any & parameters) override
|
294 | 324 | {
|
295 | 325 | parameters_ = std::any_cast<std::shared_ptr<GoalPlannerParameters>>(parameters);
|
@@ -330,6 +360,18 @@ class GoalPlannerModule : public SceneModuleInterface
|
330 | 360 | CandidateOutput planCandidate() const override { return CandidateOutput{}; }
|
331 | 361 |
|
332 | 362 | private:
|
| 363 | + // Flag class for managing whether a certain callback is running in multi-threading |
| 364 | + class ScopedFlag |
| 365 | + { |
| 366 | + public: |
| 367 | + explicit ScopedFlag(std::atomic<bool> & flag) : flag_(flag) { flag_.store(true); } |
| 368 | + |
| 369 | + ~ScopedFlag() { flag_.store(false); } |
| 370 | + |
| 371 | + private: |
| 372 | + std::atomic<bool> & flag_; |
| 373 | + }; |
| 374 | + |
333 | 375 | /*
|
334 | 376 | * state transitions and plan function used in each state
|
335 | 377 | *
|
@@ -403,10 +445,12 @@ class GoalPlannerModule : public SceneModuleInterface
|
403 | 445 | // pre-generate lane parking paths in a separate thread
|
404 | 446 | rclcpp::TimerBase::SharedPtr lane_parking_timer_;
|
405 | 447 | rclcpp::CallbackGroup::SharedPtr lane_parking_timer_cb_group_;
|
| 448 | + std::atomic<bool> is_lane_parking_cb_running_; |
406 | 449 |
|
407 | 450 | // generate freespace parking paths in a separate thread
|
408 | 451 | rclcpp::TimerBase::SharedPtr freespace_parking_timer_;
|
409 | 452 | rclcpp::CallbackGroup::SharedPtr freespace_parking_timer_cb_group_;
|
| 453 | + std::atomic<bool> is_freespace_parking_cb_running_; |
410 | 454 |
|
411 | 455 | // debug
|
412 | 456 | mutable GoalPlannerDebugData debug_data_;
|
|
0 commit comments